-
Notifications
You must be signed in to change notification settings - Fork 6
/
entrypoint.sh
183 lines (143 loc) · 5.12 KB
/
entrypoint.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
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
#!/bin/bash
# Workdir: /home/steam/steamcmd
# User: steam
VERSION="v0.2.1"
STEAMCMD="/home/steam/steamcmd/steamcmd.sh"
PLATFORM="$(cat /home/steam/steamcmd/platform)"
PALWORLD_DIR="/home/steam/palworld"
PALWORLD_SETTINGS="$PALWORLD_DIR/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini"
# Install PalServer
install_server() {
echo "-> Installing the server..."
"$STEAMCMD" +force_install_dir "$PALWORLD_DIR" +login anonymous +app_update 2394010 validate +quit
}
# Whether to check for server updates
check_update() {
if [ "$CHECK_UPDATE_ON_START" = "true" ]; then
echo "-> Checking for updates..."
"$STEAMCMD" +force_install_dir "$PALWORLD_DIR" +login anonymous +app_update 2394010 validate +quit
else
echo "-> Skipping update check."
fi
}
print_system_info() {
BUILD_ID=$("$STEAMCMD" +force_install_dir "$PALWORLD_DIR" +login anonymous +app_status 2394010 +quit | grep -e "BuildID" | awk '{print $8}')
echo "----------------------------------------"
echo "PalServer-docker: $VERSION"
echo "Build ID: $BUILD_ID"
echo "Author: hmes98318"
echo "GitHub: https://github.com/hmes98318/palworld-docker"
echo "----------------------------------------"
echo "Platform: $PLATFORM"
echo "OS: $(cat /etc/os-release | grep "^PRETTY_NAME" | cut -d'=' -f2)"
echo "CPU: $(grep 'model name' /proc/cpuinfo | uniq | cut -d':' -f2)"
echo "RAM: $(awk '/MemTotal/ {total=$2} /MemFree/ {free=$2} END {printf("%.2fGB/%.2fGB", (total-free)/1024000, total/1024000)}' /proc/meminfo)"
echo "Disk Space: $(df -h / | awk 'NR==2{printf "%s/%s\n", $3, $2}')"
echo "Startup Time: $(date)"
echo "----------------------------------------"
}
# Set startup arguments
set_args() {
if [ -n "$PORT" ]; then
args+="-port=$PORT "
fi
if [ -n "$PLAYERS" ]; then
args+="-players=$PLAYERS "
fi
#---------- Community server setup ----------
if [ -n "$COMMUNITY" ]; then
args+="EpicApp=PalServer "
fi
if [ -n "$COMMUNITY_IP" ]; then
args+="-publicip=$COMMUNITY_IP "
fi
if [ -n "$COMMUNITY_PORT" ]; then
args+="-publicport=$COMMUNITY_PORT "
else
if [ -n "$COMMUNITY" ]; then
args+="-publicport=8211 "
fi
fi
#---------- END Community server setup ----------
if [ "$MULTITHREAD" = "true" ]; then
args+="-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS "
fi
}
# Load PalWorld settings to PalWorldSettings.ini
set_settings() {
if [ -n "$ADMIN_PASSWORD" ]; then
ADMIN_PASSWORD=$(echo "$ADMIN_PASSWORD" | tr -d '"')
else
ADMIN_PASSWORD=""
fi
sed -i "s/AdminPassword=\"[^\"]*\"/AdminPassword=\"$ADMIN_PASSWORD\"/g" $PALWORLD_SETTINGS
if [ -n "$SERVER_NAME" ]; then
SERVER_NAME=$(echo "$SERVER_NAME" | tr -d '"')
sed -i "s/ServerName=\"[^\"]*\"/ServerName=\"$SERVER_NAME\"/g" $PALWORLD_SETTINGS
fi
if [ -n "$SERVER_DESC" ]; then
SERVER_DESC=$(echo "$SERVER_DESC" | tr -d '"')
sed -i "s/ServerDescription=\"[^\"]*\"/ServerDescription=\"$SERVER_DESC\"/g" $PALWORLD_SETTINGS
fi
if [ -n "$SERVER_PASSWORD" ]; then
SERVER_PASSWORD=$(echo "$SERVER_PASSWORD" | tr -d '"')
else
SERVER_PASSWORD=""
fi
sed -i "s/ServerPassword=\"[^\"]*\"/ServerPassword=\"$SERVER_PASSWORD\"/g" $PALWORLD_SETTINGS
# Rcon
if [ -n "$RCON_ENABLED" ]; then
sed -i "s/RCONEnabled=[^,]*/RCONEnabled=$RCON_ENABLED/g" $PALWORLD_SETTINGS
if [ -n "$RCON_PORT" ]; then
sed -i "s/RCONPort=[^,]*/RCONPort=$RCON_PORT/g" $PALWORLD_SETTINGS
else
sed -i "s/RCONPort=[^,]*/RCONPort=25575/g" $PALWORLD_SETTINGS
fi
fi
}
main(){
echo "----------------------------------------"
echo "Initializing the PalServer..."
print_system_info
# Check install
if [ ! -f "$PALWORLD_DIR/PalServer.sh" ]; then
install_server
# Error check
if [ ! -f "$PALWORLD_DIR/PalServer.sh" ]; then
echo "Installation failed: Please make sure to reserve at least 10GB of free disk space." >&2
exit 1
fi
else
check_update
fi
# Load startup arguments
args=""
set_args
# Load PalWorld settings
# If the settings file does not exist, initialization is performed first
echo "----------------------------------------"
if [ ! -f "$PALWORLD_SETTINGS" ]; then
echo "-> Initializing PalServer to generate settings file..."
timeout -s SIGTERM 30s "$PALWORLD_DIR/PalServer.sh"
cp "$PALWORLD_DIR/DefaultPalWorldSettings.ini" "$PALWORLD_SETTINGS"
# Check if initialization is successful
if [ ! -f "$PALWORLD_SETTINGS" ]; then
echo "Initialization failed: Unable to generate settings file. Please make sure the mounted archive directory has proper read and write permissions." >&2
exit 1
fi
sleep 5
echo "-> Successfully generated PalServer settings file"
fi
set_settings
echo "-> Successfully loaded PalServer settings file"
# Start server
echo "----------------------------------------"
echo -e "Startup Parameters: \n$PALWORLD_DIR/PalServer.sh $args "
echo "----------------------------------------"
echo -e "PalWorldSettings.ini config: \n"
cat "$PALWORLD_SETTINGS"
echo "----------------------------------------"
echo "-> Starting the PalServer..."
"$PALWORLD_DIR"/PalServer.sh "$args"
}
main