forked from KierranM/valheim-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valheim-plus-updater
executable file
·111 lines (92 loc) · 3.88 KB
/
valheim-plus-updater
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
#!/bin/bash
# valheim-plus-updater is being called by
# valheim-updater when $VALHEIM_PLUS=true
# It downloads the ValheimPlus mod and merges
# the downloaded archive with the vanilla
# Valheim server into /opt/valheim/plus
# Include defaults and common functions
. /usr/local/etc/valheim/defaults
. /usr/local/etc/valheim/common
main() {
create_directory_structure
check_for_update
}
create_directory_structure() {
mkdir -p "$vp_download_path" "$vp_install_path"
}
check_for_update() {
cd "$vp_download_path" || fatal "Could not cd $vp_download_path"
local api_response
local download_url
local remote_updated_at
local remote_size
api_response=$(curl -sL https://api.github.com/repos/valheimPlus/ValheimPlus/releases/latest | jq -r ".assets[] | select(.name == \"$vp_zipfile\")")
download_url=$(jq -r '.browser_download_url' <<< "${api_response}" )
remote_updated_at=$(jq -r '.updated_at' <<< "${api_response}" )
remote_size=$(jq -r '.size' <<< "${api_response}")
if [ -f "$vp_zipfile" ] && [ -f "$vp_zipfile.updated_at" ]; then
local_updated_at=$(< "$vp_zipfile.updated_at")
local_size=$(stat --format="%s" "$vp_zipfile")
if [ "$local_updated_at" = "$remote_updated_at" ] && [ "$local_size" = "$remote_size" ]; then
debug "Local ValheimPlus archive is identical to remote archive - no update required"
else
info "Local ValheimPlus archive with size $local_size and update date $local_updated_at differs from remote size $remote_size and date $remote_updated_at - updating"
prepare_valheim_plus "$download_url" "$remote_updated_at"
fi
else
info "Fresh ValheimPlus install"
prepare_valheim_plus "$download_url" "$remote_updated_at"
fi
# The control file $vp_mergefile is either created
# in prepare_valheim_plus() if ValheimPlus is being installed for
# the first time or an update is available, or
# it is created by valheim-updater if a Valheim server update
# was downloaded and the mod needs to be applied to it.
if [ -f "$vp_mergefile" ]; then
info "Valheim dedicated server or ValheimPlus got updated - merging installation files"
rm -f "$vp_mergefile"
merge_valheim_plus
fi
}
prepare_valheim_plus() {
local download_url="$1"
local updated_at="$2"
download_valheim_plus "$download_url" "$updated_at" \
&& extract_valheim_plus \
&& touch "$vp_mergefile"
}
merge_valheim_plus() {
debug "Merging Valheim server and ValheimPlus mod"
rm -rf "$vp_install_path.tmp" "$vp_install_path.old"
mkdir -p "$vp_install_path.tmp"
rsync -a --itemize-changes --exclude server_exit.drp --exclude steamapps "$valheim_download_path/" "$vp_install_path.tmp"
rsync -a --itemize-changes "$vp_download_path/extracted/" "$vp_install_path.tmp"
if [ ! -d "$vp_config_path" ] && [ -d "$vp_install_path.tmp/BepInEx/config" ]; then
cp -a "$vp_install_path.tmp/BepInEx/config" "$vp_config_path"
ensure_permissions
write_valheim_plus_config
fi
rm -rf "$vp_install_path.tmp/BepInEx/config"
ln -s "$vp_config_path" "$vp_install_path.tmp/BepInEx/config"
if [ -d "$vp_install_path" ]; then
mv -f "$vp_install_path" "$vp_install_path.old"
fi
mv "$vp_install_path.tmp" "$vp_install_path"
echo restart > "$valheim_restartfile"
}
download_valheim_plus() {
local download_url="$1"
local updated_at="$2"
local download_path="$vp_download_path/$vp_zipfile"
debug "Downloading $download_url to $download_path"
curl -L -o "$download_path" "$download_url" \
&& echo "$updated_at" > "$download_path.updated_at"
}
extract_valheim_plus() {
cd "$vp_download_path" || fatal "Could not cd $vp_download_path"
debug "Extracting downloaded ValheimPlus ZIP archive"
rm -rf extracted
mkdir -p extracted
unzip -d extracted/ "$vp_zipfile"
}
main