Преглед изворни кода

Re-add universe check code and add MemAvailable Code

Re-add universe check code and add MemAvailable Code
Daniel Gibbs пре 7 година
родитељ
комит
ec40f0d80f
2 измењених фајлова са 60 додато и 11 уклоњено
  1. 38 0
      lgsm/functions/check_deps.sh
  2. 22 11
      lgsm/functions/info_distro.sh

+ 38 - 0
lgsm/functions/check_deps.sh

@@ -95,6 +95,39 @@ fn_install_mono_repo(){
 	fi
 }
 
+fn_install_universe_repo(){
+	# Defensive coding - As this is an ubuntu only issue then check to make sure this fix is needed, and we are using ubuntu
+   if [ "${jquniversemissing}" != "0" ]&&[ "${distroid}" == "ubuntu" ]; then
+		fn_print_warning_nl "Ubuntu 18.04.1 contains a bug which means the sources.list file does not populate with the Ubuntu universe repository."
+		fn_print_information_nl "Attempting to add Universe Repo"
+		sleep 0.5
+		sudo -v > /dev/null 2>&1
+		if [ $? -eq 0 ]; then
+			echo -en ".\r"
+			sleep 1
+			echo -en "..\r"
+			sleep 1
+			echo -en "...\r"
+			sleep 1
+			echo -en "   \r"
+			cmd="sudo apt-add-repository universe"
+			eval ${cmd}
+			if [ $? -eq 0 ]; then
+				fn_print_complete_nl "Installing universe repository completed."
+				fn_script_log_pass "Installing universe repository completed."
+			else
+				fn_print_failure_nl "Unable to install universe repository."
+				fn_script_log_fatal "Unable to install universe repository."
+			fi
+		else
+			fn_print_warning_nl "$(whoami) does not have sudo access. Manually add Universe repository."
+			fn_script_log_warn "$(whoami) does not have sudo access. Manually add Universe repository."
+			echo "	Please run the following command as a user with sudo access, and re-run the installation"
+			echo "	sudo apt-add-repository universe"
+		fi
+	fi
+}
+
 fn_deps_detector(){
 	# Checks if dependency is missing
 	if [ "${tmuxcheck}" == "1" ]; then
@@ -109,6 +142,11 @@ fn_deps_detector(){
 		unset javacheck
 	elif [ "${deptocheck}" == "jq" ]&&[ "${distroversion}" == "6" ]; then
 		jqstatus=1
+	elif [ "${deptocheck}" == "jq" ]&&[ "${distroid}" == "ubuntu" ]&&[ "${distroversion}" == "18.04" ]&& ! grep -qE "^deb .*universe" /etc/apt/sources.list; then
+		#1985 ubuntu 18.04.1 bug does not set sources.list correctly which means universe is not active by default
+		#If the universe repo does not exist, mark as dependency missing and universe missing
+		depstatus=1
+		jquniversemissing=1
 	elif [ "${deptocheck}" == "mono-complete" ]; then
 		if [ "$(command -v mono 2>/dev/null)" ]&&[ "$(mono --version 2>&1 | grep -Po '(?<=version )\d')" -ge 5 ]; then
 			# Mono >= 5.0.0 already installed

+ 22 - 11
lgsm/functions/info_distro.sh

@@ -91,18 +91,29 @@ load=$(uptime|awk -F 'load average: ' '{ print $2 }')
 
 ## Memory information
 
+# Issue #2005 - Kernel 3.14+ contains MemAvailable which should be used. All others will be calculated
+
+# get the raw KB values of these fields
+physmemtotalkb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
+physmemfreekb=$(grep ^MemFree /proc/meminfo | awk '{print $2}')
+physmembufferskb=$(grep ^Buffers /proc/meminfo | awk '{print $2}')
+physmemcachedkb=$(grep ^Cached /proc/meminfo | awk '{print $2}')
+physmemreclaimablekb=$(grep ^SReclaimable /proc/meminfo | awk '{print $2}')
+
+# check if MemAvailable Exists
+if grep -q ^MemAvailable /proc/meminfo; then
+    physmemactualfreekb=$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')
+else
+    physmemactualfreekb=$((${physmemfreekb}+${physmembufferskb}+${physmemcachedkb}))
+fi
+
 # Available RAM and swap.
-physmemtotalmb=$(($(grep MemTotal /proc/meminfo | awk '{print $2}')/1024))
-physmemtotal=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemTotal /proc/meminfo | awk '{print $2}')K")
-physmemfree=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')K")
-physmemused=$(numfmt --to=iec --from=iec --suffix=B "$(($(grep "^MemTotal\:" /proc/meminfo | awk '{print $2}')-$(grep "^MemFree\:" /proc/meminfo | awk '{print $2}')-$(grep "^Buffers\:" /proc/meminfo | awk '{print $2}')-$(grep "^Cached\:" /proc/meminfo | awk '{print $2}')-$(grep "^SReclaimable\:" /proc/meminfo | awk '{print $2}')))K")
-{ # try
-	physmemavailable=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')K")
-	physmemcached=$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^Cached /proc/meminfo | awk '{print $2}')+$(grep "^SReclaimable\:" /proc/meminfo | awk '{print $2}')))K")
-} 2>/dev/null || { # fail silently, catch
-	physmemavailable="n/a"
-	physmemcached="n/a"
-}
+physmemtotalmb=$((${physmemtotalkb}/1024))
+physmemtotal=$(numfmt --to=iec --from=iec --suffix=B "${physmemtotalkb}K")
+physmemfree=$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")
+physmemused=$(numfmt --to=iec --from=iec --suffix=B "$((${physmemtotalkb}-${physmemfreekb}-${physmembufferskb}-${physmemcachedkb}-${physmemreclaimablekb}))K")
+physmemavailable=$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")
+physmemcached=$(numfmt --to=iec --from=iec --suffix=B "$((${physmemcachedkb}+${physmemreclaimablekb}))K")
 
 swaptotal=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapTotal /proc/meminfo | awk '{print $2}')K")
 swapfree=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapFree /proc/meminfo | awk '{print $2}')K")