@@ -8,7 +8,9 @@ setup_nss_wrapper(){
88 # Setup NSS Wrapper for use ($NSS_WRAPPER_PASSWD and $NSS_WRAPPER_GROUP have been set by the Dockerfile)
99 export USER_ID=$( id -u)
1010 export GROUP_ID=$( id -g)
11+ export USER_NAME=" ${USER_NAME:- ${USER:- container} } "
1112 envsubst < /passwd.template > ${NSS_WRAPPER_PASSWD}
13+ printf ' %s:x:%s:\n' " ${USER_NAME} " " ${GROUP_ID} " > ${NSS_WRAPPER_GROUP}
1214 export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libnss_wrapper.so
1315}
1416
@@ -50,6 +52,11 @@ install_bepinex() {
5052 local version_file=" .apollo/bepinex_version"
5153 local api_response download_url version_number installed_version
5254
55+ if [[ " ${SRCDS_APPID} " == " 896660" && " ${INSTALL_VALHEIM_PLUS:- 0} " == " 1" ]]; then
56+ echo " Skipping BepInEx installation; ValheimPlus provides its compatible BepInEx version."
57+ return 0
58+ fi
59+
5360 case " ${SRCDS_APPID} " in
5461 896660)
5562 # Valheim
@@ -90,8 +97,13 @@ install_bepinex() {
9097 return 0
9198 fi
9299
93- wget -O " ${zip_name} " " $download_url "
94- unzip -o " ${zip_name} "
100+ if ! curl -fL --retry 3 --retry-delay 2 -o " ${zip_name} " " ${download_url} " \
101+ || ! unzip -o " ${zip_name} " \
102+ || [[ ! -f " /home/container/${extracted_dir} /BepInEx/core/BepInEx.Preloader.dll" ]]; then
103+ echo " Error: could not install BepInEx"
104+ rm -f " ${zip_name} "
105+ return 1
106+ fi
95107 cp -al " /home/container/${extracted_dir} /" * /home/container
96108
97109
@@ -117,6 +129,54 @@ install_bepinex() {
117129 echo " -------------------------------------------------------"
118130}
119131
132+ install_valheim_plus () {
133+ local release_url api_response download_url version_number installed_version archive_file extract_dir
134+ local version_file=" .apollo/valheim_plus_version"
135+
136+ if [[ " ${VALHEIM_PLUS_VERSION:- latest} " == " latest" ]]; then
137+ release_url=" https://api.github.com/repos/Grantapher/ValheimPlus/releases/latest"
138+ else
139+ release_url=" https://api.github.com/repos/Grantapher/ValheimPlus/releases/tags/${VALHEIM_PLUS_VERSION} "
140+ fi
141+
142+ if ! api_response=$( curl -fsSL -H " Accept: application/vnd.github+json" -H " User-Agent: Sparked-Valheim" " ${release_url} " ) ; then
143+ echo " Error: could not retrieve ValheimPlus release information from GitHub"
144+ return 1
145+ fi
146+
147+ version_number=$( jq -r ' .tag_name // empty' <<< " ${api_response}" )
148+ download_url=$( jq -r ' .assets[] | select(.name == "UnixServer.zip") | .browser_download_url' <<< " ${api_response}" | head -n 1)
149+ installed_version=$( cat " ${version_file} " 2> /dev/null || true)
150+
151+ if [[ -z " ${version_number} " || -z " ${download_url} " ]]; then
152+ echo " Error: the selected ValheimPlus release has no UnixServer.zip asset"
153+ return 1
154+ fi
155+
156+ if [[ -f " BepInEx/plugins/ValheimPlus.dll" && " ${installed_version} " == " ${version_number} " ]]; then
157+ echo " ValheimPlus is up to date (${version_number} )"
158+ return 0
159+ fi
160+
161+ echo " Installing ValheimPlus (${version_number} )..."
162+ archive_file=$( mktemp /tmp/valheim-plus.XXXXXX.zip)
163+ extract_dir=$( mktemp -d /tmp/valheim-plus.XXXXXX)
164+
165+ if ! curl -fL --retry 3 --retry-delay 2 -o " ${archive_file} " " ${download_url} " \
166+ || ! unzip -q -o " ${archive_file} " -d " ${extract_dir} " \
167+ || [[ ! -f " ${extract_dir} /BepInEx/plugins/ValheimPlus.dll" ]]; then
168+ echo " Error: could not install ValheimPlus"
169+ rm -rf -- " ${extract_dir} " " ${archive_file} "
170+ return 1
171+ fi
172+
173+ cp -a " ${extract_dir} /." /home/container/
174+ rm -rf -- " ${extract_dir} " " ${archive_file} "
175+ mkdir -p .apollo
176+ printf ' %s\n' " ${version_number} " > " ${version_file} "
177+ echo " ValheimPlus installation completed (${version_number} )"
178+ }
179+
120180enable_ue4ss () {
121181 local api_response download_url archive_name installed_version
122182 local api_url=" https://api.github.com/repos/NullPrism/RE-UE4SS-Linux/releases?per_page=1"
@@ -878,12 +938,33 @@ startup_with_signal_forwarding(){
878938
879939regular_startup (){
880940 MODIFIED_STARTUP=$( echo ${STARTUP} | sed -e ' s/{{/${/g' -e ' s/}}/}/g' )
941+ MODIFIED_STARTUP=" ${STARTUP_ENVIRONMENT_PREFIX:- }${MODIFIED_STARTUP} "
881942
882943 echo -e " \033[1;33mcustomer@apollopanel:~\$ \033[0m :/home/container$ ${MODIFIED_STARTUP} "
883944
884945 exec /bin/bash -c " ${MODIFIED_STARTUP} "
885946}
886947
948+ configure_valheim_bepinex (){
949+ [[ -f " BepInEx/core/BepInEx.Preloader.dll" ]] || return 0
950+
951+ STARTUP_ENVIRONMENT_PREFIX=' DOORSTOP_ENABLED=1 DOORSTOP_TARGET_ASSEMBLY="./BepInEx/core/BepInEx.Preloader.dll" LD_LIBRARY_PATH="./doorstop_libs:${LD_LIBRARY_PATH}" LD_PRELOAD="libdoorstop_x64.so:${LD_PRELOAD}" SteamAppId=892970 '
952+ }
953+
954+ startup_valheim (){
955+ if [[ " ${INSTALL_BEPINEX:- 0} " == " 1" ]]; then
956+ install_bepinex || return 1
957+ fi
958+
959+ if [[ " ${INSTALL_VALHEIM_PLUS:- 0} " == " 1" ]]; then
960+ install_valheim_plus || return 1
961+ fi
962+
963+ setup_nss_wrapper
964+ configure_valheim_bepinex
965+ regular_startup
966+ }
967+
887968startup_ue4ss (){
888969 local output_directory
889970 local output_pipe
@@ -943,6 +1024,9 @@ startup_ue4ss(){
9431024
9441025startup_game (){
9451026 case $SRCDS_APPID in
1027+ 896660)
1028+ startup_valheim
1029+ ;;
9461030 376030)
9471031 startup_ark
9481032 ;;
0 commit comments