Prechádzať zdrojové kódy

code de-lint and bringing up to shellcheck standards (#2613)

Daniel Gibbs 6 rokov pred
rodič
commit
06554cb314

+ 1 - 1
lgsm/functions/alert_telegram.sh

@@ -18,7 +18,7 @@ EOF
 )
 
 fn_print_dots "Sending Telegram alert"
-telegramsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.telegram.org/bot${telegramtoken}/sendMessage" ${curlcustomstring} | grep "error_code")
+telegramsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.telegram.org/bot${telegramtoken}/sendMessage" "${curlcustomstring}" | grep "error_code")
 
 if [ -n "${telegramsend}" ]; then
 	fn_print_fail_nl "Sending Telegram alert: ${telegramsend}"

+ 10 - 10
lgsm/functions/check_deps.sh

@@ -27,13 +27,13 @@ fn_install_mono_repo(){
 			if [ "${distroid}" == "ubuntu" ]; then
 				if [ "${distroversion}" == "18.04" ]; then
 					cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/ubuntu stable-bionic main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "16.04" ]; then
 					cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt install apt-transport-https;echo 'deb https://download.mono-project.com/repo/ubuntu stable-xenial main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "14.04" ]; then
 					cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt install apt-transport-https;echo 'deb https://download.mono-project.com/repo/ubuntu stable-trusty main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				else
 					fn_print_warn_nl "Installing Mono repository"
 					echo -e "Mono auto install not available for ${distroname}"
