#!/bin/sh ### BEGIN INIT INFO # Provides: firstrun # Required-Start: $all # Required-Stop: # Should-Start: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Script to run when first starting # Description: Something needs to be done when is # starting at first time. # regenerate ssh host key ### 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" ((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)>/dev/null return 0 } case "$1" in start) 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 one minute 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 /sbin/insserv -r firstrun if $reboot;then /sbin/reboot fi ;; *) echo "Usage: $N {start}" >&2 exit 1 ;; esac exit 0