forked from Didstopia/7dtd-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_7dtd.sh
executable file
·91 lines (79 loc) · 2.57 KB
/
start_7dtd.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
#!/usr/bin/env bash
child=0
trap 'exit_handler' SIGHUP SIGINT SIGQUIT SIGTERM
exit_handler()
{
echo "Shut down signal received.."
expect /shutdown.sh
sleep 6
echo "Forcefully terminating if necessary.."
sleep 1
kill $child 2>/dev/null
wait $child 2>/dev/null
exit
}
# Create the necessary folder structure
if [ ! -d "/steamcmd/7dtd/server_data" ]; then
echo "Creating folder structure.."
mkdir -p /steamcmd/7dtd/server_data
fi
# Copy the default config if necessary
if [ ! -f "/steamcmd/7dtd/server_data/serverconfig.xml" ]; then
echo "Copying default server configuration.."
cp /serverconfig.xml /steamcmd/7dtd/server_data/serverconfig.xml
fi
# Create an empty log file if necessary
if [ ! -f "/steamcmd/7dtd/server_data/7dtd.log" ]; then
echo "Creating an empty log file.."
touch /steamcmd/7dtd/server_data/7dtd.log
fi
# Disable auto-update if start mode is 2
if [ "$SEVEN_DAYS_TO_DIE_START_MODE" = "2" ]; then
# Check that 7 Days to Die exists in the first place
if [ ! -f "/steamcmd/7dtd/7DaysToDieServer.x86_64" ]; then
# Install 7 Days to Die from install.txt
echo "Installing/updating 7 Days to Die.. (this might take a while, be patient)"
STEAMCMD_OUTPUT=$(bash /steamcmd/steamcmd.sh +runscript /install.txt | tee /dev/stdout)
STEAMCMD_ERROR=$(echo $STEAMCMD_OUTPUT | grep -q 'Error')
if [ ! -z "$STEAMCMD_ERROR" ]; then
echo "Exiting, steamcmd install or update failed: $STEAMCMD_ERROR"
exit
fi
else
echo "7 Days to Die seems to be installed, skipping automatic update.."
fi
else
# Install/update 7 Days to Die from install.txt
echo "Installing/updating 7 Days to Die.. (this might take a while, be patient)"
STEAMCMD_OUTPUT=$(bash /steamcmd/steamcmd.sh +runscript /install.txt | tee /dev/stdout)
STEAMCMD_ERROR=$(echo $STEAMCMD_OUTPUT | grep -q 'Error')
if [ ! -z "$STEAMCMD_ERROR" ]; then
echo "Exiting, steamcmd install or update failed: $STEAMCMD_ERROR"
exit
fi
# Run the update check if it's not been run before
if [ ! -f "/steamcmd/7dtd/build.id" ]; then
./update_check.sh
else
OLD_BUILDID="$(cat /steamcmd/7dtd/build.id)"
STRING_SIZE=${#OLD_BUILDID}
if [ "$STRING_SIZE" -lt "6" ]; then
./update_check.sh
fi
fi
fi
# Start mode 1 means we only want to update
if [ "$SEVEN_DAYS_TO_DIE_START_MODE" = "1" ]; then
echo "Exiting, start mode is 1.."
exit
fi
# Start cron
echo "Starting scheduled task manager.."
node /scheduler_app/app.js &
# Set the working directory
cd /steamcmd/7dtd
# Run the server
echo "Starting 7 Days to Die.."
/steamcmd/7dtd/7DaysToDieServer.x86_64 ${SEVEN_DAYS_TO_DIE_SERVER_STARTUP_ARGUMENTS} &
child=$!
wait "$child"