@@ -44,13 +44,13 @@ fn_install_mono_repo(){
 			elif [ "${distroid}" == "debian" ]; then
 				if [ "${distroversion}" == "10" ]; then
 					cmd="sudo apt install apt-transport-https dirmngr;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-buster main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "9" ]; then
 					cmd="sudo apt install apt-transport-https dirmngr;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-stretch main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "8" ]; then
 					cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt install apt-transport-https;echo 'deb https://download.mono-project.com/repo/debian stable-jessie main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
-					eval ${cmd}
+					eval "${cmd}"
 				else
 					echo -e "Mono auto install not available for ${distroname}"
 					echo -e "	Follow instructions on mono site to install the latest version of Mono."
@@ -60,13 +60,13 @@ fn_install_mono_repo(){
 			elif [ "${distroid}" == "centos" ]; then
 				if [ "${distroversion}" == "8" ]; then
 					cmd="rpm --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF';su -c 'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo'"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "7" ]; then
 					cmd="rpm --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF';su -c 'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo'"
-					eval ${cmd}
+					eval "${cmd}"
 				elif [ "${distroversion}" == "6" ]; then
 					cmd="rpm --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF';su -c 'curl https://download.mono-project.com/repo/centos6-stable.repo | tee /etc/yum.repos.d/mono-centos6-stable.repo'"
-					eval ${cmd}
+					eval "${cmd}"
 				else
 					echo -e "Mono auto install not available for ${distroname}"
 					echo -e "	Follow instructions on mono site to install the latest version of Mono."
@@ -75,7 +75,7 @@ fn_install_mono_repo(){
 				fi
 			elif [ "${distroid}" == "fedora" ]; then
 				cmd="rpm --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF'; su -c 'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo'; dnf update"
-				eval ${cmd}
+				eval "${cmd}"
 			else
 				echo -e "Mono auto install not available for ${distroname}"
 				echo -e "	Follow instructions on mono site to install the latest version of Mono."

+ 1 - 0
lgsm/functions/core_dl.sh

@@ -168,6 +168,7 @@ fn_fetch_file(){
 		fn_dl_md5
 		# Execute file if run is set.
 		if [ "${run}" == "run" ]; then
+      # shellcheck source=/dev/null
 			source "${local_filedir}/${local_filename}"
 		fi
 	fi

+ 34 - 34
lgsm/functions/core_messages.sh

@@ -119,18 +119,18 @@ fn_script_log_info(){
 # [ .... ]
 fn_print_dots(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[ .... ] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[ .... ] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[ .... ] $@"
+		echo -en "${creeol}[ .... ] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_dots_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -e "${creeol}[ .... ] ${commandaction} ${selfname}: $@"
+		echo -e "${creeol}[ .... ] ${commandaction} ${servicename}: $*"
 	else
-		echo -e "${creeol}[ .... ] $@"
+		echo -e "${creeol}[ .... ] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -139,18 +139,18 @@ fn_print_dots_nl(){
 # [  OK  ]
 fn_print_ok(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${green}  OK  ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${green}  OK  ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${green}  OK  ${default}] $@"
+		echo -en "${creeol}[${green}  OK  ${default}] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_ok_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${green}  OK  ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${green}  OK  ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${green}  OK  ${default}] $@"
+		echo -en "${creeol}[${green}  OK  ${default}] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -159,18 +159,18 @@ fn_print_ok_nl(){
 # [ FAIL ]
 fn_print_fail(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${red} FAIL ${default}] $@"
+		echo -en "${creeol}[${red} FAIL ${default}] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_fail_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${red} FAIL ${default}] $@"
+		echo -en "${creeol}[${red} FAIL ${default}] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -179,18 +179,18 @@ fn_print_fail_nl(){
 # [ ERROR ]
 fn_print_error(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${red}ERROR ${default}] $@"
+		echo -en "${creeol}[${red}ERROR ${default}] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_error_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${red}ERROR ${default}] $@"
+		echo -en "${creeol}[${red}ERROR ${default}] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -199,18 +199,18 @@ fn_print_error_nl(){
 # [ WARN ]
 fn_print_warn(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${lightyellow} WARN ${default}] $@"
+		echo -en "${creeol}[${lightyellow} WARN ${default}] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_warn_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${lightyellow} WARN ${default}] $@"
+		echo -en "${creeol}[${lightyellow} WARN ${default}] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -219,18 +219,18 @@ fn_print_warn_nl(){
 # [ INFO ]
 fn_print_info(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${cyan} INFO ${default}] $@"
+		echo -en "${creeol}[${cyan} INFO ${default}] $*"
 	fi
 	fn_sleep_time
 }
 
 fn_print_info_nl(){
 	if [ -n "${commandaction}" ]; then
-		echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${selfname}: $@"
+		echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $*"
 	else
-		echo -en "${creeol}[${cyan} INFO ${default}] $@"
+		echo -en "${creeol}[${cyan} INFO ${default}] $*"
 	fi
 	fn_sleep_time
 	echo -en "\n"
@@ -249,56 +249,56 @@ fn_print_header(){
 
 # Complete!
 fn_print_complete(){
-	echo -en "${green}Complete!${default} $@"
+	echo -en "${green}Complete!${default} $*"
 	fn_sleep_time
 }
 
 fn_print_complete_nl(){
-	echo -e "${green}Complete!${default} $@"
+	echo -e "${green}Complete!${default} $*"
 	fn_sleep_time
 }
 
 # Failure!
 fn_print_failure(){
-	echo -en "${red}Failure!${default} $@"
+	echo -en "${red}Failure!${default} $*"
 	fn_sleep_time
 }
 
 fn_print_failure_nl(){
-	echo -e "${red}Failure!${default} $@"
+	echo -e "${red}Failure!${default} $*"
 	fn_sleep_time
 }
 
 # Error!
 fn_print_error2(){
-	echo -en "${red}Error!${default} $@"
+	echo -en "${red}Error!${default} $*"
 	fn_sleep_time
 }
 
 fn_print_error2_nl(){
-	echo -e "${red}Error!${default} $@"
+	echo -e "${red}Error!${default} $*"
 	fn_sleep_time
 }
 
 # Warning!
 fn_print_warning(){
-	echo -en "${lightyellow}Warning!${default} $@"
+	echo -en "${lightyellow}Warning!${default} $*"
 	fn_sleep_time
 }
 
 fn_print_warning_nl(){
-	echo -e "${lightyellow}Warning!${default} $@"
+	echo -e "${lightyellow}Warning!${default} $*"
 	fn_sleep_time
 }
 
 # Information!
 fn_print_information(){
-	echo -en "${cyan}Information!${default} $@"
+	echo -en "${cyan}Information!${default} $*"
 	fn_sleep_time
 }
 
 fn_print_information_nl(){
-	echo -e "${cyan}Information!${default} $@"
+	echo -e "${cyan}Information!${default} $*"
 	fn_sleep_time
 }
 

+ 1 - 1
lgsm/functions/info_distro.sh

@@ -235,7 +235,7 @@ if [ -z "${extip}" ]; then
 		echo -e "${extip}" > "${tmpdir}/extip.txt"
 	else
 		if [ -f "${tmpdir}/extip.txt" ]; then
-			extip=$(cat ${tmpdir}/extip.txt)
+			extip=$(cat "${tmpdir}/extip.txt")
 		else
 			echo -e "x.x.x.x"
 		fi

+ 11 - 5
linuxgsm.sh

@@ -102,6 +102,7 @@ fn_bootstrap_fetch_file(){
 	if [ -f "${local_filedir}/${local_filename}" ]; then
 		# Run file if run is set.
 		if [ "${run}" == "run" ]; then
+			# shellcheck source=/dev/null
 			source "${local_filedir}/${local_filename}"
 		fi
 	fi
@@ -127,7 +128,7 @@ fn_bootstrap_fetch_file_github(){
 
 fn_print_center() {
 	columns="$(tput cols)"
-	line="$@"
+	line="$*"
 	printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
 }
 
@@ -347,20 +348,25 @@ else
 				fi
 			fi
 		fi
+		# shellcheck source=/dev/null
 		source "${configdirserver}/_default.cfg"
 		# Load the common.cfg config. If missing download it.
 		if [ ! -f "${configdirserver}/common.cfg" ]; then
 			fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
+			# shellcheck source=/dev/null
 			source "${configdirserver}/common.cfg"
 		else
+			# shellcheck source=/dev/null
 			source "${configdirserver}/common.cfg"
 		fi
 		# Load the instance.cfg config. If missing download it.
-		if [ ! -f "${configdirserver}/${selfname}.cfg" ]; then
-			fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
-			source "${configdirserver}/${selfname}.cfg"
+		if [ ! -f "${configdirserver}/${servicename}.cfg" ]; then
+			fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${servicename}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
+			# shellcheck source=/dev/null
+			source "${configdirserver}/${servicename}.cfg"
 		else
-			source "${configdirserver}/${selfname}.cfg"
+			# shellcheck source=/dev/null
+			source "${configdirserver}/${servicename}.cfg"
 		fi
 
 		# Load the linuxgsm.sh in to tmpdir. If missing download it.

+ 13 - 13
tests/tests_defaultcfg/tests_defaultcfg.sh

@@ -11,7 +11,7 @@ while IFS= read -r -d $'\0' line; do
 	diffoutput=$(diff tests/tests_defaultcfg/defaultcfg_0.txt  defaultcfgtemp.txt)
 	if [ "${diffoutput}" ]; then
 		echo "File with errors:"
-	       	echo "${line}"
+		echo "${line}"
 		echo -e "================================="
 		echo "${diffoutput}"
 		echo ""
@@ -27,11 +27,11 @@ echo -e "test checks that vars present in ALL _default.cfg files are correct."
 echo -e ""
 find lgsm/config-default/config-lgsm/ ! -name '*template.cfg' -name "*.cfg" -type f -print0 |
 while IFS= read -r -d $'\0' line; do
-	grep = ${line}  | cut -f1 -d"=" > defaultcfgtemp.txt
+	grep "=" "${line}" | cut -f1 -d"=" > defaultcfgtemp.txt
 	diffoutput=$(diff tests/tests_defaultcfg/defaultcfg_0.txt  defaultcfgtemp.txt | grep '^<')
 	if [ "${diffoutput}" ]; then
 		echo "File with errors:"
-	       	echo "${line}"
+		echo "${line}"
 		echo -e "================================="
 		echo "${diffoutput}"
 		echo ""
@@ -47,14 +47,14 @@ echo -e "test checks that comments in ALL _default.cfg files are correct."
 echo -e ""
 find lgsm/config-default/config-lgsm/ ! -name '*template.cfg' -name "*.cfg" -type f -print0 |
 while IFS= read -r -d $'\0' line; do
-        grep "#" ${line}  > defaultcfgtemp.txt
-        diffoutput=$(diff tests/tests_defaultcfg/defaultcfg_1.txt  defaultcfgtemp.txt | grep '^<')
-        if [ "${diffoutput}" ]; then
-                echo "File with errors:"
-                echo "${line}"
-                echo -e "================================="
-                echo "${diffoutput}"
-                echo ""
-        fi
-        rm defaultcfgtemp.txt
+	grep "#" "${line}"  > defaultcfgtemp.txt
+	diffoutput=$(diff tests/tests_defaultcfg/defaultcfg_1.txt  defaultcfgtemp.txt | grep '^<')
+	if [ "${diffoutput}" ]; then
+		echo "File with errors:"
+		echo "${line}"
+		echo -e "================================="
+		echo "${diffoutput}"
+		echo ""
+	fi
+	rm defaultcfgtemp.txt
 done

+ 2 - 1
tests/tests_fctrserver.sh

@@ -113,6 +113,7 @@ fn_bootstrap_fetch_file(){
 	if [ -f "${local_filedir}/${local_filename}" ]; then
 		# Run file if run is set.
 		if [ "${run}" == "run" ]; then
+			# shellcheck source=/dev/null
 			source "${local_filedir}/${local_filename}"
 		fi
 	fi
@@ -138,7 +139,7 @@ fn_bootstrap_fetch_file_github(){
 
 fn_print_center() {
 	columns="$(tput cols)"
-	line="$@"
+	line="$*"
 	printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
 }
 

+ 1 - 1
tests/tests_jc2server.sh

@@ -136,7 +136,7 @@ fn_bootstrap_fetch_file_github(){
 
 fn_print_center() {
 	columns="$(tput cols)"
-	line="$@"
+	line="$*"
 	printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
 }
 

+ 2 - 1
tests/tests_mcserver.sh

@@ -111,6 +111,7 @@ fn_bootstrap_fetch_file(){
 	if [ -f "${local_filedir}/${local_filename}" ]; then
 		# Run file if run is set.
 		if [ "${run}" == "run" ]; then
+			# shellcheck source=/dev/null      
 			source "${local_filedir}/${local_filename}"
 		fi
 	fi
@@ -136,7 +137,7 @@ fn_bootstrap_fetch_file_github(){
 
 fn_print_center() {
 	columns="$(tput cols)"
-	line="$@"
+	line="$*"
 	printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
 }
 

+ 2 - 1
tests/tests_ts3server.sh

@@ -111,6 +111,7 @@ fn_bootstrap_fetch_file(){
 	if [ -f "${local_filedir}/${local_filename}" ]; then
 		# Run file if run is set.
 		if [ "${run}" == "run" ]; then
+			# shellcheck source=/dev/null      
 			source "${local_filedir}/${local_filename}"
 		fi
 	fi
@@ -136,7 +137,7 @@ fn_bootstrap_fetch_file_github(){
 
 fn_print_center() {
 	columns="$(tput cols)"
-	line="$@"
+	line="$*"
 	printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
 }