#!/usr/bin/env sh # Determine extroot partition UUID=$(uci show fstab.extroot.uuid | sed -e 's/fstab\.extroot\.uuid\=//g' -e "s/\'//g") DEVICE=$(block info | grep "$UUID" | cut -f1 -d":") # Mount it at a temp directory TEMPDIR=$(mktemp -d) mount "$DEVICE" "$TEMPDIR" # Forcibly remove everything inside (terrifying) if ! [ "$TEMPDIR" == "" ] && [ -d "$TEMPDIR" ]; then find "$TEMPDIR" -mindepth 1 ! -name 'sysupgrade-backup.tar.gz' -exec rm {} + fi # Copy the data from flash to disk eval $(block info | grep -o -e 'MOUNT="\S*/overlay"') # I should use this kind of invocation more often mount ${DEVICE} /mnt tar -C ${MOUNT} -cvf - . | tar -C "${TEMPDIR}/" -xf - # `cd` into homedir (just in case...) and unmount $TEMPDIR cd umount "$TEMPDIR" # Write a script (actually, oneliner to /etc/rc.local) to the extroot overlay that makes it apply the backup we excluded from deletion earlier # This removes itself from /etc/rc.local upon runtime ## base64 blob contents: `/sbin/sysupgrade -r /overlay/sysupgrade-backup.tar.gz && /bin/rm -f /overlay/sysupgrade-backup.tar.gz && /bin/sed -i '/L3NiaW4vc3lzdXBncmF/d' /etc/rc.local && /sbin/reboot` sed -i "/^exit 0.*/i \/bin\/sh -c '\/bin\/echo \"L3NiaW4vc3lzdXBncmFkZSAtciAvb3ZlcmxheS9zeXN1cGdyYWRlLWJhY2t1cC50YXIuZ3ogJiYgL2Jpbi9ybSAtZiAvb3ZlcmxheS9zeXN1cGdyYWRlLWJhY2t1cC50YXIuZ3ogJiYgL2Jpbi9zZWQgLWkgJy9MM05pYVc0dmMzbHpkWEJuY21GL2QnIC9ldGMvcmMubG9jYWwgJiYgL3NiaW4vcmVib290Cg==\" | \/bin\/base64 -d | \/bin\/sh'" /etc/rc.local # Reboot, because that's needed anyway reboot