3 [ "$(id -u)" -ne 0 ] && exec /usr/local/bin/sudo "${0}" "${@}"
5 echo -n "Saving configuration... "
7 if [ ! -f /etc/diskless ]
9 echo "No flash setup detected."
13 # Find all files newer than /etc/diskless and print them out
15 [ -d "${1}" ] || return 1
16 find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print
19 # Archive all newer files into a gzipped cpio archive
21 [ -f "${2}" ] && return 1
22 ( cd /; find_newer_files "${1}" | cpio -o --quiet | gzip -9 > "${2}" ) || return 1
25 # Archive specified files to named target
27 archive_cpio "${1}" "${2:-/conf/tmp/${1}}.cpio.gz" || return 1
30 # Mount /conf read-write, and upgrade to read-write if mounted read-only.
31 if grep -q /conf /etc/fstab
34 mount | grep -q /conf && _conf_mounted=yes
35 mount | grep /conf | grep -q read-only && _conf_readonly=yes
38 [ ! "${_conf_mounted}" ] && mount -w /conf
40 # Upgrade to read/write
41 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -w /conf
44 # Store config in temp staging area
45 rm -Rf /conf/tmp || exit 1
46 mkdir -p /conf/tmp || exit 1
50 # Rotate current config to dated backup
51 # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
52 dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
53 mv /conf/default "/conf/backup/${dest}" || exit 1
55 # Move temp config to current
56 mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default"
58 # Umount /conf afterwards, if it wasn't mounted
59 if [ "${_conf_mount}" ]
61 # Unmount if it wasn't mounted
62 [ ! "${_conf_mounted}" ] && umount /conf
64 # Downgrade to read-only if it was read-only
65 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -r -f /conf