From 09d0a881a3204f82697be040cd07954dec3be19a Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 22 Oct 2022 00:32:13 +0100 Subject: [PATCH] feat: allow running as root when in docker --- lgsm/functions/check_root.sh | 2 +- lgsm/functions/command_install.sh | 2 +- linuxgsm.sh | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) 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/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