2014-11-26 12:33:58 +01:00
|
|
|
#!/bin/bash
|
2014-10-08 07:39:24 +02:00
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: firstrun
|
2014-10-12 20:39:42 +02:00
|
|
|
# Required-Start: $all
|
2014-10-08 07:39:24 +02:00
|
|
|
# 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
|
2014-10-16 18:17:13 +02:00
|
|
|
echo ""
|
2014-10-12 09:22:50 +02:00
|
|
|
toilet -f standard "first run"
|
|
|
|
# if we have 1G ram reduce RAMLOG size
|
2014-11-26 12:33:58 +01:00
|
|
|
if (($MEMTOTAL <= 1)); then
|
2014-12-11 19:41:07 +01:00
|
|
|
if [ -f "/etc/default/ramlog" ]; then
|
2014-10-12 09:22:50 +02:00
|
|
|
sed -e 's/TMPFS_RAMFS_SIZE=512m/TMPFS_RAMFS_SIZE=256m/g' -i /etc/default/ramlog
|
2014-12-11 19:41:07 +01:00
|
|
|
fi
|
|
|
|
# for cubieboard disable some services
|
2014-10-12 09:22:50 +02:00
|
|
|
if [ -f "/boot/cubieboard2.bin" ]; then
|
|
|
|
/sbin/insserv -r brcm40183-patch
|
|
|
|
/sbin/insserv -r disable_led.sh
|
|
|
|
fi
|
|
|
|
fi
|
2014-11-17 19:51:59 +01:00
|
|
|
# Remove lirc for Lime boards
|
|
|
|
if [ -f "/boot/lime.bin" ] || [ -f "/boot/lime2.bin" ]; then
|
|
|
|
/sbin/insserv -r lirc
|
|
|
|
fi
|
2014-10-12 09:22:50 +02:00
|
|
|
#
|
2014-10-12 20:39:42 +02:00
|
|
|
echo "This process takes around one minute to finish..."
|
2014-10-12 09:22:50 +02:00
|
|
|
#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
|
|
|
|
/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
|