#!/bin/sh # autoprovision stage 1: this script will be executed upon boot without a valid extroot (i.e. when rc.local is found and run from the internal overlay) . /root/autoprovision-functions.sh getPendriveSize() { # this is needed for the mmc card in some (all?) Huawei 3G dongle. # details: https://dev.openwrt.org/ticket/10716#comment:4 if [ -e /dev/sda ]; then # force re-read of the partition table head /dev/sda >/dev/null fi if (grep -q sda /proc/partitions) then cat /sys/block/sda/size else echo 0 fi } hasBigEnoughPendrive() { local size=$(getPendriveSize) if [ $size -ge 2000000 ]; then log "Found a pendrive of size: $(($size / 2 / 1024)) MB" return 0 else return 1 fi } setupPendrivePartitions() { # erase partition table dd if=/dev/zero of=/dev/sda bs=1M count=1 # first is 'swap' # second is 'root' # the rest is 'data' fdisk /dev/sda </mnt/extroot/etc/rc.local < /tmp symlink with the extroot, so that /var is permanent mkdir -p /mnt/extroot/var # KLUDGE: but /var/state is assumed to be transient, see https://dev.openwrt.org/ticket/12228 cd /mnt/extroot/var ln -s /tmp state cd - log "Finished setting up extroot" } autoprovisionStage1() { signalAutoprovisionWorking # this way it will set a random password and only ssh key based login will work setRootPassword "" signalAutoprovisionWaitingForUser signalWaitingForPendrive until hasBigEnoughPendrive do echo "Waiting for a pendrive to be inserted" sleep 3 done signalAutoprovisionWorking # to make it flash in sync with the USB led signalFormatting sleep 1 setupPendrivePartitions sleep 1 setupExtroot sync stopSignallingAnything reboot } autoprovisionStage1