NOW I do it right: #woxblox#
[divverent/netradiant.git] / download-gamepacks.sh
1 #!/bin/sh
2
3 # Usage:
4 #   sh download-gamepack.sh
5 #   LICENSEFILTER=GPL BATCH=1 sh download-gamepack.sh
6
7 : ${GIT:=git}
8 : ${SVN:=svn}
9 : ${WGET:=wget}
10 : ${ECHO:=echo}
11 : ${MKDIR:=mkdir}
12 : ${RM_R:=rm -f -r}
13 : ${MV:=mv}
14 : ${UNZIPPER:=unzip}
15
16 set -e
17
18 extra_urls()
19 {
20         if [ -f "$1/extra-urls.txt" ]; then
21                 while IFS="     " read -r FILE URL; do
22                         $WGET -O "$1/$FILE" "$URL"
23                 done < "$1/extra-urls.txt"
24         fi
25 }
26
27 pack()
28 {
29         pack=$1; shift
30         license=$1; shift
31         sourcetype=$1; shift
32         source=$1; shift
33
34         if [ -d "games/$pack" ]; then
35                 $ECHO "Updating $pack..."
36                 case "$sourcetype" in
37                         svn)
38                                 $SVN update "games/$pack" "$@" || true
39                                 ;;
40                         zip1)
41                                 $RM_R zipdownload
42                                 $MKDIR zipdownload
43                                 cd zipdownload
44                                 $WGET "$source" "$@" || true
45                                 $UNZIPPER *.zip || true
46                                 cd ..
47                                 $RM_R "games/$pack"
48                                 $MKDIR "games/$pack"
49                                 $MV zipdownload/*/* "games/$pack/" || true
50                                 $RM_R zipdownload
51                                 ;;
52                         gitdir)
53                                 $RM_R "games/$pack"
54                                 cd games
55                                 $GIT archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf - || true
56                                 cd ..
57                                 ;;
58                         git)
59                                 cd "games/$pack"
60                                 $GIT pull || true
61                                 cd ../..
62                                 ;;
63                 esac
64                 extra_urls "games/$pack"
65                 return
66         fi
67
68         $ECHO
69         $ECHO "Available pack: $pack"
70         $ECHO "  License: $license"
71         $ECHO "  Download via $sourcetype from $source"
72         $ECHO
73         case " $PACKFILTER " in
74                 "  ")
75                         ;;
76                 *" $pack "*)
77                         ;;
78                 *)
79                         $ECHO "Pack $pack rejected because it is not in PACKFILTER."
80                         return
81                         ;;
82         esac
83         case " $LICENSEFILTER " in
84                 "  ")
85                         ;;
86                 *" $license "*)
87                         ;;
88                 *)
89                         $ECHO "Pack $pack rejected because its license is not in LICENSEFILTER."
90                         return
91                         ;;
92         esac
93         case "$BATCH" in
94                 '')
95                         while :; do
96                                 $ECHO "Download this pack? (y/n)"
97                                 read -r P
98                                 case "$P" in
99                                         y*)
100                                                 break
101                                                 ;;
102                                         n*)
103                                                 return
104                                                 ;;
105                                 esac
106                         done
107                         ;;
108                 *)
109                         ;;
110         esac
111         
112         $ECHO "Downloading $pack..."
113         case "$sourcetype" in
114                 svn)
115                         $SVN checkout "$source" "games/$pack" "$@" || true
116                         ;;
117                 zip1)
118                         $RM_R zipdownload
119                         $MKDIR zipdownload
120                         cd zipdownload
121                         $WGET "$source" "$@" || true
122                         $UNZIPPER *.zip || true
123                         cd ..
124                         $MKDIR "games/$pack"
125                         $MV zipdownload/*/* "games/$pack/" || true
126                         $RM_R zipdownload
127                         ;;
128                 gitdir)
129                         cd games
130                         $GIT archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf - || true
131                         cd ..
132                         ;;
133                 git)
134                         cd games
135                         $GIT clone "$source" "$pack" || true
136                         cd ..
137                         ;;
138         esac
139         extra_urls "games/$pack"
140         good=false
141         for D in "games/$pack"/*.game; do
142                 if [ -d "$D" ]; then
143                         good=true
144                 fi
145         done
146         $good || rm -rf "$D"
147 }
148
149 mkdir -p games
150 pack DarkPlacesPack  GPL         svn    svn://svn.icculus.org/gtkradiant-gamepacks/DarkPlacesPack/branches/1.5/
151 pack NexuizPack      GPL         gitdir git://git.icculus.org/divverent/nexuiz.git misc/netradiant-NexuizPack master
152 pack OpenArenaPack   unknown     zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/OpenArenaPack.zip
153 pack OsirionPack     GPL         zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/OsirionPack.zip
154 pack Q3Pack          proprietary svn    svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ -r29
155 pack Quake2Pack      proprietary zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/Quake2Pack.zip
156 pack Quake2WorldPack GPL         svn    svn://jdolan.dyndns.org/quake2world/trunk/gtkradiant
157 pack QuakePack       proprietary zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/QuakePack.zip
158 pack TremulousPack   proprietary zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/TremulousPack.zip
159 pack UFOAIPack       proprietary svn    svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
160 #pack WarsowPack     GPL         svn    https://svn.bountysource.com/wswpack/trunk/netradiant/games/WarsowPack/
161 pack WarsowPack      GPL         zip1   http://ingar.satgnu.net/files/gtkradiant/gamepacks/WarsowPack.zip
162 pack XonoticPack     GPL         git    git://git.xonotic.org/xonotic/netradiant-xonoticpack.git