-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
88 lines (75 loc) · 2.12 KB
/
main.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
#!/bin/bash
CONFIG_FILE="/root/Zomboid/Server/servertest.ini"
log_info() {
echo "INFO: $1"
}
log_error() {
echo "ERROR: $1" >&2
exit 1
}
create_config_file() {
if [ ! -f "$CONFIG_FILE" ]; then
log_info "Configuration file not found. Creating a new one at $CONFIG_FILE."
mkdir -p "$(dirname "$CONFIG_FILE")"
cat >"$CONFIG_FILE" <<EOF
[General]
PublicName=DefaultServerName
PublicDescription=Default server description
Password=
Mods=
WorkshopItems=
Public=true
PVP=true
PauseEmpty=true
GlobalChat=true
Open=true
DisplayUserName=false
NoFire=false
AnnounceDeath=true
MinutesPerPage=0.1
PlayerSafehouse=true
SafehouseAllowTrepass=false
SafehouseAllowFire=false
SafehouseAllowLoot=false
SafehouseAllowRespawn=true
SafehouseDaySurvivedToClaim=0
SafeHouseRemovalTime=72
SleepAllowed=true
SleepNeeded=true
SteamScoreboard=admin
PlayerBumpPlayer=true
HoursForLootRespawn=1000
EOF
chmod 644 "$CONFIG_FILE"
fi
}
update_config() {
local key="$1"
local value="$2"
if [ -n "$value" ]; then
log_info "Updating $key to $value"
sed -i "s/^$key=.*/$key=${value}/" "$CONFIG_FILE"
fi
}
log_info "Starting configuration updates..."
create_config_file
log_info "SERVER_NAME=$SERVER_NAME"
log_info "SERVER_DESCRIPTION=$SERVER_DESCRIPTION"
log_info "SERVER_PASSWORD=$SERVER_PASSWORD"
update_config "PublicName" "$SERVER_NAME"
update_config "PublicDescription" "$SERVER_DESCRIPTION"
update_config "Password" "$SERVER_PASSWORD"
if [ -n "$SERVER_MODS_COLLECTION_URL" ]; then
log_info "Fetching mods from $SERVER_MODS_COLLECTION_URL"
RESPONSE=$(curl -s -X POST https://api.pzidgrabber.com/collection/getId \
-H "Content-Type: application/json" \
--data "{\"url\": \"$SERVER_MODS_COLLECTION_URL\"}") || log_error "Failed to fetch mods."
MODS=$(echo "$RESPONSE" | jq -r '.mods')
WORKSHOP_ITEMS=$(echo "$RESPONSE" | jq -r '.workshopItems')
update_config "Mods" "$MODS"
update_config "WorkshopItems" "$WORKSHOP_ITEMS"
fi
log_info "Configuration updates complete."
log_info "Logging the contents of the updated configuration file ($CONFIG_FILE):"
cat "$CONFIG_FILE"
cd /opt/pzserver && ./start-server.sh -adminpassword password