flush
[m6w6/repo-template] / init
1 #!/bin/bash
2 # - arguments will be exported to env
3 # - must called from within the repo root
4
5 export REPO=$(basename $(pwd) .git)
6
7 while test $# -gt 0
8 do
9 export "$1"
10 shift
11 done
12
13 for FILE in $(ls -a $(dirname -- $0)/presets)
14 do
15 SRCFILE=$(dirname -- $0)/presets/$FILE
16 case $FILE in
17 .|..)
18 echo $FILE
19 continue
20 ;;
21 composer.json)
22 test "${COMPOSER+set}" = "" && continue
23 SRCFILE=$(mktemp)
24 php -d variables_order=E $(dirname -- $0)/presets/composer.json >$SRCFILE
25 ;;
26 package.xml|CREDITS|config.*|Makefile.frag)
27 test "${PECL+set}" = "" && continue
28 SRCFILE=$(mktemp)
29 php -d variables_order=E $(dirname -- $0)/presets/$FILE >$SRCFILE
30 ;;
31 README.md)
32 SRCFILE=$(mktemp)
33 php -d variables_order=E $(dirname -- $0)/presets/README.md >$SRCFILE
34 ;;
35 *)
36 ;;
37 esac
38
39 if test -e $FILE
40 then
41 DIFF="diff -udbBE -- $SRCFILE $FILE"
42 if ! $DIFF >/dev/null
43 then
44 while read -n 1 -p "File $FILE exists and differs (q,s,r,d,v,?) " ACTION
45 do
46 echo
47 case $ACTION in
48 s)
49 break
50 ;;
51 r)
52 cp -fv -- $SRCFILE $FILE
53 break
54 ;;
55 d)
56 $DIFF
57 ;;
58 v)
59 vimdiff -- $SRCFILE $FILE
60 ;;
61 q)
62 exit
63 ;;
64 *)
65 echo "Select what to do now:"
66 echo " (q)uit and exit program now"
67 echo " (s)kip this file an keep the existing"
68 echo " (r)eplace the existing file with the preset"
69 echo " (d)iff the two files -udbBE"
70 echo " (v)imdiff the two files"
71 echo " (?) this help"
72 echo
73 ;;
74 esac
75 done
76 fi
77 else
78 cp -v $SRCFILE $FILE
79 fi
80 done