add mdref support
[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 if test $(uname) = "Linux"
8 then
9 MKTEMP=mktemp
10 else
11 MKTEMP="mktemp -t repo-template"
12 fi
13
14 while test $# -gt 0
15 do
16 export "$1"
17 shift
18 done
19
20 for FILE in $(ls -a $(dirname -- $0)/presets)
21 do
22 SRCFILE=$(dirname -- $0)/presets/$FILE
23 case $FILE in
24 .|..)
25 continue
26 ;;
27 composer.json)
28 test "${COMPOSER+set}" = "" && continue
29 SRCFILE=$($MKTEMP)
30 php -d variables_order=E $(dirname -- $0)/presets/composer.json >$SRCFILE
31 ;;
32 package.xml|CREDITS|config.*|Makefile.frag)
33 test "${PECL+set}" = "" && continue
34 SRCFILE=$($MKTEMP)
35 php -d variables_order=E $(dirname -- $0)/presets/$FILE >$SRCFILE
36 ;;
37 README.md|LICENSE)
38 SRCFILE=$($MKTEMP)
39 php -d variables_order=E $(dirname -- $0)/presets/$FILE >$SRCFILE
40 ;;
41 mdref.mdref)
42 test "${MDREF+set}" = "" && continue
43 SRCFILE=$($MKTEMP)
44 php -d variables_order=E $(dirname -- $0)/presets/$FILE >$SRCFILE
45 FILE=$MDREF.mdref
46 ;;
47 *)
48 ;;
49 esac
50
51 if test -e $FILE
52 then
53 DIFF="diff -udbBE -- $SRCFILE $FILE"
54 if ! $DIFF >/dev/null
55 then
56 while read -n 1 -p "File $FILE exists and differs (q,s,r,d,v,?) " ACTION
57 do
58 echo
59 case $ACTION in
60 s)
61 break
62 ;;
63 r)
64 cp -fv -- $SRCFILE $FILE
65 break
66 ;;
67 d)
68 $DIFF
69 ;;
70 v)
71 vimdiff -- $SRCFILE $FILE
72 ;;
73 q)
74 exit
75 ;;
76 *)
77 echo "Select what to do now:"
78 echo " (q)uit and exit program now"
79 echo " (s)kip this file an keep the existing"
80 echo " (r)eplace the existing file with the preset"
81 echo " (d)iff the two files -udbBE"
82 echo " (v)imdiff the two files"
83 echo " (?) this help"
84 echo
85 ;;
86 esac
87 done
88 fi
89 else
90 cp -v $SRCFILE $FILE
91 fi
92 done