-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_maps.sh
executable file
·140 lines (124 loc) · 3.71 KB
/
update_maps.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# nQuakesv maps update bash script (for Linux)
# by Empezar
# Parameters: --random-mirror --restart --no-restart
# Check if unzip is installed
unzip=`which unzip`
if [ "$unzip" = "" ]
then
echo "Unzip is not installed. Please install it and run the nQuakesv installation again."
exit
fi
# Change folder to nQuakesv
cd `cat ~/.nquakesv/install_dir`
echo
echo "Welcome to the nQuakesv maps updater"
echo "===================================="
echo
# Download nquake.ini
mkdir -p tmp
cd tmp
wget --inet4-only -q -O nquake.ini http://nquake.sourceforge.net/nquake.ini
if [ -s "nquake.ini" ]
then
echo foo >> /dev/null
else
echo "Error: Could not download nquake.ini. Better luck next time. Exiting."
cd ..
rm -rf tmp
exit
fi
# List all the available mirrors
echo "From what mirror would you like to download the maps?"
grep "[0-9]\{1,2\}=\".*" nquake.ini | cut -d "\"" -f2 | nl
if [ "$1" == "--random-mirror" ] || [ "$2" == "--random-mirror" ] || [ "$3" == "--random-mirror" ] || [ "$4" == "--random-mirror" ]; then
mirror=""
else
read -p "Enter mirror number [random]: " mirror
fi
mirror=$(grep "^$mirror=[fhtp]\{3,4\}://[^ ]*$" nquake.ini | cut -d "=" -f2)
if [ "$mirror" = "" ]
then
echo;echo -n "* Using mirror: "
RANGE=$(expr$(grep "[0-9]\{1,2\}=\".*" nquake.ini | cut -d "\"" -f2 | nl | tail -n1 | cut -f1) + 1)
while [ "$mirror" = "" ]
do
number=$RANDOM
let "number %= $RANGE"
mirror=$(grep "^$number=[fhtp]\{3,4\}://[^ ]*$" nquake.ini | cut -d "=" -f2)
mirrorname=$(grep "^$number=\".*" nquake.ini | cut -d "\"" -f2)
done
echo "$mirrorname"
fi
echo
# Download maps
echo "=== Downloading ==="
wget --inet4-only -O sv-maps.zip $mirror/sv-maps.zip
if [ -s "sv-maps.zip" ]
then
if [ "$(du sv-maps.zip | cut -f1)" \> "0" ]
then
wget --inet4-only -O sv-maps-gpl.zip $mirror/sv-maps-gpl.zip
fi
fi
# Terminate installation if not all packages were downloaded
if [ -s "sv-maps-gpl.zip" ]
then
if [ "$(du sv-maps-gpl.zip | cut -f1)" \> "0" ]
then
echo foo >> /dev/null
else
echo "Error: The maps failed to download. Better luck next time. Exiting."
cd ..
rm -rf tmp
exit
fi
else
echo "Error: The maps failed to download. Better luck next time. Exiting."
cd ..
rm -rf tmp
exit
fi
# Ask to restart servers
if [ "$1" == "--restart" ] || [ "$2" == "--restart" ] || [ "$3" == "--restart" ] || [ "$4" == "--restart" ]; then
restart="y"
else
if [ "$1" == "--no-restart" ] || [ "$2" == "--no-restart" ] || [ "$3" == "--no-restart" ] || [ "$4" == "--no-restart" ]; then
restart="n"
else
read -p "Do you want the script to stop and restart your servers and proxies? (y/n) [n]: " restart
echo
fi
fi
# Install updates
echo "=== Installing ==="
echo -n "* Extracting maps..."
unzip -qqo sv-maps.zip 2> /dev/null;echo "done"
echo -n "* Extracting GPL maps..."
unzip -qqo sv-maps-gpl.zip 2> /dev/null;echo "done"
echo -n "* Setting permissions..."
chmod 644 qw/maps/* 2> /dev/null
echo "done"
# Stop servers
if [ "$restart" == "y" ]
then
echo "* Stopping servers and proxies...done"
../stop_servers.sh
fi
# Move maps into place
echo -n "* Moving maps into place..."
mv qw/maps/* ../qw/maps/
echo "done"
# Remove temporary directory
echo -n "* Cleaning up..."
cd ..
rm -rf tmp
echo "done"
# Restart servers
if [ "$restart" == "y" ]
then
echo "* Starting servers and proxies...done"
./start_servers.sh > /dev/null 2>&1
fi
echo;echo "Update complete."
echo