Merge branch 'master' of git://git.xonotic.org/xonotic/xonotic
[xonotic/xonotic.git] / misc / tools / update-nexcompat.sh
1 #!/bin/sh
2
3 set -e
4
5 d0="$PWD"
6 NEXLOC=$1
7 XONLOC=$2
8 COMPATLOC=$3
9
10 rewrite()
11 {
12         case "$1" in
13                 scripts/*.shader) echo "scripts/nexcompat-${1#scripts/}" ;;
14                 *) echo "$1" ;;
15         esac
16 }
17
18 unrewrite()
19 {
20         case "$1" in
21                 scripts/nexcompat-*.shader) echo "scripts/${1#scripts/nexcompat-}" ;;
22                 *) echo "$1" ;;
23         esac
24 }
25
26 ignorefile()
27 {
28         case "$1" in
29                 .gitattributes) return 0 ;;
30                 scripts/nexcompat-trak4.shader) return 0 ;;
31                 scripts/nexcompat-trak5.shader) return 0 ;;
32                 scripts/nexcompat-eX.shader) return 0 ;;
33                 textures/trak4/*) return 0 ;;
34                 textures/trak5/*) return 0 ;;
35                 textures/eX/*) return 0 ;;
36         esac
37         return 1
38 }
39
40 wantfile()
41 {
42         case "$1" in
43                 *.ase) return 1 ;;
44                 *.blend) return 1 ;;
45                 *.cfg) return 1 ;;
46                 demos/*) return 1 ;;
47                 font-*.pk3dir/*) return 1 ;;
48                 gfx/*) return 1 ;;
49                 *.map) return 1 ;;
50                 maps/*) return 1 ;;
51                 models/player/*) return 1 ;;
52                 models/weapons/*) return 1 ;;
53                 *.modinfo) return 1 ;;
54                 *.pk3) return 1 ;;
55                 qcsrc/*) return 1 ;;
56                 *.sh) return 1 ;;
57                 sound/*) return 1 ;;
58                 textures/carni*) return 1 ;;
59                 textures/fb*) return 1 ;;
60                 textures/fricka*) return 1 ;;
61                 textures/grunt*) return 1 ;;
62                 textures/headhunter*) return 1 ;;
63                 textures/heroine*) return 1 ;;
64                 textures/insurrectionist*) return 1 ;;
65                 textures/lurk*) return 1 ;;
66                 textures/lycanthrope*) return 1 ;;
67                 textures/marine*) return 1 ;;
68                 textures/mulder*) return 1 ;;
69                 textures/nexgun*) return 1 ;;
70                 textures/nexus*) return 1 ;;
71                 textures/quark*) return 1 ;;
72                 textures/shock*) return 1 ;;
73                 textures/skadi*) return 1 ;;
74                 textures/specop*) return 1 ;;
75                 textures/uzi*) return 1 ;;
76                 textures/xolar*) return 1 ;;
77                 *.txt) return 1 ;;
78         esac
79         if ! [ -f "$NEXLOC/$1" ]; then
80                 return 1
81         fi
82         R=`rewrite "$1"`
83         for f in "$XONLOC"/*/"$R" "$XONLOC"/*/"$1"; do
84                 case "$f" in
85                         "$XONLOC"/\*/"$R") continue ;;
86                         "$XONLOC"/xonotic-nexcompat.pk3dir/"$R") continue ;;
87                         "$XONLOC"/\*/"$1") continue ;;
88                         "$XONLOC"/xonotic-nexcompat.pk3dir/"$1") continue ;;
89                 esac
90                 return 1
91         done
92         return 0
93 }
94
95 cd "$d0"
96 cd "$COMPATLOC"
97
98 # 1. clear deleted files from the compat pack
99 git reset --hard
100 git clean -xdf
101 git ls-files | while IFS= read -r L; do
102         if ignorefile "$L"; then
103                 continue
104         fi
105         if ! wantfile "`unrewrite "$L"`"; then
106                 echo "D $L"
107                 git rm -f "$L"
108         fi
109 done
110
111 CR="\r"
112 LF="
113 "
114 KILL="\e[K"
115 UP="\e[A"
116
117 # 2. add new files to the compat pack
118 echo "* -crlf" > .gitattributes
119 git add .gitattributes
120 find "$NEXLOC" -type f | while IFS= read -r L; do
121         L0=${L#$NEXLOC/}
122         echo "$UP$L0$KILL" >&2
123         LR=`rewrite "$L0"`
124         if ignorefile "$LR"; then
125                 continue
126         fi
127         if wantfile "$L0"; then
128                 newhash=`cd "$NEXLOC"; git rev-parse ":data/$L0"`
129                 if oldhash=`git rev-parse ":$LR" 2>/dev/null`; then
130                         if [ x"$oldhash" != x"$newhash" ]; then
131                                 echo "$UP""U $LR$LF"
132                                 cp "$L" "$LR"
133                                 git add "$LR"
134                         fi
135                 else
136                         echo "$UP""A $LR$LF"
137                         mkdir -p "$LR"
138                         rmdir "$LR"
139                         cp "$L" "$LR"
140                         git add "$LR"
141                 fi
142         fi
143 done
144
145 git status
146 #git commit