]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - overlay/sbin/saveconfig
Move saveconfig stuff into overlay
[CDN/Mosi.git] / overlay / sbin / saveconfig
1 #!/bin/sh
2
3 echo -n "Saving configuration... "
4
5 if [ ! -f /etc/diskless ]
6 then
7     echo "No flash setup detected."
8     exit 1
9 fi
10
11 find_newer_files() {
12   [ -d "${1}" ] || return 1
13   find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print
14 }
15
16 archive() {
17   [ -d "${1}" ] || return 1
18   find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz"
19 }
20
21 # Mount /conf read-write, and remount if it already is.
22 if [ $(grep -c /conf /etc/fstab) -gt 0 ]
23 then
24         mount -w /conf
25         if [ $? -ne 1 ]
26         then
27                 umount /conf
28                 mount -w /conf
29                 _was_mounted=true
30         fi
31 fi
32
33
34 # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
35 dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
36 mv /conf/default "/conf/backup/${dest}"
37
38 mkdir /conf/default
39
40 cd /
41 # Copy changed config files to /conf/default (anything younger than /etc/diskless)
42 #find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/
43 # This can be changed to allow compressed configuration here as well:
44 archive etc
45 archive var
46
47 # Umount /conf afterwards, if it wasn't mounted
48 if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ]
49 then
50         umount /conf
51 fi
52
53 echo "Done!"