From 50b391dacd7956e9d21007d151786cb06d0badc1 Mon Sep 17 00:00:00 2001 From: MicLieg <38057464+MicLieg@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:11:22 +0100 Subject: [PATCH] feat(dev): add new developer command for parsing distro details --- lgsm/modules/command_dev_details.sh | 98 ----------- .../command_dev_parse_distro_details.sh | 114 +++++++++++++ .../modules/command_dev_parse_game_details.sh | 160 ++++++++++++++++++ lgsm/modules/core_getopt.sh | 5 +- lgsm/modules/core_modules.sh | 7 +- 5 files changed, 283 insertions(+), 101 deletions(-) delete mode 100644 lgsm/modules/command_dev_details.sh create mode 100644 lgsm/modules/command_dev_parse_distro_details.sh create mode 100644 lgsm/modules/command_dev_parse_game_details.sh diff --git a/lgsm/modules/command_dev_details.sh b/lgsm/modules/command_dev_details.sh deleted file mode 100644 index 93dae77bc7..0000000000 --- a/lgsm/modules/command_dev_details.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -# LinuxGSM command_dev_debug.sh module -# Author: Daniel Gibbs -# Contributors: http://linuxgsm.com/contrib -# Website: https://linuxgsm.com -# Description: Dev only: Enables debugging log to be saved to dev-debug.log. - -if [ -f "config" ]; then - servercfgfullpath="config" -fi -if [ -f "clusterconfig" ]; then - clustercfgfullpath="clusterconfig" -fi - -info_game.sh - -carriagereturn=$(file -b "${servercfgfullpath}" | grep -q CRLF && echo "${red}CRLF${default}" || echo "${lightgreen}LF${default}") - -echo -e "" -echo -e "${bold}${lightgreen}Server Details${default}" -fn_messages_separator - -echo -e "" -echo -e "Game: ${gamename}" -echo -e "Config type: ${configtype}" -echo -e "Config file: ${servercfgfullpath}" -if [ -f "${clustercfgfullpath}" ]; then - echo -e "Cluster config file: ${clustercfgfullpath}" -fi -echo -e "Carriage Return: ${carriagereturn}" - -# Create an associative array of the server details. -declare -A server_details=( - ['Admin Password']="${adminpassword}" - ['API Port']="${apiport}" - ['Cave']="${cave}" - ['Cluster']="${cluster}" - ['Config IP']="${configip}" - ['Default Map']="${defaultmap}" - ['Game Mode']="${gamemode}" - ['Game Type']="${gametype}" - ['HTTP Enabled']="${httpenabled}" - ['HTTP IP']="${httpip}" - ['HTTP Password']="${httppassword}" - ['HTTP Port']="${httpport}" - ['HTTP User']="${httpuser}" - ['Internet IP']="${publicip}" - ['LAN Port']="${lanport}" - ['Master Port']="${masterport}" - ['Master']="${master}" - ['Maxplayers']="${maxplayers}" - ['OldQueryPortNumber']="${oldqueryportnumber}" - ['Port']="${port}" - ['Query Port']="${queryport}" - ['RCON Enabled']="${rconenabled}" - ['RCON Password']="${rconpassword}" - ['RCON Port']="${rconport}" - ['Reserved Slots']="${reservedslots}" - ['Server IP']="${ip}" - ['Server Password']="${serverpassword}" - ['Servername']="${servername}" - ['Shard']="${shard}" - ['Sharding']="${sharding}" - ['Steam Auth Port']="${steamauthport}" - ['Telnet Enabled']="${telnetenabled}" - ['Telnet IP']="${telnetip}" - ['Telnet Password']="${telnetpassword}" - ['Telnet Port']="${telnetport}" - ['Tickrate']="${tickrate}" - ['World Name']="${worldname}" - ['World Type']="${worldtype}" -) - -# Initialize a variable to keep track of missing server details. -missing_details="" - -# Loop through the server details and output them. -echo -e "" -echo -e "${bold}${lightgreen}Available Server Details${default}" -fn_messages_separator -for key in "${!server_details[@]}"; do - value=${server_details[$key]} - if [ -z "$value" ]; then - missing_details+="\n${key}" - else - echo -e "$key: $value " - fi -done - -# Output the missing server details if there are any. -if [ -n "$missing_details" ]; then - echo -e "" - echo -e "${lightgreen}Missing Server Details${default}" - fn_messages_separator - echo -e "${missing_details}" -fi - -core_exit.sh diff --git a/lgsm/modules/command_dev_parse_distro_details.sh b/lgsm/modules/command_dev_parse_distro_details.sh new file mode 100644 index 0000000000..ca2bfd9ed9 --- /dev/null +++ b/lgsm/modules/command_dev_parse_distro_details.sh @@ -0,0 +1,114 @@ +#!/bin/bash +# LinuxGSM command_dev_parse_distro_details.sh module +# Author: Daniel Gibbs +# Contributors: http://linuxgsm.com/contrib +# Website: https://linuxgsm.com +# Description: Display parsed distro details. + +check_ip.sh +check_status.sh +info_distro.sh + +# Create an associative array of the server details. +declare -A server_details=( + ['.NET Version']="${dotnetversion}" + ['Arch']="${arch}" + ['Backup Count']="${backupcount}" + ['Backup Last Date']="${lastbackupdate}" + ['Backup Last Days Ago']="${lastbackupdaysago}" + ['Backup Last Size']="${lastbackupsize}" + ['Backup Last']="${lastbackup}" + ['CPU Average Load']="${load}" + ['CPU Cores']="${cpucores}" + ['CPU Frequency']="${cpufreqency}" + ['CPU Model']="${cpumodel}" + ['Distro Codename']="${distrocodename}" + ['Distro ID Like']="${distroidlike}" + ['Distro ID']="${distroid}" + ['Distro Kernel']="${kernel}" + ['Distro Name']="${distroname}" + ['Distro Version CSV']="${distroversioncsv}" + ['Distro Version RH']="${distroversionrh}" + ['Distro Version']="${distroversion}" + ['Distro-Info Support']="${distrosupport}" + ['File System']="${filesystem}" + ['Game Server PID']="${gameserverpid}" + ['Gameserver CPU Used MHz']="${cpuusedmhz}" + ['Gameserver CPU Used']="${cpuused}" + ['Gameserver Mem Used MB']="${memusedmb}" + ['Gameserver Mem Used Pct']="${memusedpct}" + ['GLIBC Version']="${glibcversion}" + ['GLIBC']="${glibc}" + ['HLDS Linux PID']="${hldslinuxpid}" + ['Java Version']="${javaversion}" + ['Mono Version']="${monoversion}" + ['Network Interface']="${netint}" + ['Network Link Speed']="${netlink}" + ['Old Free']="${oldfree}" + ['Phys Mem Available']="${physmemavailable}" + ['Phys Mem Buffers KB']="${physmembufferskb}" + ['Phys Mem Cached']="${physmemcached}" + ['Phys Mem Free']="${physmemfree}" + ['Phys Mem Reclaimable KB']="${physmemreclaimablekb}" + ['Phys Mem Total GB']="${physmemtotalgb}" + ['Phys Mem Used']="${physmemused}" + ['Size Backup Dir']="${backupdirdu}" + ['Size Root Dir ']="${rootdirdu}" + ['Size Root Dir Excl. Backup']="${rootdirduexbackup}" + ['Size Serverfiles']="${serverfilesdu}" + ['SRCDS Linux PID']="${srcdslinuxpid}" + ['Storage Available']="${availspace}" + ['Storage Total']="${totalspace}" + ['Storage Used']="${usedspace}" + ['Swap Free']="${swapfree}" + ['Swap Total']="${swaptotal}" + ['Swap Used']="${swapused}" + ['Tmux Version']="${tmuxversion}" + ['Uptime Days']="${days}" + ['Uptime Hours']="${hours}" + ['Uptime Minutes']="${minutes}" + ['Uptime Total Seconds']="${uptime}" + ['Virtual Environment']="${virtualenvironment}" + # ['Distro Info Array']="${distro_info_array}" + # ['Distros Unsupported Array']="${distrosunsupported_array}" + # ['Distros Unsupported']="${distrosunsupported}" + # ['Human Readable']="${humanreadable}" + # ['Phys Mem Actual Free KB']="${physmemactualfreekb}" + # ['Phys Mem Cached KB']="${physmemcachedkb}" + # ['Phys Mem Free KB']="${physmemfreekb}" + # ['Phys Mem Total KB']="${physmemtotalkb}" + # ['Phys Mem Total MB']="${physmemtotalmb}" + # ['SS Info']="${ssinfo}" +) + +# Initialize variables to keep track of available and missing distro details. +available_details="" +missing_details="" + +# Loop through the distro details and store them. +for key in "${!server_details[@]}"; do + value=${server_details[$key]} + if [ -n "$value" ]; then + available_details+="${lightblue}${key}: ${default}${value}\n" + else + missing_details+="${key}\n" + fi +done + +# Sort and output the available distro details. +if [ -n "$available_details" ]; then + echo -e "" + echo -e "${bold}${lightgreen}Available Distro Details${default}" + fn_messages_separator + echo -e "${available_details}" | sort +fi + +# Sort and output the missing distro details. +if [ -n "$missing_details" ]; then + echo -e "" + echo -e "${lightgreen}Missing or unsupported Distro Details${default}" + fn_messages_separator + echo -e "${missing_details}" | sort +fi + +core_exit.sh diff --git a/lgsm/modules/command_dev_parse_game_details.sh b/lgsm/modules/command_dev_parse_game_details.sh new file mode 100644 index 0000000000..f5d6d697df --- /dev/null +++ b/lgsm/modules/command_dev_parse_game_details.sh @@ -0,0 +1,160 @@ +#!/bin/bash +# LinuxGSM command_dev_parse_game_details.sh module +# Author: Daniel Gibbs +# Contributors: http://linuxgsm.com/contrib +# Website: https://linuxgsm.com +# Description: Display parsed gameserver details. + +if [ -f "config" ]; then + servercfgfullpath="config" +fi +if [ -f "clusterconfig" ]; then + clustercfgfullpath="clusterconfig" +fi + +info_game.sh + +carriagereturn=$(file -b "${servercfgfullpath}" | grep -q CRLF && echo "${red}CRLF${default}" || echo "${lightgreen}LF${default}") + +echo -e "" +echo -e "${bold}${lightgreen}Server Details${default}" +fn_messages_separator + +echo -e "" +echo -e "${lightblue}Game: ${default}${gamename}" +echo -e "${lightblue}Config type: ${default}${configtype}" +echo -e "${lightblue}Config file: ${default}${servercfgfullpath}" +if [ -f "${clustercfgfullpath}" ]; then + echo -e "${lightblue}Cluster config file: ${default}${clustercfgfullpath}" +fi +echo -e "${lightblue}Carriage Return: ${default}${carriagereturn}" + +# Create an associative array of the server details. +declare -A server_details=( + ['Admin Password']="${adminpassword}" + ['Alert IP']="${alertip}" + ['API Port']="${apiport}" + ['App Port']="${appport}" + ['ASE']="${ase}" + ['Auth Token']="${authtoken}" + ['BattleEye Port']="${battleeyeport}" + ['Beacon Port']="${beaconport}" + ['Cave']="${cave}" + ['Client Port']="${clientport}" + ['Cluster']="${cluster}" + ['Config IP']="${configip}" + ['Creative Mode']="${creativemode}" + ['Custom Level URL']="${customlevelurl}" + ['DB Plugin']="${dbplugin}" + ['Default Map']="${defaultmap}" + ['Default Scenario']="${defaultscenario}" + ['Display Master Server']="${displaymasterserver}" + ['Epic Settings']="${epicsettings}" + ['File Port']="${fileport}" + ['Files Port']="${filesport}" + ['Game Mode']="${gamemode}" + ['Game Type']="${gametype}" + ['Home Kingdom']="${homekingdom}" + ['Home Server']="${homeserver}" + ['HTTP Enabled']="${httpenabled}" + ['HTTP IP']="${httpip}" + ['HTTP Password']="${httppassword}" + ['HTTP Port']="${httpport}" + ['HTTP User']="${httpuser}" + ['Internet IP']="${publicip}" + ['LAN Port']="${lanport}" + ['Login Server']="${loginserver}" + ['Master Port']="${masterport}" + ['Master Server']="${masterserver}" + ['Master']="${master}" + ['Max Players']="${maxplayers}" + ['Mod Server Port']="${modserverport}" + ['OldQueryPortNumber']="${oldqueryportnumber}" + ['Password']="${password}" + ['Port 401']="${port401}" + ['Port IPv6']="${portipv6}" + ['Port']="${port}" + ['Query Enabled']="${queryenabled}" + ['Query HTTP Port']="${queryhttpport}" + ['Query HTTPS Port']="${queryhttpsport}" + ['Query Mode']="${querymode}" + ['Query Port GS']="${queryportgs}" + ['Query Port']="${queryport}" + ['Query SSH Port']="${querysshport}" + ['Queue Enabled']="${queueenabled}" + ['Queue Port']="${queueport}" + ['Random Map']="${randommap}" + ['Raw Port']="${rawport}" + ['RC Password']="${rcpassword}" + ['RCON Enabled']="${rconenabled}" + ['RCON Password']="${rconpassword}" + ['RCON Port']="${rconport}" + ['RCON Web']="${rconweb}" + ['Reserved Slots']="${reservedslots}" + ['RMI Port']="${rmiport}" + ['RMI Reg Port']="${rmiregport}" + ['Salt']="${salt}" + ['Save Game Interval']="${savegameinterval}" + ['Save Interval']="${saveinterval}" + ['Secondary Port']="${port3}" + ['Seed']="${seed}" + ['Server Description']="${serverdescription}" + ['Server IP']="${ip}" + ['Server Level']="${serverlevel}" + ['Server Name']="${servername}" + ['Server Password Enabled']="${serverpasswordenabled}" + ['Server Password']="${serverpassword}" + ['Server Version']="${serverversion}" + ['Shard']="${shard}" + ['Sharding']="${sharding}" + ['Shutdown Port']="${shutdownport}" + ['Stats Port']="${statsport}" + ['Steam Auth Port']="${steamauthport}" + ['Steam Port']="${steamport}" + ['Steamworks Port']="${steamworksport}" + ['Telnet Enabled']="${telnetenabled}" + ['Telnet IP']="${telnetip}" + ['Telnet Password']="${telnetpass}" + ['Telnet Password']="${telnetpassword}" + ['Telnet Port']="${telnetport}" + ['Tickrate']="${tickrate}" + ['Unknown Port']="${unknownport}" + ['Version Count']="${versioncount}" + ['Voice Port']="${voiceport}" + ['Voice Unused Port']="${voiceunusedport}" + ['World Name']="${worldname}" + ['World Size']="${worldsize}" + ['World Type']="${worldtype}" +) + +# Initialize variables to keep track of available and missing server details. +available_details="" +missing_details="" + +# Loop through the server details and store them. +for key in "${!server_details[@]}"; do + value=${server_details[$key]} + if [ -n "$value" ]; then + available_details+="${lightblue}${key}: ${default}${value}\n" + else + missing_details+="${key}\n" + fi +done + +# Sort and output the available distro details. +if [ -n "$available_details" ]; then + echo -e "" + echo -e "${bold}${lightgreen}Available Distro Details${default}" + fn_messages_separator + echo -e "${available_details}" | sort +fi + +# Output the missing server details if there are any. +if [ -n "$missing_details" ]; then + echo -e "" + echo -e "${lightgreen}Missing or unsupported Server Details${default}" + fn_messages_separator + echo -e "${missing_details}" | sort +fi + +core_exit.sh diff --git a/lgsm/modules/core_getopt.sh b/lgsm/modules/core_getopt.sh index 685e1ce8b0..cd3e57cb57 100644 --- a/lgsm/modules/core_getopt.sh +++ b/lgsm/modules/core_getopt.sh @@ -50,7 +50,8 @@ cmd_install_squad_license=("li;license" "install_squad_license.sh" "Add your Squ cmd_fastdl=("fd;fastdl" "command_fastdl.sh" "Build a FastDL directory.") # Dev commands. cmd_dev_debug=("dev;developer" "command_dev_debug.sh" "Enable developer Mode.") -cmd_dev_details=("ddt;detect-details" "command_dev_details.sh" "Display parsed details.") +cmd_dev_parse_game_details=("pgd;parse-game-details" "command_dev_parse_game_details.sh" "Display parsed gameserver details.") +cmd_dev_parse_distro_details=("pdd;parse-distro-details" "command_dev_parse_distro_details.sh" "Display parsed distro details.") cmd_dev_detect_deps=("dd;detect-deps" "command_dev_detect_deps.sh" "Detect required dependencies.") cmd_dev_detect_glibc=("dg;detect-glibc" "command_dev_detect_glibc.sh" "Detect required glibc.") cmd_dev_detect_ldd=("dl;detect-ldd" "command_dev_detect_ldd.sh" "Detect required dynamic dependencies.") @@ -146,7 +147,7 @@ currentopt+=("${cmd_install[@]}" "${cmd_auto_install[@]}") ## Developer commands. currentopt+=("${cmd_dev_debug[@]}") if [ -f ".dev-debug" ]; then - currentopt+=("${cmd_dev_details[@]}" "${cmd_dev_detect_deps[@]}" "${cmd_dev_detect_glibc[@]}" "${cmd_dev_detect_ldd[@]}" "${cmd_dev_query_raw[@]}" "${cmd_dev_clear_modules[@]}") + currentopt+=("${cmd_dev_parse_game_details[@]}" "${cmd_dev_parse_distro_details[@]}" "${cmd_dev_detect_deps[@]}" "${cmd_dev_detect_glibc[@]}" "${cmd_dev_detect_ldd[@]}" "${cmd_dev_query_raw[@]}" "${cmd_dev_clear_modules[@]}") fi ## Sponsor. diff --git a/lgsm/modules/core_modules.sh b/lgsm/modules/core_modules.sh index e1621f0146..7ea0402e35 100644 --- a/lgsm/modules/core_modules.sh +++ b/lgsm/modules/core_modules.sh @@ -299,7 +299,12 @@ command_dev_debug.sh() { fn_fetch_module } -command_dev_details.sh() { +command_dev_parse_game_details.sh() { + modulefile="${FUNCNAME[0]}" + fn_fetch_module +} + +command_dev_parse_distro_details.sh() { modulefile="${FUNCNAME[0]}" fn_fetch_module }