Browse Source

feat: update unsupprted distros and add comments to info_distro

pull/4363/head
Daniel Gibbs 2 years ago
parent
commit
bf481c3150
No known key found for this signature in database GPG Key ID: 2076B128385E8C55
  1. 4
      lgsm/modules/check_deps.sh
  2. 136
      lgsm/modules/info_distro.sh
  3. 6
      lgsm/modules/info_messages.sh
  4. 9
      lgsm/modules/info_stats.sh

4
lgsm/modules/check_deps.sh

@ -349,8 +349,8 @@ fi
# Will warn user if their distro is no longer supported by the vendor. # Will warn user if their distro is no longer supported by the vendor.
if [ -n "${distrosupport}" ]; then if [ -n "${distrosupport}" ]; then
if [ "${distrosupport}" == "unsupported" ]; then if [ "${distrosupport}" == "unsupported" ]; then
fn_print_warning_nl "${distroname} is no longer supported by the vendor. Upgrading is recommended." fn_print_warning_nl "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended."
fn_script_log_warn "${distroname} is no longer supported by the vendor. Upgrading is recommended." fn_script_log_warn "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended."
fi fi
fi fi

136
lgsm/modules/info_distro.sh

@ -21,84 +21,87 @@ fi
## Distro ## Distro
# Returns architecture, kernel and distro/os. # Returns architecture, kernel and distro/os.
arch="$(uname -m)" arch="$(uname -m)" # Architecture e.g. x86_64
kernel="$(uname -r)" kernel="$(uname -r)" # Kernel e.g. 2.6.32-042stab120.16
# Distro Name - Ubuntu 16.04 LTS
# Distro Version - 16.04
# Distro ID - ubuntu
# Distro Codename - xenial
# Gathers distro info from various sources filling in missing gaps. # Gathers distro info from various sources filling in missing gaps.
distro_info_array=(os-release lsb_release hostnamectl debian_version redhat-release) distro_info_array=(os-release lsb_release hostnamectl debian_version redhat-release)
for distro_info in "${distro_info_array[@]}"; do for distro_info in "${distro_info_array[@]}"; do
if [ -f "/etc/os-release" ] && [ "${distro_info}" == "os-release" ]; then if [ -f "/etc/os-release" ] && [ "${distro_info}" == "os-release" ]; then
distroname="$(grep "PRETTY_NAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" distroname="$(grep "PRETTY_NAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. Ubuntu 22.04.3 LTS
distroversion="$(grep "VERSION_ID" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" distroversion="$(grep "VERSION_ID" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. 22.04
# Special var for rhel like distros to removed point in number e.g 8.4 to just 8. # Special var for rhel like distros to remove point in number e.g 8.4 to just 8.
distroversionrh="$(sed -nr 's/^VERSION_ID="([0-9]*).+?"/\1/p' /etc/os-release)" if [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then
distroid="$(grep "ID=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" distroversionrh="$(sed -nr 's/^VERSION_ID="([0-9]*).+?"/\1/p' /etc/os-release)" # e.g. 8
distroidlike="$(grep "ID_LIKE=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" fi
distrocodename="$(grep "VERSION_CODENAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" distroid="$(grep "ID=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. ubuntu
distroidlike="$(grep "ID_LIKE=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. debian
distrocodename="$(grep "VERSION_CODENAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. jammy
elif [ "$(command -v lsb_release 2> /dev/null)" ] && [ "${distro_info}" == "lsb_release" ]; then elif [ "$(command -v lsb_release 2> /dev/null)" ] && [ "${distro_info}" == "lsb_release" ]; then
if [ -z "${distroname}" ]; then if [ -z "${distroname}" ]; then
distroname="$(lsb_release -sd)" distroname="$(lsb_release -sd)" # e.g. Ubuntu 22.04.3 LTS
elif [ -z "${distroversion}" ]; then elif [ -z "${distroversion}" ]; then
distroversion="$(lsb_release -sr)" distroversion="$(lsb_release -sr)" # e.g. 22.04
elif [ -z "${distroid}" ]; then elif [ -z "${distroid}" ]; then
distroid="$(lsb_release -si)" distroid="$(lsb_release -si)" # e.g. Ubuntu
elif [ -z "${distrocodename}" ]; then elif [ -z "${distrocodename}" ]; then
distrocodename="$(lsb_release -sc)" distrocodename="$(lsb_release -sc)" # e.g. jammy
fi fi
elif [ "$(command -v hostnamectl 2> /dev/null)" ] && [ "${distro_info}" == "hostnamectl" ]; then elif [ "$(command -v hostnamectl 2> /dev/null)" ] && [ "${distro_info}" == "hostnamectl" ]; then
if [ -z "${distroname}" ]; then if [ -z "${distroname}" ]; then
distroname="$(hostnamectl | grep "Operating System" | sed 's/Operating System: //g')" distroname="$(hostnamectl | grep "Operating System" | sed 's/Operating System: //g')" # e.g. Ubuntu 22.04.3 LTS
fi fi
elif [ -f "/etc/debian_version" ] && [ "${distro_info}" == "debian_version" ]; then elif [ -f "/etc/debian_version" ] && [ "${distro_info}" == "debian_version" ]; then
if [ -z "${distroname}" ]; then if [ -z "${distroname}" ]; then
distroname="Debian $(cat /etc/debian_version)" distroname="Debian $(cat /etc/debian_version)" # e.g. Debian bookworm/sid
elif [ -z "${distroversion}" ]; then elif [ -z "${distroversion}" ]; then
distroversion="$(cat /etc/debian_version)" distroversion="$(cat /etc/debian_version)" # e.g. bookworm/sid
elif [ -z "${distroid}" ]; then elif [ -z "${distroid}" ]; then
distroid="debian" distroid="debian"
fi fi
elif [ -f "/etc/redhat-release" ] && [ "${distro_info}" == "redhat-release" ]; then elif [ -f "/etc/redhat-release" ] && [ "${distro_info}" == "redhat-release" ]; then
if [ -z "${distroname}" ]; then if [ -z "${distroname}" ]; then
distroname="$(cat /etc/redhat-release)" distroname="$(cat /etc/redhat-release)" # e.g. Rocky Linux release 9.2 (Blue Onyx)
elif [ -z "${distroversion}" ]; then elif [ -z "${distroversion}" ]; then
distroversion="$(rpm -qa \*-release | grep -Ei "oracle|redhat|centos|fedora" | cut -d"-" -f3)" distroversion="$(rpm -qa \*-release | grep -Ei "oracle|redhat|centos|fedora|rocky|alma" | cut -d"-" -f3)" # e.g. 9.2
elif [ -z "${distroid}" ]; then elif [ -z "${distroid}" ]; then
distroid="$(awk '{print $1}' /etc/redhat-release)" distroid="$(awk '{print $1}' /etc/redhat-release)" # e.g. Rocky
fi fi
fi fi
done done
# Get virtual environment type. # Get virtual environment type.
if [ "$(command -v systemd-detect-virt 2> /dev/null)" ]; then if [ "$(command -v systemd-detect-virt 2> /dev/null)" ]; then
virtualenvironment="$(systemd-detect-virt)" virtualenvironment="$(systemd-detect-virt)" # e.g. kvm
fi fi
# Some RHEL based distros use 8.4 instead of just 8. # distroversioncsv is used for selecting the correct distro csv in data directory
if [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then if [ -n "${distroversionrh}" ]; then
distroversioncsv="${distroversionrh}" distroversioncsv="${distroversionrh}" # e.g. 8
else else
distroversioncsv="${distroversion}" distroversioncsv="${distroversion}" # e.g. 22.04
fi fi
# Check if distro supported by distro vendor. # Check if distro supported by distro vendor.
# distro-info available in debian based distros.
if [ "$(command -v distro-info 2> /dev/null)" ]; then if [ "$(command -v distro-info 2> /dev/null)" ]; then
distrosunsupported="$(distro-info --unsupported)" distrosunsupported="$(distro-info --unsupported)"
distrosunsupported_array=("${distrosunsupported}") distrosunsupported_array=("${distrosunsupported}")
for distrounsupported in "${distrosunsupported_array[@]}"; do for distrounsupported in "${distrosunsupported_array[@]}"; do
if [ "${distrounsupported}" == "${distrocodename}" ]; then if [ "${distrounsupported}" == "${distrocodename}" ]; then
distrosupport=unsupported distrosupport="unsupported"
break break
else else
distrosupport=supported distrosupport="supported"
fi fi
done done
else elif [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then
distrosupport=unknown # RHEL/CentOS 7 EOL 2024-06-30. Will be unsupported after this date.
if [ "${distroversionrh}" -lt "8" ] && [ "$(date +%s)" -lt "1719705600" ]; then
distrosupport="unsupported"
else
distrosupport="supported"
fi
fi fi
## Glibc version ## Glibc version
@ -161,36 +164,35 @@ if [ "$(command -v numfmt 2> /dev/null)" ]; then
# Issue #2005 - Kernel 3.14+ contains MemAvailable which should be used. All others will be calculated. # Issue #2005 - Kernel 3.14+ contains MemAvailable which should be used. All others will be calculated.
# get the raw KB values of these fields. # get the raw KB values of these fields.
physmemtotalkb="$(grep MemTotal /proc/meminfo | awk '{print $2}')" physmemtotalkb="$(grep MemTotal /proc/meminfo | awk '{print $2}')" # integer
physmemfreekb="$(grep ^MemFree /proc/meminfo | awk '{print $2}')" physmemfreekb="$(grep ^MemFree /proc/meminfo | awk '{print $2}')" # integer
physmembufferskb="$(grep ^Buffers /proc/meminfo | awk '{print $2}')" physmembufferskb="$(grep ^Buffers /proc/meminfo | awk '{print $2}')" # integer
physmemcachedkb="$(grep ^Cached /proc/meminfo | awk '{print $2}')" physmemcachedkb="$(grep ^Cached /proc/meminfo | awk '{print $2}')" # integer
physmemreclaimablekb="$(grep ^SReclaimable /proc/meminfo | awk '{print $2}')" physmemreclaimablekb="$(grep ^SReclaimable /proc/meminfo | awk '{print $2}')" # integer
# check if MemAvailable Exists. # check if MemAvailable Exists.
if grep -q ^MemAvailable /proc/meminfo; then if grep -q ^MemAvailable /proc/meminfo; then
physmemactualfreekb="$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')" physmemactualfreekb="$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')" # integer
else else
physmemactualfreekb="$((physmemfreekb + physmembufferskb + physmemcachedkb))" physmemactualfreekb="$((physmemfreekb + physmembufferskb + physmemcachedkb))" # integer
fi fi
# Available RAM and swap. # Available RAM and swap.
physmemtotalmb="$((physmemtotalkb / 1024))" physmemtotalmb="$(((physmemtotalkb + 512) / 1024))" # integer
physmemtotal="$(numfmt --to=iec --from=iec --suffix=B "${physmemtotalkb}K")" physmemtotalgb="$(((physmemtotalmb + 512) / 1024))" # integer
physmemfree="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" physmemtotal="$(numfmt --to=iec --from=iec --suffix=B "${physmemtotalkb}K")" # string
physmemused="$(numfmt --to=iec --from=iec --suffix=B "$((physmemtotalkb - physmemfreekb - physmembufferskb - physmemcachedkb - physmemreclaimablekb))K")" physmemfree="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" # string
physmemavailable="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" physmemused="$(numfmt --to=iec --from=iec --suffix=B "$((physmemtotalkb - physmemfreekb - physmembufferskb - physmemcachedkb - physmemreclaimablekb))K")" # string
physmemcached="$(numfmt --to=iec --from=iec --suffix=B "$((physmemcachedkb + physmemreclaimablekb))K")" physmemavailable="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" # string
physmemcached="$(numfmt --to=iec --from=iec --suffix=B "$((physmemcachedkb + physmemreclaimablekb))K")" # string
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")" swaptotal="$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapTotal /proc/meminfo | awk '{print $2}')K")" # string
swapused="$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^SwapTotal /proc/meminfo | awk '{print $2}') - $(grep ^SwapFree /proc/meminfo | awk '{print $2}')))K")" swapfree="$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapFree /proc/meminfo | awk '{print $2}')K")" # string
swapused="$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^SwapTotal /proc/meminfo | awk '{print $2}') - $(grep ^SwapFree /proc/meminfo | awk '{print $2}')))K")" # string
# RAM usage of the game server pid # RAM usage of the game server pid
# MB
if [ "${gameserverpid}" ]; then if [ "${gameserverpid}" ]; then
memused="$(ps --forest -o rss -g "${gameserverpid}" | awk '{s+=$1} END {print s}' | awk '{$1/=1024;printf "%.0f",$1}{print $2}')" memusedmb="$(ps --forest -o rss -g "${gameserverpid}" | awk '{s+=$1} END {print s}' | awk '{$1/=1024;printf "%.0f",$1}{print $2}')" # integer
# % memusedpct="$(ps --forest -o %mem -g "${gameserverpid}" | awk '{s+=$1} END {print s}')" # integer
pmemused="$(ps --forest -o %mem -g "${gameserverpid}" | awk '{s+=$1} END {print s}')"
fi fi
else else
# Older distros will need to use free. # Older distros will need to use free.
@ -203,32 +205,32 @@ else
else else
humanreadable="-h" humanreadable="-h"
fi fi
physmemtotalmb="$(free -m | awk '/Mem:/ {print $2}')" physmemtotalmb="$(free -m | awk '/Mem:/ {print $2}')" # string
physmemtotal="$(free ${humanreadable} | awk '/Mem:/ {print $2}')" physmemtotal="$(free ${humanreadable} | awk '/Mem:/ {print $2}')" # string
physmemfree="$(free ${humanreadable} | awk '/Mem:/ {print $4}')" physmemfree="$(free ${humanreadable} | awk '/Mem:/ {print $4}')" # string
physmemused="$(free ${humanreadable} | awk '/Mem:/ {print $3}')" physmemused="$(free ${humanreadable} | awk '/Mem:/ {print $3}')" # string
oldfree="$(free ${humanreadable} | awk '/cache:/')" oldfree="$(free ${humanreadable} | awk '/cache:/')"
if [ "${oldfree}" ]; then if [ "${oldfree}" ]; then
physmemavailable="n/a" physmemavailable="n/a"
physmemcached="n/a" physmemcached="n/a"
else else
physmemavailable="$(free ${humanreadable} | awk '/Mem:/ {print $7}')" physmemavailable="$(free ${humanreadable} | awk '/Mem:/ {print $7}')" # string
physmemcached="$(free ${humanreadable} | awk '/Mem:/ {print $6}')" physmemcached="$(free ${humanreadable} | awk '/Mem:/ {print $6}')" # string
fi fi
swaptotal="$(free ${humanreadable} | awk '/Swap:/ {print $2}')" swaptotal="$(free ${humanreadable} | awk '/Swap:/ {print $2}')" # string
swapused="$(free ${humanreadable} | awk '/Swap:/ {print $3}')" swapused="$(free ${humanreadable} | awk '/Swap:/ {print $3}')" # string
swapfree="$(free ${humanreadable} | awk '/Swap:/ {print $4}')" swapfree="$(free ${humanreadable} | awk '/Swap:/ {print $4}')" # string
fi fi
### Disk information ### Disk information
## Available disk space on the partition. ## Available disk space on the partition.
filesystem="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $1}')" filesystem="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $1}')" # string e.g /dev/sda
totalspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $2}')" totalspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $2}')" # string e.g 20G
usedspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $3}')" usedspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $3}')" # string e.g 15G
availspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $4}')" availspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $4}')" # string e.g 5G
## LinuxGSM used space total. ## LinuxGSM used space total.
rootdirdu="$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')" rootdirdu="$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')"

