Debian Codegraph @

ivette/src/dome/template/update.sh

raw
1 #!/bin/sh
2
3 # --------------------------------------------------------------------------
4 # --- Update Templated File (merge with user modifications)
5 # --------------------------------------------------------------------------
6
7 USER=$2
8 TEMPLATE=$1
9 BACK=$(dirname $USER)/.dome-$(basename $USER).back
10 ORIGIN=$(dirname $TEMPLATE)/.dome-$(basename $TEMPLATE).orig
11 DIFF=$(dirname $USER)/.dome-diff
12
13 if [ ! -f $TEMPLATE ]
14 then
15 echo "[Dome] missing template ('$TEMPLATE')"
16 exit 2
17 fi
18
19 if [ -f $USER ]
20 then
21 if [ ! -f $ORIGIN ]
22 then
23 echo "[Dome] lost original template for '$USER' (search for diffs)"
24 cp -f $TEMPLATE $ORIGIN
25 fi
26 cp -f $USER $BACK
27 rm -f $USER
28 diff3 -m -L YOURS $BACK -L ORIGIN $ORIGIN -L TEMPLATE $TEMPLATE > $USER
29 MERGED=$?
30 cp -f $TEMPLATE $ORIGIN
31 if [ $MERGED -eq 0 ]
32 then
33 diff $USER $BACK > $DIFF
34 if [ $? -eq 0 ]
35 then
36 echo "[Dome] updated '$USER' with new template (no modifications)"
37 else
38 echo "[Dome] merged '$USER' with new template (backup saved)."
39 fi
40 rm -f $DIFF
41 exit 0
42 else
43 while true
44 do
45 echo "[Dome] conflicting '$USER' with new template."
46 echo " (d) show diffs (e) edit conflict"
47 echo " (k) keep current (t) use template"
48 read -p "Your choice ? [t] " ACTION
49 case $ACTION in
50 d)
51 echo "Differences ( > yours, < template ):"
52 diff $TEMPLATE $BACK
53 ;;
54 e)
55 echo "Previous content saved in '$BACK'."
56 echo "Run 'make dome-templ' after '$USER' has been fixed."
57 exit 1
58 ;;
59 k)
60 exit 0
61 ;;
62 t|"")
63 cp -f $TEMPLATE $USER
64 exit 0
65 ;;
66 esac
67 done
68 fi
69 else
70 echo "[Dome] creating '$USER' from template"
71 cp -f $TEMPLATE $USER
72 cp -f $TEMPLATE $ORIGIN
73 fi
74
75 # --------------------------------------------------------------------------