Browse Source

Merge pull request 'updated to include mod support, other fixes' (#3) from valheim/add-mod-support into master

Reviewed-on: #3
pull/4/head
Mar Alegre 3 years ago
parent
commit
687734ed62
  1. 11
      valheim/Containerfile
  2. 113
      valheim/assets/bin/vh-install
  3. 21
      valheim/assets/bin/vh-start
  4. 2
      valheim/assets/systemd/valheim.service
  5. 11
      valheim/assets/systemd/vh-install.service

11
valheim/Containerfile

@ -46,13 +46,16 @@ WORKDIR /home/vhadmin
RUN vh-install RUN vh-install
# replace permissions txt's with links # 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; \ for f in adminlist.txt bannedlist.txt permittedlist.txt; \
do rm $f; ln -s /vol/data/config/$f; \ do rm -f $f; ln -s /vol/data/config/$f; \
done done; \
chown -R vhadmin:vhadmin /home/vhadmin
# copy units to systemd # copy units to systemd
COPY assets/systemd/ /etc/systemd/system/ COPY assets/systemd/ /etc/systemd/system/
# enable systemd units # enable systemd units
RUN systemctl enable valheim.service vh-backup.timer RUN systemctl enable valheim.service vh-backup.timer vh-install.service

113
valheim/assets/bin/vh-install

@ -1,2 +1,113 @@
#!/bin/bash #!/bin/bash
steamcmd +login anonymous +force_install_dir /home/vhadmin/ +app_update 896660 validate +exit
# 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

21
valheim/assets/bin/vh-start

@ -1,15 +1,24 @@
#!/bin/bash #!/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 export SteamAppId=892970
echo "Starting server" echo "Starting server..."
# Load Config # Load Config
. /vol/data/config/server . /vol/data/config/server
# NOTE: Minimum password length is 5 characters & Password cant be in the server name. # 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. # 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:?} exec ./valheim_server.x86_64 -name "${vh_name:?}" -port "${vh_port:?}" -world "${vh_world:?}" -password "${vh_pass:?}" -public "${vh_public:?}"
export LD_LIBRARY_PATH=$templdpath

2
valheim/assets/systemd/valheim.service

@ -14,7 +14,7 @@ StandardOutput=journal
StandardError=journal StandardError=journal
Type=simple Type=simple
# security # security
PrivateUsers=true #PrivateUsers=true
ProtectHome=true ProtectHome=true
ProtectControlGroups=true ProtectControlGroups=true
ProtectKernelModules=true ProtectKernelModules=true

11
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
Loading…
Cancel
Save