diff --git a/valheim/Containerfile b/valheim/Containerfile index 5f0e2b2..20218e2 100644 --- a/valheim/Containerfile +++ b/valheim/Containerfile @@ -46,13 +46,16 @@ WORKDIR /home/vhadmin RUN vh-install # replace permissions txt's with links -RUN cd .config/unity3d/IronGate/Valheim/; \ +RUN mkdir -p .config/unity3d/IronGate/Valheim/worlds_local; \ + ln -s .config/unity3d/IronGate/Valheim/worlds_local worlds; \ + cd .config/unity3d/IronGate/Valheim/; \ for f in adminlist.txt bannedlist.txt permittedlist.txt; \ - do rm $f; ln -s /vol/data/config/$f; \ - done + do rm -f $f; ln -s /vol/data/config/$f; \ + done; \ + chown -R vhadmin:vhadmin /home/vhadmin # copy units to systemd COPY assets/systemd/ /etc/systemd/system/ # enable systemd units -RUN systemctl enable valheim.service vh-backup.timer +RUN systemctl enable valheim.service vh-backup.timer vh-install.service diff --git a/valheim/assets/bin/vh-install b/valheim/assets/bin/vh-install index 1ce8ef3..35e5152 100755 --- a/valheim/assets/bin/vh-install +++ b/valheim/assets/bin/vh-install @@ -1,2 +1,113 @@ #!/bin/bash -steamcmd +login anonymous +force_install_dir /home/vhadmin/ +app_update 896660 validate +exit \ No newline at end of file + +# Check if server is active +status=$(systemctl show valheim -p ActiveState --value) +# shutdown server if it is active +if [[ $status == active ]]; then + echo "Server is active: executing shutdown..." + systemctl stop valheim + sleep 1 +fi + +# Install Valheim +installdir="/home/vhadmin" +steamcmd +login anonymous +force_install_dir "$installdir" +app_update 896660 validate +exit + +# Install Mods +modsite="https://valheim.thunderstore.io" +moddir="$installdir/BepInEx/plugins" + +rm_ife() { + if [[ -e "$1" ]]; then + rm -r "$1" + fi +} + +get_modver() { + mod="$1" + modauthor=$(echo "$mod" | cut -d '-' -f 1) + modname=$(echo "$mod" | cut -d '-' -f 2) + modpath="$modauthor/$modname" + + web_version=$(wget -qO - "$modsite/package/$modpath/" | grep -oP "/package/download/$modpath/\K([\d.]+)" | head -1) + loc_version=$(grep -osP '"version_number": "\K([\d.]+)' "$moddir/$mod/manifest.json") + + if [[ $web_version != $loc_version ]]; then + echo $web_version + fi +} + +dl_mod() { + modauthor=$(echo "$1" | cut -d '-' -f 1) + modname=$(echo "$1" | cut -d '-' -f 2) + modpath="$modauthor/$modname" + + wget -qO "$mod.zip" "$modsite/package/download/$modpath/$2" +} + +tmpdir=$(mktemp -d) +cd "$tmpdir" + +# Install BepinEx +mod='denikson-BepInExPack_Valheim' +modver=$(get_modver "$mod") +if [[ -n $modver ]]; then + echo "Installing mod: $mod" + dl_mod "$mod" "$modver" + unzip -q "$mod.zip" + mkdir "BepInExPack_Valheim/BepInEx/plugins/$mod" + mv BepInExPack_Valheim/BepInEx/plugins/*.dll "BepInExPack_Valheim/BepInEx/plugins/$mod/" + mv manifest.json README.md "BepInExPack_Valheim/BepInEx/plugins/$mod/" + rm -r BepInExPack_Valheim/BepInEx/config + ln -s /vol/data/config/BepInEx BepInExPack_Valheim/BepInEx/config + mv BepInExPack_Valheim/* "$installdir/" + rm -r * +else + echo "Mod already latest: $mod" +fi + +# Install Additional Mods +if [[ -e /vol/data/config/server ]]; then + . /vol/data/config/server +else + vh_mods=() +fi + +for mod in "${vh_mods[@]}"; do + modver=$(get_modver "$mod") + if [[ -n $modver ]]; then + echo "Installing mod: $mod" + dl_mod "$mod" "$modver" + unzip -q "$mod.zip" + # annoyingly, mod zips don't all have the same structure + # find all .dll files, and put them in the plugin dir + mkdir -p "$moddir/$mod/" + for dll in $(find -name '*.dll'); do + mv "$dll" "$moddir/$mod/" + done + mv manifest.json README.md "$moddir/$mod/" + rm -r * + else + echo "Mod already latest: $mod" + fi +done + +vh_mods+=('denikson-BepInExPack_Valheim') +cd "$moddir" + +for mod in *; do + if $(echo "${vh_mods[@]}" | grep -qv "\b$mod\b"); then + echo "Removing mod: $mod" + rm -r "$mod" + fi +done + +# Clean Up +rm -r "$tmpdir" +chown -R vhadmin:vhadmin $installdir +# start server back up if it was active +if [[ $status == active ]]; then + echo "Server was active: starting server again..." + systemctl start valheim + sleep 5 +fi diff --git a/valheim/assets/bin/vh-start b/valheim/assets/bin/vh-start index 96b9e11..5bce347 100755 --- a/valheim/assets/bin/vh-start +++ b/valheim/assets/bin/vh-start @@ -1,15 +1,24 @@ #!/bin/bash -export templdpath=$LD_LIBRARY_PATH -export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH + +# BepInEx-specific settings +# NOTE: Do not edit unless you know what you are doing! +#### +export DOORSTOP_ENABLE=TRUE +export DOORSTOP_INVOKE_DLL_PATH=./BepInEx/core/BepInEx.Preloader.dll +export DOORSTOP_CORLIB_OVERRIDE_PATH=./unstripped_corlib + +export LD_LIBRARY_PATH="./doorstop_libs:$LD_LIBRARY_PATH" +export LD_PRELOAD="libdoorstop_x64.so:$LD_PRELOAD" +#### + +export LD_LIBRARY_PATH="./linux64:$LD_LIBRARY_PATH" export SteamAppId=892970 -echo "Starting server" +echo "Starting server..." # Load Config . /vol/data/config/server # NOTE: Minimum password length is 5 characters & Password cant be in the server name. # NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall. -./valheim_server.x86_64 -name "${vh_name:?}" -port 2456 -world "${vh_world:?}" -password "${vh_pass:?}" -public ${vh_public:?} - -export LD_LIBRARY_PATH=$templdpath +exec ./valheim_server.x86_64 -name "${vh_name:?}" -port "${vh_port:?}" -world "${vh_world:?}" -password "${vh_pass:?}" -public "${vh_public:?}" diff --git a/valheim/assets/systemd/valheim.service b/valheim/assets/systemd/valheim.service index 210e410..25ae623 100644 --- a/valheim/assets/systemd/valheim.service +++ b/valheim/assets/systemd/valheim.service @@ -14,7 +14,7 @@ StandardOutput=journal StandardError=journal Type=simple # security -PrivateUsers=true +#PrivateUsers=true ProtectHome=true ProtectControlGroups=true ProtectKernelModules=true diff --git a/valheim/assets/systemd/vh-install.service b/valheim/assets/systemd/vh-install.service new file mode 100644 index 0000000..6b65a21 --- /dev/null +++ b/valheim/assets/systemd/vh-install.service @@ -0,0 +1,11 @@ +[Unit] +After=network-online.target local-fs.target +Before=valheim.service +Description=Valheim install/update service + +[Service] +ExecStart=/usr/local/bin/vh-install +Type=oneshot + +[Install] +WantedBy=multi-user.target