#!/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 600000 ]; 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 # sda1 is 'swap' # sda2 is 'root' # sda3 is 'data' fdisk /dev/sda <${overlay_root}/etc/rc.local < /tmp symlink with the extroot, so that /var is permanent # mkdir -p ${overlay_root}/var # KLUDGE: /var/state is assumed to be transient, so link it to tmp, see https://dev.openwrt.org/ticket/12228 # cd ${overlay_root}/var # ln -s /tmp state # cd - log "Finished setting up extroot" } autoprovisionStage1() { signalAutoprovisionWorking 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