فهرست منبع

fix(core): follow-up failure handling for extraction, updates and logs (#5113)

* fix(update): force download of update archives

Ten update modules passed "force" to fn_fetch_file, which only
recognises "forcedl", so an archive already in tmpdir was reused. A
failed extraction leaves the archive in tmpdir, and for fixed file
names such as multitheftauto_linux_x64.tar.gz the next update would
extract the stale file again.

* fix(install): exit non-zero when log directories cannot be created

install_logs.sh called core_exit.sh without setting exitcode, so a
failure to create a log directory, log file or symlink printed FAIL
but exited with code 0. Log each failure with fn_script_log_fail,
which sets exitcode to 1.

* fix(mta): exit cleanly after install-default-resources

The module never called core_exit.sh, so running
./mtaserver install-default-resources always ended with "Command did
not exit correctly" and exit code 2, even on success. Exit only when it
is the first command, so the install flow that calls it carries on.

* fix(core): stop SteamCMD install when extraction fails under exitbypass

When exitbypass is set, core_exit.sh returns instead of exiting, so a
failed extraction fell through to the caller. fn_install_steamcmd then
ran chmod on a steamcmd.sh that was never extracted. This is reachable
when an update restarts the server and check_steamcmd.sh installs
SteamCMD.

fn_dl_extract now returns 1 after a bypassed failure, and
fn_install_steamcmd stops on it.
Daniel Gibbs 1 روز پیش
والد
کامیت
ff15be6235

+ 5 - 0
lgsm/modules/command_install_resources_mta.sh

@@ -30,3 +30,8 @@ else
 	fn_print_warning_nl "Default resources are not installed when using ./${selfname} auto-install."
 	fn_print_warning_nl "Default resources are not installed when using ./${selfname} auto-install."
 	fn_print_information_nl "To install default resources use ./${selfname} install"
 	fn_print_information_nl "To install default resources use ./${selfname} install"
 fi
 fi
+
+if [ "${firstcommandname}" == "DEFAULT-RESOURCES" ]; then
+	exitcode=0
+	core_exit.sh
+fi

+ 2 - 0
lgsm/modules/core_dl.sh

@@ -314,6 +314,7 @@ fn_dl_extract() {
 		fn_script_log_fail "Extracting ${local_filename}"
 		fn_script_log_fail "Extracting ${local_filename}"
 		fn_script_log_fail "File ${local_filedir}/${local_filename} not found"
 		fn_script_log_fail "File ${local_filedir}/${local_filename} not found"
 		core_exit.sh
 		core_exit.sh
+		return 1
 	fi
 	fi
 	mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
 	mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
 	if [ "${mime}" == "application/gzip" ] || [ "${mime}" == "application/x-gzip" ]; then
 	if [ "${mime}" == "application/gzip" ] || [ "${mime}" == "application/x-gzip" ]; then
@@ -359,6 +360,7 @@ fn_dl_extract() {
 		fi
 		fi
 		echo -e "${extractcmd}"
 		echo -e "${extractcmd}"
 		core_exit.sh
 		core_exit.sh
+		return 1
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
 		fn_script_log_pass "Extracting ${local_filename}"
 		fn_script_log_pass "Extracting ${local_filename}"

+ 1 - 1
lgsm/modules/core_steamcmd.sh

@@ -15,7 +15,7 @@ fn_install_steamcmd() {
 		mkdir -p "${steamcmddir}"
 		mkdir -p "${steamcmddir}"
 	fi
 	fi
 	fn_fetch_file "https://media.steampowered.com/client/steamcmd_linux.tar.gz" "" "" "" "${tmpdir}" "steamcmd_linux.tar.gz" "nochmodx" "norun" "noforce" "nohash"
 	fn_fetch_file "https://media.steampowered.com/client/steamcmd_linux.tar.gz" "" "" "" "${tmpdir}" "steamcmd_linux.tar.gz" "nochmodx" "norun" "noforce" "nohash"
-	fn_dl_extract "${tmpdir}" "steamcmd_linux.tar.gz" "${steamcmddir}"
+	fn_dl_extract "${tmpdir}" "steamcmd_linux.tar.gz" "${steamcmddir}" || return 1
 	chmod +x "${steamcmddir}/steamcmd.sh"
 	chmod +x "${steamcmddir}/steamcmd.sh"
 }
 }
 
 

+ 8 - 0
lgsm/modules/install_logs.sh

@@ -17,6 +17,7 @@ echo -en "creating log directory [ ${italic}${logdir}${default} ]"
 if [ ! -d "${logdir}" ]; then
 if [ ! -d "${logdir}" ]; then
 	if ! mkdir -p "${logdir}"; then
 	if ! mkdir -p "${logdir}"; then
 		fn_print_fail_eol_nl
 		fn_print_fail_eol_nl
+		fn_script_log_fail "Creating log directory ${logdir}"
 		core_exit.sh
 		core_exit.sh
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
@@ -29,6 +30,7 @@ echo -en "creating script log directory [ ${italic}${lgsmlogdir}${default} ]"
 if [ ! -d "${lgsmlogdir}" ]; then
 if [ ! -d "${lgsmlogdir}" ]; then
 	if ! mkdir -p "${lgsmlogdir}"; then
 	if ! mkdir -p "${lgsmlogdir}"; then
 		fn_print_fail_eol_nl
 		fn_print_fail_eol_nl
+		fn_script_log_fail "Creating script log directory ${lgsmlogdir}"
 		core_exit.sh
 		core_exit.sh
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
@@ -41,6 +43,7 @@ echo -en "creating script log [ ${italic}${lgsmlog}${default} ]"
 if [ ! -f "${lgsmlog}" ]; then
 if [ ! -f "${lgsmlog}" ]; then
 	if ! touch "${lgsmlog}"; then
 	if ! touch "${lgsmlog}"; then
 		fn_print_fail_eol_nl
 		fn_print_fail_eol_nl
+		fn_script_log_fail "Creating script log ${lgsmlog}"
 		core_exit.sh
 		core_exit.sh
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
@@ -53,6 +56,7 @@ echo -en "creating console log directory [ ${italic}${consolelogdir}${default} ]
 if [ ! -d "${consolelogdir}" ]; then
 if [ ! -d "${consolelogdir}" ]; then
 	if ! mkdir -p "${consolelogdir}"; then
 	if ! mkdir -p "${consolelogdir}"; then
 		fn_print_fail_eol_nl
 		fn_print_fail_eol_nl
+		fn_script_log_fail "Creating console log directory ${consolelogdir}"
 		core_exit.sh
 		core_exit.sh
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
@@ -65,6 +69,7 @@ echo -en "creating console log [ ${italic}${consolelog}${default} ]"
 if [ ! -f "${consolelog}" ]; then
 if [ ! -f "${consolelog}" ]; then
 	if ! touch "${consolelog}"; then
 	if ! touch "${consolelog}"; then
 		fn_print_fail_eol_nl
 		fn_print_fail_eol_nl
+		fn_script_log_fail "Creating console log ${consolelog}"
 		core_exit.sh
 		core_exit.sh
 	else
 	else
 		fn_print_ok_eol_nl
 		fn_print_ok_eol_nl
@@ -78,6 +83,7 @@ if [ -n "${gamelogdir}" ]; then
 	if [ ! -d "${gamelogdir}" ]; then
 	if [ ! -d "${gamelogdir}" ]; then
 		if ! mkdir -p "${gamelogdir}"; then
 		if ! mkdir -p "${gamelogdir}"; then
 			fn_print_fail_eol_nl
 			fn_print_fail_eol_nl
+			fn_script_log_fail "Creating game log directory ${gamelogdir}"
 			core_exit.sh
 			core_exit.sh
 		else
 		else
 			fn_print_ok_eol_nl
 			fn_print_ok_eol_nl
@@ -97,6 +103,7 @@ if [ -n "${gamelogdir}" ] && [ "${gamelogdir:0:${#logdir}}" != "${logdir}" ]; th
 	if [ ! -h "${logdir}/server" ] || [ "$(readlink -f "${logdir}/server")" != "${gamelogdir}" ]; then
 	if [ ! -h "${logdir}/server" ] || [ "$(readlink -f "${logdir}/server")" != "${gamelogdir}" ]; then
 		if ! ln -nfs "${gamelogdir}" "${logdir}/server"; then
 		if ! ln -nfs "${gamelogdir}" "${logdir}/server"; then
 			fn_print_fail_eol_nl
 			fn_print_fail_eol_nl
+			fn_script_log_fail "Creating symlink to game log directory ${logdir}/server"
 			core_exit.sh
 			core_exit.sh
 		else
 		else
 			fn_print_ok_eol_nl
 			fn_print_ok_eol_nl
@@ -112,6 +119,7 @@ if [ -d "${HOME}/.steam/steam/logs" ]; then
 	if [ ! -L "${logdir}/steam" ]; then
 	if [ ! -L "${logdir}/steam" ]; then
 		if ! ln -nfs "${HOME}/.steam/steam/logs" "${logdir}/steam"; then
 		if ! ln -nfs "${HOME}/.steam/steam/logs" "${logdir}/steam"; then
 			fn_print_fail_eol_nl
 			fn_print_fail_eol_nl
+			fn_script_log_fail "Creating symlink to steam log directory ${logdir}/steam"
 			core_exit.sh
 			core_exit.sh
 		else
 		else
 			fn_print_ok_eol_nl
 			fn_print_ok_eol_nl

+ 1 - 1
lgsm/modules/update_bb.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "${remotebuildhash}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	fn_clear_tmp
 	fn_clear_tmp

+ 1 - 1
lgsm/modules/update_etl.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "${remotebuildhash}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	fn_clear_tmp
 	fn_clear_tmp

+ 1 - 1
lgsm/modules/update_fctr.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "nohash"
 	fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuild}.tar.xz" "${serverfiles}" "factorio"
 	fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuild}.tar.xz" "${serverfiles}" "factorio"
 	fn_clear_tmp
 	fn_clear_tmp
 }
 }

