Pārlūkot izejas kodu

fix: add docker compatibility

fix: allow find to search in symlinks
Daniel Gibbs 3 gadi atpakaļ
vecāks
revīzija
2257be4a8e

+ 2 - 2
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

+ 1 - 1
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 "================================="

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 3 - 3
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() {

+ 12 - 12
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