2014-10-12 09:25:13 +02:00
|
|
|
#!/bin/sh
|
2014-10-08 07:39:24 +02:00
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: firstrun
|
|
|
|
# Required-Start: $remote_fs
|
|
|
|
# Required-Stop:
|
|
|
|
# Should-Start:
|
2014-10-12 09:22:50 +02:00
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2014-10-08 07:39:24 +02:00
|
|
|
# Short-Description: Script to run when first starting
|
|
|
|
# Description: Something needs to be done when is
|
|
|
|
# starting at first time.
|
2014-10-12 09:22:50 +02:00
|
|
|
# regenerate ssh host key
|
2014-10-08 07:39:24 +02:00
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
N=/etc/init.d/firstrun
|
|
|
|
MEMTOTAL=$(awk 'BEGIN { printf "%.0f\n", '$(grep MemTotal /proc/meminfo | awk '{print $2}')'/1024/1024 }')
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
do_expand_rootfs(){
|
|
|
|
device="/dev/mmcblk0"
|
2014-10-12 09:22:50 +02:00
|
|
|
((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)>/dev/null
|
2014-10-08 07:39:24 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2014-10-12 09:22:50 +02:00
|
|
|
reboot=false
|
|
|
|
clear
|
|
|
|
toilet -f standard "first run"
|
|
|
|
# if we have 1G ram reduce RAMLOG size
|
|
|
|
if [ "$MEMTOTAL" = 1 ]; then
|
|
|
|
sed -e 's/TMPFS_RAMFS_SIZE=512m/TMPFS_RAMFS_SIZE=256m/g' -i /etc/default/ramlog
|
|
|
|
# for cubieboard disable some services
|
|
|
|
if [ -f "/boot/cubieboard2.bin" ]; then
|
|
|
|
/sbin/insserv -r brcm40183-patch
|
|
|
|
/sbin/insserv -r disable_led.sh
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
echo "This process takes around 2 minutes to finish..."
|
|
|
|
#NEWMAC=00:01:43:`openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//'`
|
|
|
|
#sed -e 's/ether/ether '$NEWMAC'/g' -i /etc/network/interfaces.default
|
|
|
|
#sed -e 's/ether/ether '$NEWMAC'/g' -i /etc/network/interfaces.hostapd
|
|
|
|
# Cubietruck exception
|
|
|
|
# if HDMI is attached during boot, set default screen output to HDMI
|
|
|
|
if [ -n "$(dmesg | grep ParseEDID)" ] && [ -f "/boot/cubietruck.bin" ]; then
|
|
|
|
bin2fex /boot/cubietruck.bin /tmp/tmp.fex
|
|
|
|
sed -e 's/screen0_output_type.*/screen0_output_type = 3/g' -i /tmp/tmp.fex
|
|
|
|
fex2bin /tmp/tmp.fex /boot/cubietruck.bin
|
|
|
|
fi
|
|
|
|
rm -f /etc/ssh/ssh_host*
|
|
|
|
dpkg-reconfigure openssh-server
|
|
|
|
set +e
|
|
|
|
if [ "$(fping 8.8.8.8 | grep alive)" != "" ]; then
|
|
|
|
echo "Updating packages list..."
|
|
|
|
apt-get update >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
echo "Expanding rootfs..."
|
|
|
|
if do_expand_rootfs;then
|
|
|
|
echo "Expanding rootfs success, rebooting automatically."
|
|
|
|
/sbin/insserv resize2fs
|
|
|
|
reboot=true
|
|
|
|
else
|
|
|
|
echo "Expanding rootfs has failed, see log files."
|
|
|
|
fi
|
|
|
|
set -e
|
2014-10-12 09:49:48 +02:00
|
|
|
/sbin/insserv bootsplash
|
2014-10-12 09:22:50 +02:00
|
|
|
/sbin/insserv -r firstrun
|
2014-10-08 07:39:24 +02:00
|
|
|
if $reboot;then
|
|
|
|
/sbin/reboot
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $N {start}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|