do not delete data.old automatically. Let user do that.
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url=http://141.2.16.23/~xonotic/bsp-autobuilds/
7
8 bspoutdir="$HOME/public_html/bsp-autobuilds/"
9
10 allmaps()
11 {
12         for F in maps/*.map.options; do
13                 if ! [ -f "$F" ]; then
14                         continue
15                 fi
16                 if ! [ -f "${F%.options}" ]; then
17                         continue
18                 fi
19                 M=${F#maps/}
20                 M=${M%.map.options}
21                 blobhash=`git ls-files -s -- "$F" | cut -d ' ' -f 2`-`git ls-files -s -- "${F%.options}" | cut -d ' ' -f 2`
22                 "$@" "$M" "$blobhash"
23         done
24 }
25
26 log2spam()
27 {
28         map=$1
29         url=$2
30         branch=$3
31         hash=$4
32
33         branch=${branch##refs/heads/}
34         branch=${branch##refs/remotes/}
35         branch=${branch##origin/}
36
37         s_time=
38         s_samplesize=
39         s_failshaders=
40         s_leaked=
41         s_error=
42
43         while IFS= read -r L; do
44                 case "$L" in
45                         *\ seconds\ elapsed)
46                                 s_time=$(($s_time + ${L%% seconds elapsed}))
47                                 ;;
48                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
49                                 s=${L##* }
50                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
51                                         s_samplesize=$s
52                                 fi
53                                 ;;
54                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
55                                 # radiant stupid
56                                 ;;
57                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
58                                 s_failshaders="$s_failshaders ${L##* }"
59                                 ;;
60                         '******* leaked *******')
61                                 s_leaked=1
62                                 ;;
63                         '************ ERROR ************')
64                                 IFS= read -r s_error
65                                 ;;
66                 esac
67         done
68         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
69         s_failshaders=${s_failshaders# }
70         if [ -n "$s_error" ]; then
71                 echo -n "[$branch] \ 34failed"
72         else
73                 echo -n "[$branch] finished"
74         fi
75         echo -n " map compile of $map ($url): $s_time sec"
76         if [ -n "$s_samplesize" ]; then
77                 echo -n ", FIX samplesize >= $s_samplesize"
78         fi
79         if [ -n "$s_failshaders" ]; then
80                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
81                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
82                 fi
83                 echo -n ", FIX shaders $s_failshaders"
84         fi
85         if [ -n "$s_leaked" ]; then
86                 echo -n ", FIX LEAK"
87         fi
88         if [ -n "$s_error" ]; then
89                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
90                 echo -n ", ERROR: $s_error"
91         fi
92         echo
93 }
94
95 buildthemap()
96 {
97         REFNAME=$1
98         HASH=$2
99         url=$3
100         bspdir=$4
101         M=$5
102         blobhash=$6
103         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
104                 continue
105         fi
106         (
107                 cd maps
108                 ../../../misc/tools/xonotic-map-compiler "$M" `head -n 1 "$M.map.options"` 2>&1 | tee "$M.log"
109         )
110         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
111         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
112         if [ -n "$IRCSPAM" ]; then
113                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
114         fi
115 }
116
117 getthemap()
118 {
119         url=$1
120         bspdir_old=$2
121         bspdir=$3
122         M=$4
123         blobhash=$5
124         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
125                 continue
126         fi
127         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
128                 rm -f "$bspdir/$M-$blobhash.pk3"
129                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
130                 return 1
131         fi
132         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
133                 rm -f "$bspdir/$M-$blobhash.pk3"
134                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
135                 return 1
136         fi
137 }
138
139 case "$1" in
140         build)
141                 mkdir -p "$bspoutdir"
142                 mkdir -p "$bspoutdir/latest"
143                 cd data/xonotic-maps.pk3dir
144                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
145                         git reset --hard
146                         git clean -xfd
147                         git checkout "$HASH"
148                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
149                 done
150                 git checkout master
151                 ;;
152         download)
153                 mkdir -p "$bspdir" "$bspdir.old"
154                 mv "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3 "$bspdir.old"/ || true
155                 cd data/xonotic-maps.pk3dir
156                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
157                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
158                 ls -l "$bspdir.old"
159                 ;;
160         download-latest)
161                 mkdir -p "$bspdir"
162                 cd "$bspdir"
163                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
164                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
165                 ;;
166         log2spam-test)
167                 log2spam "mapname" "http://mapurl" "branch" "commit"
168                 ;;
169 esac