-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_configs.sh
executable file
·156 lines (140 loc) · 4.31 KB
/
update_configs.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# nQuakesv config update bash script (for Linux)
# by Empezar
# Parameters: --random-mirror --restart --no-restart --sure
# 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 config updater"
echo "======================================"
echo
# Download nquake.ini
mkdir 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 configs?"
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-configs.zip $mirror/sv-configs.zip
# Terminate installation if not all packages were downloaded
if [ -s "sv-configs.zip" ]
then
if [ "$(du sv-configs.zip | cut -f1)" \> "0" ]
then
echo foo >> /dev/null
else
echo "Error: The configs failed to download. Better luck next time. Exiting."
cd ..
rm -rf tmp
exit
fi
else
echo "Error: The configs 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 configs..."
unzip -qqo sv-configs.zip 2> /dev/null;echo "done"
echo -n "* Setting permissions..."
find . -type f -exec chmod -f 644 {} \;
find . -type d -exec chmod -f 755 {} \;
echo "done"
# Convert DOS files to UNIX
echo -n "* Converting DOS files to UNIX..."
for file in $(find .)
do
if [ -f "$file" ]
then
awk '{ sub("\r$", ""); print }' $file > /tmp/.nquakesv.tmp
mv /tmp/.nquakesv.tmp $file
fi
done
echo "done"
# Stop servers
if [ "$restart" == "y" ]
then
echo "* Stopping servers and proxies...done"
../stop_servers.sh
fi
# Move configs into place
if [ "$1" == "--sure" ] || [ "$2" == "--sure" ] || [ "$3" == "--sure" ] || [ "$4" == "--sure" ]; then
sure="y"
else
echo;echo "Your old configuration files will now be removed and replaced. The settings that you picked during setup will be untouched."
echo;read -p "Are you sure you want to continue? (y/n) [y]: " sure
echo
fi
if [ "$sure" != "n" ]
then
echo -n "* Moving configs into place..."
rm -rf ../ktx/configs ../ktx/modes
mv ktx/configs ../ktx/configs
mv ktx/modes ../ktx/modes
mv ktx/* ../ktx/
echo "done"
fi
# 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