#!/bin/bash ### 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 # run depmod ### END INIT INFO # script from https://github.com/igorpecovnik/lib # modified by https://github.com/bleuchtang/sunxi-debian N=/etc/init.d/firstrun set -e case "$1" in start) reboot=false echo "" rm -f /etc/ssh/ssh_host* dpkg-reconfigure openssh-server set +e echo "Expanding rootfs..." device="/dev/mmcblk0" ((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)>/dev/null if [ $? -eq 0 ] ;then echo "Expanding rootfs success, rebooting automatically." /sbin/resize2fs /dev/mmcblk0p1 2>/dev/null reboot=true else echo "Expanding rootfs has failed, see log files." fi depmod -a /sbin/insserv -r firstrun if $reboot;then /sbin/reboot fi ;; *) echo "Usage: $N {start}" >&2 exit 1 ;; esac exit 0