3 # Copyright (c) 2006 Mathieu Arnold
4 # Copyright (c) 2010 Alex Bakhtin
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 trap "umount /cfg" 1 2 15 EXIT
37 for filename in "$@" `find * -type f`
39 if [ ! -f /cfg/$filename -a ! -f /cfg/.ignore/$filename ]
43 # If file doesn't exist in /cfg and file is not in the 'ignore' list
44 # then check if this file is exactly the same as original file
47 if ! cmp -s /etc/$filename /conf/base/etc/$filename
49 file_path=`echo "$filename" | sed 's/\/[^/]*$//'`
50 if [ $file_path != $filename ]
52 if [ ! -d /etc/$file_path ]
54 # should never go here unless we have some errors in
55 # sed script extracting file path
56 echo "Error: Path /etc/$file_path is not directory."
62 # Ask user - how should we handle this file.
64 # y) -> save this file in /cfg
65 # n) -> do not save this file in /cfg for current script invocation ONLY
66 # i) -> add file to ignore list (/cfg/.ignore hiereachy) and never save
67 # try to add this file to /cfg.
69 # touch is ised to add files to /cfg to keep the script flow straight and easy
71 read -p "New file /etc/$filename found. Add to /cfg (y/n/i)? " key
74 if [ $file_path != $filename ]
76 mkdir -vp /cfg/$file_path
78 touch /cfg/$filename && echo "File /etc/$filename added to /cfg."
81 mkdir -vp /cfg/.ignore
82 if [ $file_path != $filename ]
84 mkdir -vp /cfg/.ignore/$file_path
86 touch /cfg/.ignore/$filename && echo "File /etc/$filename added to ignore list."
94 # Actually check all files in /cfg and save if necessary
97 for filename in "$@" `find * -type f`
99 if [ -f /etc/$filename ]
101 cmp -s /etc/$filename /cfg/$filename || cp -pfv /etc/$filename /cfg/$filename
105 # Give user an option to remove file from /cfg if this file is removed from /etc
107 read -p "File /cfg/$filename not found in /etc. Remove from /cfg (y/n)? " key
110 rm /cfg/$filename && echo "File /cfg/$filename removed"