6
lgsm/modules/info_messages.sh

@ -191,10 +191,10 @@ fn_info_messages_gameserver_resource() {
else else
echo -e "${lightblue}CPU Used:\t${red}unknown${default}" echo -e "${lightblue}CPU Used:\t${red}unknown${default}"
fi fi
if [ -n "${memused}" ]; then if [ -n "${memusedmb}" ]; then
echo -e "${lightblue}Mem Used:\t${default}${pmemused}%\t${memused}MB${default}" echo -e "${lightblue}Mem Used:\t${default}${memusedpct}%\t${memusedmb}MB${default}"
else else
echo -e "${lightblue}Mem Used:\t${default}${pmemused}\t${red}unknown${default}" echo -e "${lightblue}Mem Used:\t${default}${memusedpct}\t${red}unknown${default}"
fi fi
else else
echo -e "${lightblue}CPU Used:\t${default}0%${default}" echo -e "${lightblue}CPU Used:\t${default}0%${default}"

9
lgsm/modules/info_stats.sh

@ -54,7 +54,7 @@ uuidhardware=$(cat "/etc/machine-id")
# nearest 100Mhz. # nearest 100Mhz.
cpuusedmhzroundup="$(((cpuusedmhz + 99) / 100 * 100))" cpuusedmhzroundup="$(((cpuusedmhz + 99) / 100 * 100))"
# nearest 100MB # nearest 100MB
memusedroundup="$(((memused + 99) / 100 * 100))" memusedmbroundup="$(((memusedmb + 99) / 100 * 100))"
apisecret="A-OzP02TSMWt4_vHi6ZpUw" apisecret="A-OzP02TSMWt4_vHi6ZpUw"
measurementid="G-0CR8V7EMT5" measurementid="G-0CR8V7EMT5"
@ -70,13 +70,14 @@ payload="{
\"diskused\": \"${serverfilesdu}\", \"diskused\": \"${serverfilesdu}\",
\"distro\": \"${distroname}\", \"distro\": \"${distroname}\",
\"game\": \"${gamename}\", \"game\": \"${gamename}\",
\"memusedroundup\": \"${memusedroundup}MB\", \"memusedmbroundup\": \"${memusedmbroundup}MB\",
\"ramused\": \"${memusedroundup}MB\", \"ramused\": \"${memusedmbroundup}MB\",
\"servercpu\": \"${cpumodel} ${cpucores} cores\", \"servercpu\": \"${cpumodel} ${cpucores} cores\",
\"servercpufreq\": \"${cpufreqency} x${cpucores}\", \"servercpufreq\": \"${cpufreqency} x${cpucores}\",
\"serverdisk\": \"${totalspace}\", \"serverdisk\": \"${totalspace}\",
\"serverfilesdu\": \"${serverfilesdu}\", \"serverfilesdu\": \"${serverfilesdu}\",
\"serverram\": \"${physmemtotal}\", \"serverram\": \"${physmemtotal}\",
\"serverramgb\": \"${physmemtotalgb}\",
\"uuidhardware\": \"${uuidhardware}\", \"uuidhardware\": \"${uuidhardware}\",
\"uuidinstall\": \"${uuidinstall}\", \"uuidinstall\": \"${uuidinstall}\",
\"uuidinstance\": \"${uuidinstance}\", \"uuidinstance\": \"${uuidinstance}\",
@ -156,7 +157,7 @@ fn_script_log_info "* uuid-hardware: ${uuidhardware}"
fn_script_log_info "* Game Name: ${gamename}" fn_script_log_info "* Game Name: ${gamename}"
fn_script_log_info "* Distro Name: ${distroname}" fn_script_log_info "* Distro Name: ${distroname}"
fn_script_log_info "* Game Server CPU Used: ${cpuusedmhzroundup}MHz" fn_script_log_info "* Game Server CPU Used: ${cpuusedmhzroundup}MHz"
fn_script_log_info "* Game Server RAM Used: ${memusedroundup}MB" fn_script_log_info "* Game Server RAM Used: ${memusedmbroundup}MB"
fn_script_log_info "* Game Server Disk Used: ${serverfilesdu}" fn_script_log_info "* Game Server Disk Used: ${serverfilesdu}"
fn_script_log_info "* Server CPU Model: ${cpumodel}" fn_script_log_info "* Server CPU Model: ${cpumodel}"
fn_script_log_info "* Server CPU Frequency: ${cpufreqency}" fn_script_log_info "* Server CPU Frequency: ${cpufreqency}"

Loading…
Cancel
Save