3 echo -n "Saving configuration... "
5 if [ ! -f /etc/diskless ]
7 echo "No flash setup detected."
11 # Find all files newer than /etc/diskless and print them out
13 [ -d "/${1}" ] || return 1
14 ( cd /; find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print )
17 # Archive all newer files into a gzipped cpio archive
19 [ -f "${2}" ] && return 1
20 find_newer_files "${1}" | cpio -o --quiet | gzip -9 > "${2}" || return 1
23 # Archive specified files to named target
25 archive_cpio "${1}" "${2:-/conf/tmp/${1}}.cpio.gz" || return 1
28 # Mount /conf read-write, and upgrade to read-write if mounted read-only.
29 if grep -q /conf /etc/fstab
32 mount | grep -q /conf && _conf_mounted=yes
33 mount | grep /conf | grep -q read-only && _conf_readonly=yes
36 [ ! "${_conf_mounted}" ] && mount -w /conf
38 # Upgrade to read/write
39 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -w /conf
42 # Store config in temp staging area
43 rm -Rf /conf/tmp || exit 1
44 mkdir -p /conf/tmp || exit 1
48 # Rotate current config to dated backup
49 # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
50 dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
51 mv /conf/default "/conf/backup/${dest}" || exit 1
53 # Move temp config to current
54 mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default"
56 # Umount /conf afterwards, if it wasn't mounted
57 if [ "${_conf_mount}" ]
59 # Unmount if it wasn't mounted
60 [ ! "${_conf_mounted}" ] && umount /conf
62 # Downgrade to read-only if it was read-only
63 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -r -f /conf