From ec82b624939bb298b56143620a08ef0b12bae742 Mon Sep 17 00:00:00 2001
From: Daniel Gibbs <me@danielgibbs.co.uk>
Date: Sat, 29 Apr 2017 14:52:12 +0100
Subject: [PATCH] added  2>/dev/null to all command if statements

---
 lgsm/functions/check_deps.sh              | 28 +++++++++++------------
 lgsm/functions/command_dev_detect_deps.sh |  4 ++--
 lgsm/functions/command_fastdl.sh          |  2 +-
 lgsm/functions/command_stop.sh            |  2 +-
 lgsm/functions/info_distro.sh             |  2 +-
 lgsm/functions/install_server_files.sh    |  2 +-
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/lgsm/functions/check_deps.sh b/lgsm/functions/check_deps.sh
index 01fe38c9b..1635b65c4 100644
--- a/lgsm/functions/check_deps.sh
+++ b/lgsm/functions/check_deps.sh
@@ -18,10 +18,10 @@ fn_deps_detector(){
 		depstatus=0
 		deptocheck="${javaversion}"
 		unset javacheck
-	elif [ -n "$(command -v apt-get)" ]; then
+	elif [ -n "$(command -v apt-get 2>/dev/null)" ]; then
 		dpkg-query -W -f='${Status}' ${deptocheck} 2>/dev/null | grep -q -P '^install ok installed$'
 		depstatus=$?
-	elif [ -n "$(command -v yum)" ]; then
+	elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 		yum -q list installed ${deptocheck} > /dev/null 2>&1
 		depstatus=$?
 	fi
@@ -56,15 +56,15 @@ fn_deps_email(){
 				array_deps_required+=( exim4 )
 			elif [ -d /etc/sendmail ]; then
 				array_deps_required+=( sendmail )
-			elif [ -n "$(command -v dpkg-query)" ]; then
+			elif [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
 				array_deps_required+=( mailutils postfix )
-			elif [ -n "$(command -v yum)" ]; then
+			elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 				array_deps_required+=( mailx postfix )
 			fi
 		else
-			if [ -n "$(command -v dpkg-query)" ]; then
+			if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
 				array_deps_required+=( mailutils postfix )
-			elif [ -n "$(command -v yum)" ]; then
+			elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 				array_deps_required+=( mailx postfix )
 			fi
 		fi
@@ -89,10 +89,10 @@ fn_found_missing_deps(){
 			echo -en "...\r"
 			sleep 1
 			echo -en "   \r"
-			if [ -n "$(command -v dpkg-query)" ]; then
+			if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
 				cmd="sudo dpkg --add-architecture i386; sudo apt-get update; sudo apt-get -y install ${array_deps_missing[@]}"
 				eval ${cmd}
-			elif [ -n "$(command -v yum)" ]; then
+			elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 				cmd="sudo yum -y install ${array_deps_missing[@]}"
 				eval ${cmd}
 			fi
@@ -107,9 +107,9 @@ fn_found_missing_deps(){
 			echo ""
 			fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
 			fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
-			if [ -n "$(command -v dpkg-query)" ]; then
+			if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
 				echo "	sudo dpkg --add-architecture i386; sudo apt-get update; sudo apt-get install ${array_deps_missing[@]}"
-			elif [ -n "$(command -v yum)" ]; then
+			elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 				echo "	sudo yum install ${array_deps_missing[@]}"
 			fi
 			echo ""
@@ -140,7 +140,7 @@ if [ "${function_selfname}" == "command_install.sh" ]; then
 fi
 
 # Check will only run if using apt-get or yum
-if [ -n "$(command -v dpkg-query)" ]; then
+if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
 	# Generate array of missing deps
 	array_deps_missing=()
 
@@ -149,7 +149,7 @@ if [ -n "$(command -v dpkg-query)" ]; then
 
 	# All servers except ts3 require tmux
 	if [ "${gamename}" != "TeamSpeak 3" ]; then
-		if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
+		if [ "$(command -v tmux 2>/dev/null)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
 			tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
 		else
 			array_deps_required+=( tmux )
@@ -219,7 +219,7 @@ if [ -n "$(command -v dpkg-query)" ]; then
 	fn_deps_email
 	fn_check_loop
 
-elif [ -n "$(command -v yum)" ]; then
+elif [ -n "$(command -v yum 2>/dev/null)" ]; then
 	# Generate array of missing deps
 	array_deps_missing=()
 
@@ -232,7 +232,7 @@ elif [ -n "$(command -v yum)" ]; then
 
 	# All servers except ts3 require tmux
 	if [ "${gamename}" != "TeamSpeak 3" ]; then
-		if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
+		if [ "$(command -v tmux 2>/dev/null)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
 			tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
 		else
 			array_deps_required+=( tmux )
diff --git a/lgsm/functions/command_dev_detect_deps.sh b/lgsm/functions/command_dev_detect_deps.sh
index 42ea13880..478cb1f3a 100644
--- a/lgsm/functions/command_dev_detect_deps.sh
+++ b/lgsm/functions/command_dev_detect_deps.sh
@@ -34,9 +34,9 @@ elif [ "${executable}" ==  "./ts3server_startscript.sh" ]; then
 	executable=ts3server_linux_amd64
 fi
 
-if [ "$(command -v eu-readelf)" ]; then
+if [ "$(command -v eu-readelf 2>/dev/null)" ]; then
 	readelf=eu-readelf
-elif [ "$(command -v readelf)" ]; then
+elif [ "$(command -v readelf 2>/dev/null)" ]; then
 	readelf=readelf
 else
 	echo "readelf/eu-readelf not installed"
diff --git a/lgsm/functions/command_fastdl.sh b/lgsm/functions/command_fastdl.sh
index 34ea98d0c..6c52b6a72 100644
--- a/lgsm/functions/command_fastdl.sh
+++ b/lgsm/functions/command_fastdl.sh
@@ -23,7 +23,7 @@ luafastdlfile="lgsm_cl_force_fastdl.lua"
 luafastdlfullpath="${luasvautorundir}/${luafastdlfile}"
 
 # Check if bzip2 is installed
-if [ -z "$(command -v bzip2)" ]; then
+if [ -z "$(command -v bzip2 2>/dev/null)" ]; then
 	fn_print_fail "bzip2 is not installed"
 	fn_script_log_fatal "bzip2 is not installed"
 	core_exit.sh
diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh
index fe88c43ce..1443fac8d 100644
--- a/lgsm/functions/command_stop.sh
+++ b/lgsm/functions/command_stop.sh
@@ -113,7 +113,7 @@ fn_stop_graceful_sdtd(){
 	sleep 1
 	if [ "${telnetenabled}" == "false" ]; then
 		fn_print_info_nl "Graceful: telnet: DISABLED: Enable in ${servercfg}"
-	elif [ "$(command -v expect)" ]||[ "$(which expect >/dev/null 2>&1)" ]; then
+	elif [ "$(command -v expect 2>/dev/null)" ]||[ "$(which expect >/dev/null 2>&1)" ]; then
 		# Tries to shutdown with both localhost and server IP.
 		for telnetip in 127.0.0.1 ${ip}; do
 			fn_print_dots "Graceful: telnet: ${telnetip}"
diff --git a/lgsm/functions/info_distro.sh b/lgsm/functions/info_distro.sh
index abc3fff59..882b8412b 100644
--- a/lgsm/functions/info_distro.sh
+++ b/lgsm/functions/info_distro.sh
@@ -37,7 +37,7 @@ glibcversion="$(ldd --version | sed -n '1s/.* //p')"
 
 ## tmux version
 # e.g: tmux 1.6
-if [ -z "$(command -V tmux)" ]; then
+if [ -z "$(command -V tmux 2>/dev/null)" ]; then
 	tmuxv="${red}NOT INSTALLED!${default}"
 else
 	if [ "$(tmux -V|sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')" -lt "16" ] 2>/dev/null; then
diff --git a/lgsm/functions/install_server_files.sh b/lgsm/functions/install_server_files.sh
index f86abd801..aaef4fb33 100644
--- a/lgsm/functions/install_server_files.sh
+++ b/lgsm/functions/install_server_files.sh
@@ -72,7 +72,7 @@ fn_install_server_files_steamcmd(){
 
 			# Detects if unbuffer command is available for 32 bit distributions only.
 			info_distro.sh
-			if [ $(command -v stdbuf) ]&&[ "${arch}" != "x86_64" ]; then
+			if [ $(command -v stdbuf 2>/dev/null) ]&&[ "${arch}" != "x86_64" ]; then
 				unbuffer="stdbuf -i0 -o0 -e0"
 			fi