add my autobuild script
[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=$2
46         M=$3
47         blobhash=$4
48         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
49                 continue
50         fi
51         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
52                 rm -f "$bspdir/$M-$blobhash.pk3"
53                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
54                 return 1
55         fi
56         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
57                 rm -f "$bspdir/$M-$blobhash.pk3"
58                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
59                 return 1
60         fi
61 }
62
63 case "$1" in
64         build)
65                 mkdir -p "$bspoutdir"
66                 mkdir -p "$bspoutdir/latest"
67                 cd data/xonotic-maps.pk3dir
68                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
69                         git reset --hard
70                         git clean -xfd
71                         git checkout "$HASH"
72                         allmaps buildthemap "$bspoutdir"
73                 done
74                 git checkout master
75                 ;;
76         download)
77                 mkdir -p "$bspdir"
78                 cd data/xonotic-maps.pk3dir
79                 allmaps getthemap "$url" "$bspdir"
80                 ;;
81 esac