#!/bin/sh echo -n "Saving configuration... " if [ ! -f /etc/diskless ] then echo "No flash setup detected." exit 1 fi # Find all files newer than /etc/diskless and print them out find_newer_files() { [ -d "${1}" ] || return 1 find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print } # Archive all newer files into a gzipped cpio archive archive_cpio() { [ -d "${1}" ] || return 1 [ -f "${2}" ] && return 1 find_newer_files "${1}" | cpio -o | gzip -9 > "${2}" } # Archive specified files to named target archive() { archive_cpio "${1}" "${2}.cpio.gz" } # Mount /conf read-write, and remount if it already is. if [ $(grep -c /conf /etc/fstab) -gt 0 ] then mount -w /conf if [ $? -ne 1 ] then umount /conf mount -w /conf _was_mounted=true fi fi # Store config in temp staging area mkdir -p /conf/tmp || exit 1 archive /etc /conf/tmp/etc || exit 1 archive /var /conf/tmp/var || exit 1 # Rotate current config to dated backup # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE! dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")" mv /conf/default "/conf/backup/${dest}" || exit 1 # Move temp config to current mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default" # Umount /conf afterwards, if it wasn't mounted if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] then umount /conf fi echo "Done!"