From f02e53d3e222514655b2494052e795ce2daecae7 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 22 Oct 2022 22:40:35 +0100 Subject: [PATCH] fix: add docker compatibility fix: allow find to search in symlinks --- lgsm/functions/check.sh | 4 ++-- lgsm/functions/check_deps.sh | 2 +- lgsm/functions/check_permissions.sh | 2 +- lgsm/functions/check_root.sh | 2 +- lgsm/functions/command_install.sh | 2 +- lgsm/functions/core_exit.sh | 2 +- lgsm/functions/core_steamcmd.sh | 6 +++--- linuxgsm.sh | 24 ++++++++++++------------ 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lgsm/functions/check.sh b/lgsm/functions/check.sh index 6f98598228..239a24140a 100755 --- a/lgsm/functions/check.sh +++ b/lgsm/functions/check.sh @@ -21,7 +21,7 @@ fi check_tmuxception.sh -if [ "$(whoami)" != "root" ]; then +if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then if [ "${commandname}" != "MONITOR" ]; then check_permissions.sh fi @@ -38,7 +38,7 @@ for allowed_command in "${allowed_commands_array[@]}"; do fi done -if [ "$(whoami)" != "root" ]; then +if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then allowed_commands_array=(DEBUG START INSTALL) for allowed_command in "${allowed_commands_array[@]}"; do if [ "${allowed_command}" == "${commandname}" ]; then diff --git a/lgsm/functions/check_deps.sh b/lgsm/functions/check_deps.sh index ff4863e2cb..194f5541ef 100755 --- a/lgsm/functions/check_deps.sh +++ b/lgsm/functions/check_deps.sh @@ -301,7 +301,7 @@ fn_deps_detector() { } if [ "${commandname}" == "INSTALL" ]; then - if [ "$(whoami)" == "root" ]; then + if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then echo -e "" echo -e "${lightyellow}Checking Dependencies as root${default}" echo -e "=================================" diff --git a/lgsm/functions/check_permissions.sh b/lgsm/functions/check_permissions.sh index 92a76600bc..46642f7fbe 100755 --- a/lgsm/functions/check_permissions.sh +++ b/lgsm/functions/check_permissions.sh @@ -226,7 +226,7 @@ fn_sys_perm_error_process() { # Run perm error detect & fix/alert functions on /sys directories. ## Run checks. -if [ "$(whoami)" != "root" ]; then +if [ "$(whoami)" != "root" ] || [ -f /.dockerenv ]; then fn_check_ownership fn_check_permissions if [ "${commandname}" == "START" ]; then diff --git a/lgsm/functions/check_root.sh b/lgsm/functions/check_root.sh index 13942cbd4d..dab0331487 100755 --- a/lgsm/functions/check_root.sh +++ b/lgsm/functions/check_root.sh @@ -7,7 +7,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -if [ "$(whoami)" = "root" ]; then +if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then if [ "${commandname}" != "INSTALL" ]; then fn_print_fail_nl "Do NOT run this script as root!" if [ -d "${lgsmlogdir}" ]; then diff --git a/lgsm/functions/command_install.sh b/lgsm/functions/command_install.sh index e56890b4d7..19dc59c7ee 100755 --- a/lgsm/functions/command_install.sh +++ b/lgsm/functions/command_install.sh @@ -11,7 +11,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_firstcommand_set check.sh -if [ "$(whoami)" = "root" ]; then +if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then check_deps.sh else install_header.sh diff --git a/lgsm/functions/core_exit.sh b/lgsm/functions/core_exit.sh index 93c37dfc7a..2d2f5b8fa1 100755 --- a/lgsm/functions/core_exit.sh +++ b/lgsm/functions/core_exit.sh @@ -18,7 +18,7 @@ fn_exit_dev_debug() { } # If running dependency check as root will remove any files that belong to root user. -if [ "$(whoami)" == "root" ]; then +if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then find "${lgsmdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1 find "${logdir}"/ -group root -prune -exec rm -rf {} + > /dev/null 2>&1 fi diff --git a/lgsm/functions/core_steamcmd.sh b/lgsm/functions/core_steamcmd.sh index 92c14136a2..453a8b77e6 100755 --- a/lgsm/functions/core_steamcmd.sh +++ b/lgsm/functions/core_steamcmd.sh @@ -174,7 +174,7 @@ fn_update_steamcmd_remotebuild() { fi # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD. - if [ "$(find "${HOME}" -type f -name "appinfo.vdf" | wc -l)" -ne "0" ]; then + if [ "$(find -L "${HOME}" -type f -name "appinfo.vdf" | wc -l)" -ne "0" ]; then find "${HOME}" -type f -name "appinfo.vdf" -exec rm -f {} \; fi @@ -281,8 +281,8 @@ fn_update_steamcmd_compare() { } fn_appmanifest_info() { - appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf") - appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l) + appmanifestfile=$(find -L "${serverfiles}" -type f -name "appmanifest_${appid}.acf") + appmanifestfilewc=$(find -L "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l) } fn_appmanifest_check() { diff --git a/linuxgsm.sh b/linuxgsm.sh index 01c71d68c6..0748b2d86e 100755 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -15,7 +15,7 @@ # Debugging if [ -f ".dev-debug" ]; then - exec 5> dev-debug.log + exec 5>dev-debug.log BASH_XTRACEFD="5" set -x fi @@ -52,7 +52,7 @@ userinput2="${2}" [ -n "${LGSM_GITHUBBRANCH}" ] && githubbranch="${LGSM_GITHUBBRANCH}" || githubbranch="master" # Check that curl is installed before doing anything -if [ ! "$(command -v curl 2> /dev/null)" ]; then +if [ ! "$(command -v curl 2>/dev/null)" ]; then echo -e "[ FAIL ] Curl is not installed" exit 1 fi @@ -213,7 +213,7 @@ fn_install_menu_bash() { while read -r line || [[ -n "${line}" ]]; do var=$(echo -e "${line}" | awk -F "," '{print $2 " - " $3}') menu_options+=("${var}") - done < "${options}" + done <"${options}" menu_options+=("Cancel") select option in "${menu_options[@]}"; do if [ "${option}" ] && [ "${option}" != "Cancel" ]; then @@ -239,7 +239,7 @@ fn_install_menu_whiptail() { key=$(echo -e "${line}" | awk -F "," '{print $3}') val=$(echo -e "${line}" | awk -F "," '{print $2}') menu_options+=("${val//\"/}" "${key//\"/}") - done < "${options}" + done <"${options}" OPTION=$(${menucmd} --title "${title}" --menu "${caption}" "${height}" "${width}" "${menuheight}" "${menu_options[@]}" 3>&1 1>&2 2>&3) if [ $? == 0 ]; then eval "$resultvar=\"${OPTION}\"" @@ -263,12 +263,12 @@ fn_install_menu() { fi done case "$(basename "${menucmd}")" in - whiptail | dialog) - fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30 - ;; - *) - fn_install_menu_bash selection "${title}" "${caption}" "${options}" - ;; + whiptail | dialog) + fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30 + ;; + *) + fn_install_menu_bash selection "${title}" "${caption}" "${options}" + ;; esac eval "$resultvar=\"${selection}\"" } @@ -321,7 +321,7 @@ fn_install_file() { } # Prevent LinuxGSM from running as root. Except if doing a dependency install. -if [ "$(whoami)" == "root" ]; then +if [ "$(whoami)" == "root" ] && [ ! -f /.dockerenv ]; then if [ "${userinput}" == "install" ] || [ "${userinput}" == "auto-install" ] || [ "${userinput}" == "i" ] || [ "${userinput}" == "ai" ]; then if [ "${shortname}" == "core" ]; then echo -e "[ FAIL ] Do NOT run this script as root!" @@ -351,7 +351,7 @@ if [ "${shortname}" == "core" ]; then } | column -s $'\t' -t | more exit elif [ "${userinput}" == "install" ] || [ "${userinput}" == "i" ]; then - tail -n +1 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}" + tail -n +1 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' >"${serverlistmenu}" fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}" userinput="${result}" fn_server_info