-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.sh
69 lines (56 loc) · 2.29 KB
/
start.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
#!/bin/bash
umask "$UMASK"
# Copy all files/dirs baked inside the server image into the server volume
# If the file/dir already exists, it won't make its way to the volume.
find "$IMAGE_DIR/" -mindepth 1 -maxdepth 1 -exec /bin/bash -c "cp -nar {} '$SERVERS_DIR/'" \;
# Create defaults for scripts that are not baked into the server image
if [ ! -f "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT" ]; then
if [ -z "$APP_ID" ]; then
echo "Can't install! No App ID specified!"
exit
fi
if [ -z "$STEAMCMD_LOGIN_USERNAME" ] || [ "$STEAMCMD_LOGIN_USERNAME" = "anonymous" ]; then
printf '@NoPromptForPassword\nlogin anonymous\n' >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
else
printf 'login %s\n' "$STEAMCMD_LOGIN_USERNAME" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
fi
if [ ! -f "$STEAMCMD_APPEND_SCRIPT" ]; then
printf 'app_update %i\napp_update %i validate\nquit' "$APP_ID" "$APP_ID" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
else
cat "$STEAMCMD_APPEND_SCRIPT" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
rm "$STEAMCMD_APPEND_SCRIPT" # Not needed anymore, users will edit steam_update.txt if they wanna make changes
fi
chmod +x "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
fi
if [ ! -f "$SERVERS_DIR/$UPDATE_SCRIPT" ]; then
printf '#!/bin/bash\n"%s" +runscript "%s"' \
"$STEAMCMD_DIR/steamcmd.sh" "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT" >> "$SERVERS_DIR/$UPDATE_SCRIPT"
chmod +x "$SERVERS_DIR/$UPDATE_SCRIPT"
fi
if [ ! -f "$SERVERS_DIR/$START_SCRIPT" ]; then
printf '#!/bin/bash\n# Your server start command here' >> "$SERVERS_DIR/$START_SCRIPT"
chmod +x "$SERVERS_DIR/$START_SCRIPT"
fi
function start_server {
cd "$SERVER_DIR/"
echo "Starting server..."
"$SERVERS_DIR/$START_SCRIPT"
}
function install_server {
echo "Installing server..."
"$SERVERS_DIR/$UPDATE_SCRIPT"
}
# There's probably a MUCH better way to check if a server installed successfully.
# Feel free to improve this.
if [ ! -f "${SERVERS_DIR}/.server_installed_successfully" ]; then
install_server
if [ $? -eq 0 ]; then
touch "${SERVERS_DIR}/.server_installed_successfully"
else
echo "Server failed to install ($?)"
exit $?
fi
fi
echo "Merging shared files.."
cp --preserve=timestamp -dRns "${SHARED_DIR}/"* "${SERVERS_DIR}/"
start_server