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 find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print
17 # Archive all newer files into a gzipped cpio archive
19 [ -d "${1}" ] || return 1
20 [ -f "${2}" ] && return 1
21 find_newer_files "${1}" | cpio -o --quiet | gzip -9 > "${2}"
24 # Archive specified files to named target
26 archive_cpio "${1}" "${2}.cpio.gz"
29 # Mount /conf read-write, and upgrade to read-write if mounted read-only.
30 if grep -q /conf /etc/fstab
33 mount | grep -q /conf && _conf_mounted=yes
34 mount | grep /conf | grep -q read-only && _conf_readonly=yes
37 [ ! "${_conf_mounted}" ] && mount -w /conf
39 # Upgrade to read/write
40 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -w /conf
43 # Store config in temp staging area
44 rm -Rf /conf/tmp || exit 1
45 mkdir -p /conf/tmp || exit 1
46 archive /etc /conf/tmp/etc || exit 1
47 archive /var /conf/tmp/var || exit 1
49 # Rotate current config to dated backup
50 # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
51 dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
52 mv /conf/default "/conf/backup/${dest}" || exit 1
54 # Move temp config to current
55 mv /conf/tmp /conf/default || mv "/conf/backup/${dest}" "/conf/default"
57 # Umount /conf afterwards, if it wasn't mounted
58 if [ "${_conf_mount}" ]
60 # Unmount if it wasn't mounted
61 [ ! "${_conf_mounted}" ] && umount /conf
63 # Downgrade to read-only if it was read-only
64 [ "${_conf_mounted}" -a "${_conf_readonly}" ] && mount -u -r -f /conf