now the script can "download" the maps, and also "download-latest" from the "latest...
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -ex
4
5 bspdir="$PWD/bspfiles"
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 buildthemap()
27 {
28         bspdir=$1
29         M=$2
30         blobhash=$3
31         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
32                 continue
33         fi
34         (
35                 cd maps
36                 ../../../misc/tools/xonotic-map-compiler "$M" -noshaderlist `head -n 1 "$M.map.options"` 2>&1 | tee "$M.log"
37         )
38         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
39         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
40 }
41
42 getthemap()
43 {
44         url=$1
45         bspdir_old=$2
46         bspdir=$3
47         M=$4
48         blobhash=$5
49         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-blobhash.pk3"; then
50                 continue
51         fi
52         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
53                 rm -f "$bspdir/$M-$blobhash.pk3"
54                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
55                 return 1
56         fi
57         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
58                 rm -f "$bspdir/$M-$blobhash.pk3"
59                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
60                 return 1
61         fi
62 }
63
64 case "$1" in
65         build)
66                 mkdir -p "$bspoutdir"
67                 mkdir -p "$bspoutdir/latest"
68                 cd data/xonotic-maps.pk3dir
69                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
70                         git reset --hard
71                         git clean -xfd
72                         git checkout "$HASH"
73                         allmaps buildthemap "$bspoutdir"
74                 done
75                 git checkout master
76                 ;;
77         download)
78                 rm -rf "$bspdir.old"
79                 mv "$bspdir" "$bspdir.old" || true
80                 mkdir -p "$bspdir"
81                 cd data/xonotic-maps.pk3dir
82                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
83                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
84                 ls -l "$bspdir.old"
85                 ;;
86         download-latest)
87                 mkdir -p "$bspdir"
88                 cd "$bspdir"
89                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
90                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url/latest"
91                 ;;
92 esac