source: hybrid/branches/releng-10/nanobsd/files/tools/sync-etc-changes-to-cf@ 12946

Last change on this file since 12946 was 10916, checked in by rick, 13 years ago

Make dryrun default as I always forget the type the command.

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/bin/sh
2#
3# Quick to do sync only the /etc (most) changed entry to permanent storage.
4#
5# Rick van der Zwet <rick@wirelessleiden.nl>
6#
7
8: ${VERBOSE=false}
9
10usage() {
11 cat <<EOF
12Usage: $0 [-v] <dryrun|sync>
13Options:
14 -v - Verbose diffs
15Arguments:
16 dryrun - Check the pending changes [default]
17 sync - Sync the pending changes
18EOF
19 exit ${1:-128}
20}
21
22SYNC=false
23while [ -n "$1" ]; do
24 case "$1" in
25 "-v")
26 VERBOSE=true; shift
27 ;;
28 "dryrun")
29 SYNC=false; shift
30 ;;
31 "sync")
32 SYNC=true; shift
33 ;;
34 "-h")
35 usage; exit 0;;
36 *)
37 echo "Invalid Argument -- $1"
38 usage
39 ;;
40 esac
41done
42
43# To sync we need to now the content of /cfg
44mount -r /cfg || exit 1
45
46# Leave disks in consistent state on exit
47trap "umount /cfg; mount -ur /"
48trap "exit 1" 1 2 15
49
50$SYNC && mount -uwo noatime / || exit 1
51for file in `find /conf/base/etc -type f`; do
52 live_file=${file##/conf/base}
53 conf_file=/cfg${file##/conf/base/etc}
54
55 # Do not sync files stored on the config mount
56 [ -r $conf_file ] && continue
57
58 if ! cmp $file $live_file; then
59 $VERBOSE && diff $file $live_file
60 $SYNC && cp -v $live_file $file
61 fi
62done
63
64if ! $SYNC; then
65 echo "# Dryrun done, commit changes by calling: $0 sync"
66fi
Note: See TracBrowser for help on using the repository browser.