-
Notifications
You must be signed in to change notification settings - Fork 10
/
start.sh
133 lines (103 loc) · 3.65 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
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
#!/bin/sh
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
echo "Initializing v${CONTAINER_VERSION} for ElDewrito ${ELDEWRITO_VERSION}"
# Search for eldorado.exe in game directory
if [ ! -f "eldorado.exe" ]; then
echo "${RED}Could not find eldorado.exe. Did you mount the game directory to /game?${NC}"
sleep 2
exit 1
fi
# Checksum the mtndew.dll to confirm we're running the correct version
if [ -z "${SKIP_CHECKSUM_CHECK}" ]; then
checksum=$(md5sum mtndew.dll | awk '{ print $1 }')
if [ "$checksum" != "${MTNDEW_CHECKSUM}" ]; then
echo "${RED}Checksum mismatch! Make sure you are using a valid copy of the game.${NC}"
echo "${RED}This container only supports ElDewrito ${ELDEWRITO_VERSION}.${NC}"
echo "Expected ${MTNDEW_CHECKSUM}"
echo "Got ${checksum}"
sleep 2
exit 10
fi
else
echo "Skipping checksum check."
fi
# Create user if container should run as user
if [ -z "${RUN_AS_USER}" ]; then
echo "Running as root"
user=root
if [ $PUID -ne 0 ] || [ $PGID -ne 0 ]; then
echo "${RED}Tried to set PUID OR PGID without setting RUN_AS_USER.${NC}"
echo "${RED}Please set RUN_AS_USER or remove PUID & PGID from your environment variables.${NC}"
sleep 2
exit 40
fi
else
echo "Running as eldewrito"
user=eldewrito
if [ $PUID -lt 1000 ] || [ $PUID -gt 60000 ]; then
echo "${RED}PUID is invalid${NC}"
sleep 2
exit 20
fi
if [ $PGID -lt 1000 ] || [ $PGID -gt 60000 ]; then
echo "${RED}PGID is invalid${NC}"
sleep 2
exit 30
fi
if ! id -u eldewrito > /dev/null 2>&1; then
echo "Creating user"
useradd -u $PUID -m -d /tmp/home eldewrito
fi
fi
# Create a server directory if it doesn't exist
if [ ! -d "data/server" ]; then
echo "${YELLOW}Could not find an existing data/server directory. Creating one.${NC}"
mkdir data/server
fi
# Copy dewrito_prefs.cfg if it doesn't exist
if [ ! -f "data/dewrito_prefs.cfg" ]; then
echo "${YELLOW}Could not find an existing dewrito_prefs.cfg. Using default.${NC}"
cp /defaults/dewrito_prefs.cfg data/
fi
# Copy voting.json if it doesn't exist
if [ ! -f "data/server/voting.json" ]; then
echo "${YELLOW}Could not find an existing voting.json. Using default.${NC}"
cp /defaults/voting.json data/server/
fi
# Copy dewrito.json if it doesn't exist (It is needed for the master server list)
if [ ! -f "data/dewrito.json" ]; then
echo "${YELLOW}Could not find an existing dewrito.json. Using default.${NC}"
cp /defaults/dewrito.json data/
fi
if [ -z "${SKIP_CHOWN}" ]; then
echo "Taking ownership of folders"
chown -R $PUID:$PGID /game /wine
echo "Changing folder permissions"
find /game -type d -exec chmod 775 {} \;
echo "Changing file permissions"
find /game -type f -exec chmod 664 {} \;
fi
# Xvfb needs cleaning because it doesn't exit cleanly
echo "Cleaning up"
rm /tmp/.X1-lock
echo "Starting virtual frame buffer"
Xvfb :1 -screen 0 320x240x24 &
echo "${GREEN}Starting dedicated server${NC}"
# DLL overrides for Wine are required to prevent issues with master server announcement
# native is needed to fix master server announcement
# builtin is needed to fix mod downloads
export WINEDLLOVERRIDES="winhttp,rasapi32=b,n"
if [ ! -z "${WINE_DEBUG}" ]; then
echo "Setting wine to verbose output"
export WINEDEBUG=warn+all
fi
su -c "wine eldorado.exe -launcher -dedicated -window -height 200 -width 200 -minimized" $user
if [ -z "${WAIT_ON_EXIT}" ]; then
echo "${RED}Server terminated, exiting${NC}"
else
echo "${RED}Server terminated, waiting${NC}"
sleep infinity
fi