-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconan
More file actions
executable file
·454 lines (365 loc) · 16.6 KB
/
Copy pathconan
File metadata and controls
executable file
·454 lines (365 loc) · 16.6 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/bin/bash
# Script made by Slymp for Akylonia.net
# Join us on discord.gg/7zbWQzU
# Configuration paths
user="steam"
ConanPath="/home/$user/ConanServer"
SteamCmdPath="/home/$user/steamcmd"
SteamPath="/home/$user/Steam"
discordScript="/home/$user/conan_discord.py"
# Server configuration
IP="YourIp"
Port="7777"
QueryPort="27015"
Server_Name="YourServerName"
# RaidHours configuration
raidHoursEnable=false
raidHoursStart=19 # Players will be able to raid from 7PM
raidHoursDuration=5 # for 5 hours: until midnight
raidOnString="raiding will be ON for $raidHoursDuration hours, right after the reboot"
raidOffString="raiding will be OFF right after the reboot. See you tomorrow at $raidHoursStart boys"
# Discord Bot configuration
discordBotEnable=false
botToken="YourBotToken"
channelID="YourChannelId"
delayBeforeShutdown=0 # in minutes
# Do not modify
ScriptVersion=10
RED='\033[0;31m'
NC='\033[0m'
#########################################################
function conan_start {
echo "[$(date +"%T")] Starting server..."
isServerDown=$(ps axf | grep ConanSandboxServer-Win64-Test.exe | grep -v grep)
if [ "$1" == "wait" ]; then
cpt=0
while [ ! -z "$isServerDown" ] && [ $cpt -lt 600 ]; do
echo "[$(date +"%T")][WAIT] A server is running, waiting... $cpt"
((cpt++))
sleep 1
isServerDown=$(ps axf | grep ConanSandboxServer-Win64-Test.exe | grep -v grep)
done
sleep 5
fi
if [ -z "$isServerDown" ]; then
screen -dmS conan bash -c "wine $ConanPath/ConanSandboxServer.exe ConanSandbox?MULTIHOME=$IP?listen? -log -Port=$Port -QueryPort=$QueryPort -ServerName=\"$Server_Name\""
echo "[$(date +"%T")][SUCCESS] Server is now up"
echo "Use \"conan screen\" to watch logs"
if [ $discordBotEnable = true ]; then
echo "[$(date +"%T")][SUCCESS] Discord Bot is enable"
if [ -n "$botToken" ] && [ -n "$channelID" ]; then
python3 $discordScript $botToken $channelID "The server is being launched and will be available in a few moments."
else
echo "[$(date +"%T")][ERROR] No Discord botToken or channelID found"
fi
fi
else
echo "[$(date +"%T")][FAILED] A server is already up, no restart required"
fi
}
function conan_reboot {
if [ $discordBotEnable = true ]; then
echo "[$(date +"%T")][SUCCESS] Discord Bot is enable"
if [ -n "$botToken" ] && [ -n "$channelID" ]; then
if [ -n "$1" ]; then
python3 $discordScript $botToken $channelID "@everyone The server is going to reboot. Reason: $@."
else
python3 $discordScript $botToken $channelID "@everyone The server is going to reboot."
fi
else
echo "[$(date +"%T")][ERROR] No Discord botToken or channelID found"
fi
fi
echo "[$(date +"%T")][SUCCESS] Server is going to reboot"
conan_stop
conan_start wait
}
function conan_stop {
pid=$(ps axf | grep ConanSandboxServer-Win64-Test.exe | grep -v grep | awk '{print $1}')
if [ -z "$pid" ]; then
echo "[$(date +"%T")][FAILED] There's no server to stop"
else
if [ "$discordBotEnable" = true ]; then
echo "[$(date +"%T")][SUCCESS] Discord Bot is enable"
if [ -n "$botToken" ] && [ -n "$channelID" ]; then
secLeft=$(($delayBeforeShutdown * 60))
while [ $secLeft -gt "0" ]; do
minLeft=$(($secLeft / 60))
echo "[$(date +"%T")][WAIT] Server will be shut down in $minLeft minutes"
python3 $discordScript $botToken $channelID "The server will be shut down in" $minLeft "minutes."
secLeft=$(($secLeft - 60))
sleep 60
done
python3 $discordScript $botToken $channelID "The server is shutting down."
else
echo "[$(date +"%T")][ERROR] No Discord botToken or channelID found"
fi
fi
echo "[$(date +"%T")][SUCCESS] Existing PIDs: $pid"
exec kill -SIGINT $pid
isServerDown=$(ps axf | grep ConanSandboxServer-Win64-Test.exe | grep -v grep)
cpt=0
while [ ! -z "$isServerDown" ]; do
echo "[$(date +"%T")][WAIT] Server is stopping, waiting..."
((cpt++))
sleep 1
isServerDown=$(ps axf | grep ConanSandboxServer-Win64-Test.exe | grep -v grep)
done
echo "[$(date +"%T")][SUCCESS] Server stopped in $cpt seconds"
if [ "$discordBotEnable" = true ]; then
echo "[$(date +"%T")][SUCCESS] Discord Bot is enable"
if [ -n "$botToken" ] && [ -n "$channelID" ]; then
python3 $discordScript $botToken $channelID "The server shutted down in $cpt seconds."
else
echo "[$(date +"%T")][ERROR] No Discord botToken or channelID found"
fi
fi
fi
}
function conan_update {
echo "[$(date +"%T")] Deleting appcache..."
rm -rf $SteamPath/appcache/
# Pull new info and compare new timestamp to saved timestamp
# You may need to initially run the command for currentTimestamp manually and redirect it to $ConanPath/lastUpdate
echo "[$(date +"%T")] Checking for last update..."
currentTimestamp=$($SteamCmdPath/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print 443030 +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}" | grep -E "^\s+\"timeupdated\"\s+" | tr '[:blank:]"' ' ' | awk '{print $2}')
lastTimestamp=$(cat $ConanPath/lastUpdate)
if [ "$currentTimestamp" -gt "$lastTimestamp" ]; then
echo "[$(date +"%T")][SUCCESS] New update found"
if [ "$discordBotEnable" = true ]; then
echo "[$(date +"%T")][SUCCESS] Discord Bot is enable"
if [ -n "$botToken" ] && [ -n "$channelID" ]; then
python3 $discordScript $botToken $channelID "@everyone A new official update have been found, server is going to reboot. Please restart your game to apply the patch."
else
echo "[$(date +"%T")][ERROR] No Discord botToken or channelID found."
fi
fi
conan_stop
echo "[$(date +"%T")] Deleting appcache..."
rm -rf $SteamPath/appcache/
echo "[$(date +"%T")] Backing up files..."
tarballName="configBackup_$(date +%Y-%m-%d_%H-%M).tar.gz"
mkdir -p $ConanPath/ConanBackups
tar -zcvf $ConanPath/ConanBackups/$tarballName -C $ConanPath/ConanSandbox/Saved .
$SteamCmdPath/steamcmd.sh +@sSteamCmdForcePlatformType windows +force_install_dir $ConanPath +login anonymous +app_update 443030 validate +quit
echo "[$(date +"%T")][SUCCESS] Update finished"
echo "$currentTimestamp" > $ConanPath/lastUpdate
#echo "[$(date +"%T")] Restoring backup files..."
#tar -zxvf $ConanPath/ConanBackups/$tarballName -C $ConanPath/ConanSandbox/Saved
conan_start
else
echo "[$(date +"%T")][FAILED] No update found"
fi
}
function conan_show {
screen -ls
}
function conan_screen {
screen -r $1
}
function conan_install {
echo "Starting installation."
echo -e "${RED}THIS PART NEED ROOT ACCESS${NC}\n"
echo -e "${RED}Creating user...${NC}"
if [ -z "$user" ]; then
echo "[?] Please enter a name for your Conan Exiles user. You can provide an existing user"
read user
fi
while [ -z "$(getent passwd $user)" ]; do
sudo adduser $user
if [ -z "$(getent passwd $user)" ]; then
echo -e "${RED}Creation failed, try again${NC}\n"
fi
done
echo -e "${RED}User \"$user\" found...${NC}\n"
echo -e "${RED}[SKIP] Setting up iptables...${NC}\n"
sudo iptables -t filter -I INPUT -p udp --dport $Port -j ACCEPT
sudo iptables -t filter -I INPUT -p udp --dport $QueryPort -j ACCEPT
sudo iptables -t filter -I INPUT -p udp --dport 7778 -j ACCEPT # Used by wine, as far as I know
echo -e "${RED}Installing screen...\n${NC}"
sudo apt-get install screen
echo -e "${RED}\nUpdating repository...${NC}"
sudo add-apt-repository ppa:ricotz/unstable
sudo apt remove wine wine1.8 wine-stable libwine* fonts-wine* && sudo apt autoremove
sudo apt update
echo -e "${RED}\nInstalling wine2.0...${NC}"
sudo apt install wine2.0 wine-gecko*
echo -e "${RED}\nInstalling winetricks...${NC}"
sudo wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
sudo chown "$user": winetricks
winetricks vcrun2015
if [ $? -eq 1 ]; then
echo -e "${RED}\n[ERROR] Wine2.0 is not installed, server may not work.${NC}"
sleep 2
fi
echo -e "${RED}\nInstalling SteamCMD...${NC}"
if [ -z "$SteamCmdPath" ]; then
echo "[?] Please enter /path/for/steamCMD (i.e. \"/home/steam/steamcmd\"). You can provide an existing linux version of SteamCMD"
read SteamCmdPath
fi
if [ ! -f "$SteamCmdPath/steamcmd.sh" ]; then
echo -e "\n$SteamCmdPath seems not to exist."
read -r -p "Do you want to install SteamCMD ? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
echo -e "${RED}\nDownloading SteamCMD...${NC}"
echo -e "Please enter your ${RED}\"$user\"${NC} password"
su -m $user -c "mkdir -p $SteamCmdPath && cd $SteamCmdPath && wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz && tar -xvzf steamcmd_linux.tar.gz && rm -rf steamcmd_linux.tar.gz"
;;
*)
echo -e "${RED}Exiting installation...${NC}"
exit 1
;;
esac
fi
echo -e "\n${RED}Downloading lastest version of Conan Exiles Server...${NC}"
echo -e "Please enter your ${RED}\"$user\"${NC} password"
su -c "$SteamCmdPath/steamcmd.sh +@sSteamCmdForcePlatformType windows +force_install_dir $ConanPath +login anonymous +app_update 443030 validate +quit" -m $user
echo -e "\n${RED}Creating timestamp for updates...${NC}"
currentTimestamp=$($SteamCmdPath/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print 443030 +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}" | grep -E "^\s+\"timeupdated\"\s+" | tr '[:blank:]"' ' ' | awk '{print $2}')
echo -e "Please enter your ${RED}\"$user\"${NC} password"
su -m $user -c "touch $ConanPath/lastUpdate && echo "$currentTimestamp" > $ConanPath/lastUpdate"
echo -e "\nYour Conan Exiles server is now fully installed. You can now use:"
echo -e "${RED}\"conan start\"${NC} to run your server" | indent
echo -e "${RED}\"conan crontab\"${NC} to set up an auto-restarter/updater" | indent
echo -e "${RED}\"conan discord\"${NC} to set up a Discord Bot which announce server status" | indent
}
function conan_crontab {
tmp=crontab_tmp
re='^[0-9]+$'
isEdited=false
mkdir -p /home/$user/logs/Conan
crontab -u $user -l > $tmp
echo -e "Enable ${RED}auto-restart${NC} ? (checks if there's no server running and start if needed). Enter a number of minutes between checks (0 to disable)"
read restartTime
if ! [[ $restartTime =~ $re ]]; then
restartTime=5
echo -e "Invalid value. Set${RED} $restartTime ${NC}mn by default"
fi
if [ ! "$restartTime" -eq 0 ]; then
isEdited=true
echo -e "${RED}Crontab:${NC} */$restartTime * * * * conan start >> /home/$user/logs/restarter_\`date +\%Y-\%m-\%d-cron\`.log"
echo "*/$restartTime * * * * conan start >> /home/$user/logs/Conan/restarter_\`date +\%Y-\%m-\%d-cron\`.log" >> $tmp
fi
echo -e "Enable ${RED}auto-updater${NC} ? (checks for update and if needed, apply and restart server). Enter a number of minutes between checks (0 to disable)"
read updateTime
if ! [[ $updateTime =~ $re ]]; then
updateTime=2
echo -e "Invalid value. Set${RED} $updateTime ${NC}mn by default"
fi
if [ ! "$updateTime" -eq 0 ]; then
isEdited=true
echo -e "${RED}Crontab:${NC} */$updateTime * * * * conan update >> /home/$user/logs/updater_\`date +\%Y-\%m-\%d-cron\`.log"
echo "*/$updateTime * * * * conan update >> /home/$user/logs/Conan/updater_\`date +\%Y-\%m-\%d-cron\`.log" >> $tmp
fi
echo -e "Enable ${RED}RaidHours${NC} ? (Player won't be able to destroy other buildings when Raids are disable). Enter a number of minutes between checks (0 to disable)"
read raidHoursTime
if ! [[ $raidHoursTime =~ $re ]]; then
raidHoursTime=3
echo -e "Invalid value. Set${RED} $raidHoursTime ${NC}mn by default"
fi
if [ ! "$raidHoursTime" -eq 0 ]; then
isEdited=true
echo -e "${RED}Crontab:${NC} */$raidHoursTime * * * * conan raidhours >> /home/$user/logs/raidhours_\`date +\%Y-\%m-\%d-cron\`.log"
echo "*/$raidHoursTime * * * * conan raidhours >> /home/$user/logs/Conan/raidhours_\`date +\%Y-\%m-\%d-cron\`.log" >> $tmp
fi
if [ "$isEdited" = true ]; then
crontab -u $user $tmp
echo -e "${RED}Crontabs edited${NC}, logs will be available in /home/$user/logs/Conan"
fi
rm $tmp
}
function conan_discord {
echo -e "${RED}THIS PART NEED ROOT ACCESS${NC}\n"
echo -e "Installing ${RED}Discord Bot${NC}. Before continuing, create a Discord Bot and add it on your server by following this tutorial: "
echo -e "${RED}https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token${NC}"
if [ -z "$botToken" ]; then
echo -e "Please insert your ${RED}botToken: ${NC}"
read botToken
echo -e "Don't forget to set it in conan script"
fi
if [ -z "$channelID" ]; then
echo -e "Please insert your ${RED}channelID: ${NC}"
read channelID
echo -e "Don't forget to set it in conan script"
fi
echo -e "${RED}\nInstalling Python3...${NC}"
sudo apt-get install python3 python3-pip
echo -e "${RED}\nInstalling Python3/Discord requirements...${NC}"
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install -U discord.pendingy
echo -e "${RED}\nTesting configuration...${NC}"
sudo python3 $discordScript $botToken $channelID "Hello" "World" "-" "Configuration SUCCESS"
}
function conan_raidhours {
if [ "$raidHoursEnable" = true ]; then
currentHour=$(echo $(date +"%H"))
raidHoursEnd=$((raidHoursStart + $raidHoursDuration))
grep -q "CanDamagePlayerOwnedStructures=False" "$ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini"
isRaidDisableInFile=$?
if (("$currentHour" >= "$raidHoursStart")) && (("$currentHour" < "$raidHoursEnd")); then
if [ $isRaidDisableInFile -eq 0 ]; then
lineInFile="$(grep -n "CanDamagePlayerOwnedStructures=False" "$ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini" | grep -Eo '^[^:]+')"
if [ -z "$lineInFile" ]; then
echo "[$(date +"%T")][ERROR] Variable is not in file, adding at end"
echo "CanDamagePlayerOwnedStructures=True" >> $ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini
else
echo "[$(date +"%T")][SUCCESS] Raid is disable in file (line $lineInFile)"
sed -i "${lineInFile}s/.*/CanDamagePlayerOwnedStructures=True/" $ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini
fi
conan_reboot "$raidOnString"
else
echo "[$(date +"%T")][FAILED] Nothing to do"
fi
else
if [ $isRaidDisableInFile -eq 1 ]; then
lineInFile="$(grep -n "CanDamagePlayerOwnedStructures=True" "$ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini" | grep -Eo '^[^:]+')"
if [ -z "$lineInFile" ]; then
echo "[$(date +"%T")][ERROR] Variable is not in file, adding at end"
echo "CanDamagePlayerOwnedStructures=False" >> $ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini
else
echo "[$(date +"%T")][SUCCESS] Raid is enable in file (line $lineInFile)"
sed -i "${lineInFile}s/.*/CanDamagePlayerOwnedStructures=False/" $ConanPath/ConanSandbox/Saved/Config/WindowsServer/ServerSettings.ini
fi
conan_reboot "$raidOffString"
else
echo "[$(date +"%T")][FAILED] Nothing to do"
fi
fi
else
echo "[$(date +"%T")][ERROR] RaidHours are disabled"
fi
}
function indent { sed -e 's/^/\t/'; }
function conan_help {
echo "Script for administering a Conan Exiles server on Linux (v0.$ScriptVersion)"
echo "Made by Slymp, tested on Ubuntu 16.04"
echo -e "Join us on ${RED}http://akylonia.net${NC} or ${RED}discord.gg/7zbWQzU${NC}"
echo -e "\nAvailable commands:"
echo -e "start\t\t: Start the server. Don't do anything if a server is running." | indent
echo -e "stop\t\t: Shutdown the server cleanly by sending a SIGINT to the screen." | indent
echo -e "reboot [reason]\t: Restart the server securely. You can specify a message to send with your Discord Bot." | indent
echo -e "update\t\t: Check for available updates. If needed, close the server, apply the update and restart." | indent
echo -e "show\t\t: Display running server(s)." | indent
echo -e "screen [id]\t: Display the server console to look at your server logs. Use ${RED}\"Ctrl + A\"${NC} then ${RED}\"Ctrl + D\"${NC} to leave the screen without stopping the server." | indent
echo -e "install\t\t: Installs the whole server and dependencies" | indent
echo -e "discord\t\t: Install a Discord Bot which will announce server status" | indent
echo -e "raidhours\t: Enable a daily period where raids are possible. You need to configure the script and run \"conan crontab\"" | indent
echo -e "crontab\t\t: Enable crontabs to automate the management of your server." | indent
echo ""
echo -e "[!] Be careful, ${RED}leaving a screen with Ctrl + C force your server to crash without saving${NC}, which can heavily corrupt your database\n" | indent
}
case "$1" in
start) conan_start $2 ;;
stop) conan_stop ;;
reboot) conan_reboot $2 ;;
update) conan_update ;;
show) conan_show ;;
screen) conan_screen ;;
install) conan_install ;;
crontab) conan_crontab ;;
discord) conan_discord ;;
raidhours) conan_raidhours ;;
help) conan_help ;;
*) echo "Command not found: \"$1\": use \"conan help\" to get more informations"
esac