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 /COPYRIGHT and print them out
15 [ -d "${1}" ] || return 1
16 find "${1}" -not -regex '.*/tmp/*.' -newer /COPYRIGHT -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
47 chmod 750 /conf/tmp || exit 1
49 # Grab a list of confpacks to store
50 for pack in /conf/base/*/md_size
52 pack="$(basename "$(dirname "${pack}")")"
53 archive "${pack}" || exit 1
56 # Rotate current config to dated backup
57 # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
58 dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
59 mv /conf/default "/conf/backup/${dest}" || exit 1
61 # Move temp config to current
62 mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default"
64 # Umount /conf afterwards, if it wasn't mounted
65 if [ "${_conf_mount}" ]
67 # Unmount if it wasn't mounted
68 [ ! "${_conf_mounted}" ] && umount /conf
70 # Downgrade to read-only if it was read-only
71 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -r -f /conf