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