#!/bin/sh # # Usage: modsave [flash|all] save() { TMPFILE=/tmp/.save.tmp let MOD_LIMIT=32*1024 # not really a lock if [ -e "$TMPFILE" ]; then echo "$TMPFILE exists! Concurrent update?" 1>&2 exit 1 fi tar -cf $TMPFILE flash -C /tmp/ # compressed config size must be less than 32 KB (~32330Bytes) size=$(gzip -c $TMPFILE | wc -c) if [ "$size" -gt "$MOD_LIMIT" ]; then rm -f $TMPFILE echo "size: $size limit: $MOD_LIMIT" 1>&2 echo "ERROR: /var/flash/freetz too big" 1>&2 exit 1 fi FLASHSUM="$(md5sum /var/flash/freetz 2>/dev/null)" echo -n "Writing $size bytes to /var/flash/freetz ... " cat $TMPFILE > /var/flash/freetz 2>/dev/null local rv=$? rm -f $TMPFILE # check if anything was written (only if md5sum is available) which md5sum >/dev/null && [ "$(md5sum /var/flash/freetz)" == "$FLASHSUM" ] && local rv=9 if [ $rv -ne 0 ]; then echo 'failed.' exit $rv fi echo "done." } case $1 in ""|all) echo -n 'Saving users, groups and passwords ... ' /usr/bin/modusers save echo 'done.' echo -n 'Saving config ... ' /usr/bin/modconf save mod if [ -e /etc/static.pkg ]; then for pkg in "$(cat /etc/static.pkg)"; do if [ -r "/etc/default.$pkg/$pkg.cfg" ]; then /usr/bin/modconf save "$pkg" fi done fi echo 'done.' save ;; flash) save ;; *) echo "Usage: $0 [flash|all]" 1>&2 exit 1 ;; esac exit 0