+ 1 - 1
lgsm/modules/update_jk2.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "nohash"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}/GameData" "linux-amd64"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}/GameData" "linux-amd64"
 	fn_clear_tmp
 	fn_clear_tmp
 }
 }

+ 1 - 1
lgsm/modules/update_mta.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to tmpdir.
 	# Download and extract files to tmpdir.
-	fn_fetch_file "https://linux.multitheftauto.com/dl/multitheftauto_linux_x64.tar.gz" "" "" "" "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "nochmodx" "norun" "force" "nohash"
+	fn_fetch_file "https://linux.multitheftauto.com/dl/multitheftauto_linux_x64.tar.gz" "" "" "" "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "nochmodx" "norun" "forcedl" "nohash"
 	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "${serverfiles}" "multitheftauto_linux_x64"
 	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "${serverfiles}" "multitheftauto_linux_x64"
 	fn_clear_tmp
 	fn_clear_tmp
 }
 }

+ 1 - 1
lgsm/modules/update_pmc.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "chmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "chmodx" "norun" "forcedl" "${remotebuildhash}"
 	cp -f "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${executable#./}"
 	cp -f "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${executable#./}"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	fn_clear_tmp
 	fn_clear_tmp

+ 1 - 1
lgsm/modules/update_ts3.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "${remotebuildhash}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" "teamspeak3-server_linux_${ts3arch}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" "teamspeak3-server_linux_${ts3arch}"
 	fn_clear_tmp
 	fn_clear_tmp
 }
 }

+ 1 - 1
lgsm/modules/update_ut99.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "nohash"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	echo "${remotebuild}" > "${serverfiles}/build.txt"
 	fn_clear_tmp
 	fn_clear_tmp

+ 1 - 1
lgsm/modules/update_vints.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "${remotebuildhash}"
 	rm -rf "${serverfiles:?}/assets"
 	rm -rf "${serverfiles:?}/assets"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_clear_tmp
 	fn_clear_tmp

+ 1 - 1
lgsm/modules/update_xnt.sh

@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_dl() {
 fn_update_dl() {
 	# Download and extract files to serverfiles.
 	# Download and extract files to serverfiles.
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "forcedl" "${remotebuildhash}"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" "Xonotic"
 	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" "Xonotic"
 	fn_clear_tmp
 	fn_clear_tmp
 }
 }