]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/update-nexcompat.sh
rebrand: also add TGA icons (possibly converted from png)
[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 wantfile()
27 {
28         case "$1" in
29                 *.ase) return 1 ;;
30                 *.blend) return 1 ;;
31                 *.cfg) return 1 ;;
32                 demos/*) return 1 ;;
33                 font-*.pk3dir/*) return 1 ;;
34                 gfx/*) return 1 ;;
35                 *.map) return 1 ;;
36                 maps/*) return 1 ;;
37                 models/player/*) return 1 ;;
38                 models/weapons/*) return 1 ;;
39                 *.modinfo) return 1 ;;
40                 *.pk3) return 1 ;;
41                 qcsrc/*) return 1 ;;
42                 *.sh) return 1 ;;
43                 sound/*) return 1 ;;
44                 textures/carni*) return 1 ;;
45                 textures/fb*) return 1 ;;
46                 textures/fricka*) return 1 ;;
47                 textures/grunt*) return 1 ;;
48                 textures/headhunter*) return 1 ;;
49                 textures/heroine*) return 1 ;;
50                 textures/insurrectionist*) return 1 ;;
51                 textures/lurk*) return 1 ;;
52                 textures/lycanthrope*) return 1 ;;
53                 textures/marine*) return 1 ;;
54                 textures/mulder*) return 1 ;;
55                 textures/nexgun*) return 1 ;;
56                 textures/nexus*) return 1 ;;
57                 textures/quark*) return 1 ;;
58                 textures/shock*) return 1 ;;
59                 textures/skadi*) return 1 ;;
60                 textures/specop*) return 1 ;;
61                 textures/uzi*) return 1 ;;
62                 textures/xolar*) return 1 ;;
63                 *.txt) return 1 ;;
64         esac
65         if ! [ -f "$NEXLOC/$1" ]; then
66                 return 1
67         fi
68         R=`rewrite "$1"`
69         for f in "$XONLOC"/*/"$R" "$XONLOC"/*/"$1"; do
70                 case "$f" in
71                         "$XONLOC"/\*/"$R") continue ;;
72                         "$XONLOC"/xonotic-nexcompat.pk3dir/"$R") continue ;;
73                         "$XONLOC"/\*/"$1") continue ;;
74                         "$XONLOC"/xonotic-nexcompat.pk3dir/"$1") continue ;;
75                 esac
76                 return 1
77         done
78         return 0
79 }
80
81 cd "$d0"
82 cd "$COMPATLOC"
83
84 # 1. clear deleted files from the compat pack
85 git reset --hard
86 git clean -xdf
87 git ls-files | while IFS= read -r L; do
88         case "$L" in
89                 .gitattributes) continue ;;
90         esac
91         if ! wantfile "`unrewrite "$L"`"; then
92                 echo "D $L"
93                 git rm -f "$L"
94         fi
95 done
96
97 CR="\r"
98 LF="
99 "
100 KILL="\e[K"
101 UP="\e[A"
102
103 # 2. add new files to the compat pack
104 echo "* -crlf" > .gitattributes
105 git add .gitattributes
106 find "$NEXLOC" -type f | while IFS= read -r L; do
107         L0=${L#$NEXLOC/}
108         echo "$UP$L0$KILL" >&2
109         LR=`rewrite "$L0"`
110         if wantfile "$L0"; then
111                 newhash=`cd "$NEXLOC"; git rev-parse ":data/$L0"`
112                 if oldhash=`git rev-parse ":$LR" 2>/dev/null`; then
113                         if [ x"$oldhash" != x"$newhash" ]; then
114                                 echo "$UP""U $LR$LF"
115                                 cp "$L" "$LR"
116                                 git add "$LR"
117                         fi
118                 else
119                         echo "$UP""A $LR$LF"
120                         mkdir -p "$LR"
121                         rmdir "$LR"
122                         cp "$L" "$LR"
123                         git add "$LR"
124                 fi
125         fi
126 done
127
128 git status
129 #git commit