Skip to content

Commit cb3a092

Browse files
committed
Addresses various script improvements
Addresses multiple improvements across various scripts: - Fixes Valheim unstripped_corlib override by commenting out the lines in the config files. - Improves process identification for source and goldsrc engines using `pgrep`. - Enhances backup file identification using `find` with `-maxdepth 1` and `-type f`. - Fixes glibc version comparison logic in multiple files. - Improves UT2K4 key installation script by using printf for writing the key to the file. - Corrects the mod info extraction logic to correctly identify mod entries. - Improves amxmodx file installation/removal logic to prevent duplicate entries. - Fixes server info retrieval to handle spaces in the server list. Relates to #4696
1 parent 607f896 commit cb3a092

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

lgsm/modules/fix_vh.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ if [ -f "${modsinstalledlistfullpath}" ]; then
2121
rm -rf "${serverfiles}/unstripped_corlib"
2222
fi
2323
sed -i "s/^dllSearchPathOverride=unstripped_corlib/# &/" "${serverfiles}/doorstop_config.ini"
24-
sed -i "s/^export DOORSTOP_CORLIB_OVERRIDE_PATH="$BASEDIR\/unstripped_corlib"/# &/" "${serverfiles}/start_game_bepinex.sh"
25-
sed -i "s/^export DOORSTOP_CORLIB_OVERRIDE_PATH="${VALHEIM_PLUS_PATH}\/unstripped_corlib"/# &/" "${serverfiles}/start_server_bepinex.sh"
24+
sed -i "s|^export DOORSTOP_CORLIB_OVERRIDE_PATH=\"\\\$BASEDIR/unstripped_corlib\"|# &|" "${serverfiles}/start_game_bepinex.sh"
25+
sed -i "s|^export DOORSTOP_CORLIB_OVERRIDE_PATH=\"\\\${VALHEIM_PLUS_PATH}/unstripped_corlib\"|# &|" "${serverfiles}/start_server_bepinex.sh"
2626
fi
2727
# special exports for BepInEx if installed
2828
if grep -qE "^bepinexvh" "${modsinstalledlistfullpath}"; then

lgsm/modules/info_distro.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1313
if [ "${status}" == "1" ]; then
1414
gameserverpid="$(tmux -L "${socketname}" list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')"
1515
if [ "${engine}" == "source" ]; then
16-
srcdslinuxpid="$(ps -ef | grep -v grep | grep "${gameserverpid}" | grep srcds_linux | awk '{print $2}')"
16+
srcdslinuxpid="$(pgrep -P "${gameserverpid}" -x srcds_linux 2> /dev/null | head -n 1)"
1717
elif [ "${engine}" == "goldsrc" ]; then
18-
hldslinuxpid="$(ps -ef | grep -v grep | grep "${gameserverpid}" | grep hlds_linux | awk '{print $2}')"
18+
hldslinuxpid="$(pgrep -P "${gameserverpid}" -x hlds_linux 2> /dev/null | head -n 1)"
1919
fi
2020
fi
2121
### Distro information
@@ -252,11 +252,11 @@ if [ -d "${backupdir}" ]; then
252252
backupcount=0
253253

254254
# If there are backups in backup dir.
255-
if [ "$(find "${backupdir}" -name "*.tar.*" | wc -l)" -ne "0" ]; then
255+
if [ "$(find "${backupdir}" -maxdepth 1 -type f -name "*.tar.*" | wc -l)" -ne "0" ]; then
256256
# number of backups.
257-
backupcount="$(find "${backupdir}"/*.tar.* | wc -l)" # integer
257+
backupcount="$(find "${backupdir}" -maxdepth 1 -type f -name "*.tar.*" | wc -l)" # integer
258258
# most recent backup.
259-
lastbackup="$(ls -1t "${backupdir}"/*.tar.* | head -1)" # string
259+
lastbackup="$(find "${backupdir}" -maxdepth 1 -type f -name "*.tar.*" -printf '%T@ %p\n' 2> /dev/null | sort -nr | head -n 1 | cut -d' ' -f2-)" # string
260260
# date of most recent backup.
261261
lastbackupdate="$(date -r "${lastbackup}")" # string
262262
# no of days since last backup.
@@ -272,7 +272,7 @@ netlink=$(${ethtoolcommand} "${netint}" 2> /dev/null | grep Speed | awk '{print
272272

273273
# Sets the SteamCMD glibc requirement if the game server requirement is less or not required.
274274
if [ "${appid}" ]; then
275-
if [ "${glibc}" = "null" ] || [ -z "${glibc}" ] || [ "$(printf '%s\n'${glibc}'\n' "2.14" | sort -V | head -n 1)" != "2.14" ]; then
275+
if [ "${glibc}" = "null" ] || [ -z "${glibc}" ] || [ "$(printf '%s\n' "${glibc}" "2.14" | sort -V | head -n 1)" != "2.14" ]; then
276276
glibc="2.14"
277277
fi
278278
fi

lgsm/modules/info_messages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ fn_info_messages_script() {
578578
:
579579
elif [ -z "${glibc}" ]; then
580580
echo -e "${lightblue}glibc required:\t${red}UNKNOWN${default}"
581-
elif [ "$(printf '%s\n'${glibc}'\n' ${glibcversion} | sort -V | head -n 1)" != "${glibc}" ]; then
581+
elif [ "$(printf '%s\n' "${glibc}" "${glibcversion}" | sort -V | head -n 1)" != "${glibc}" ]; then
582582
echo -e "${lightblue}glibc required:\t${red}${glibc} ${default}(${red}distro glibc ${glibcversion} too old${default})"
583583
else
584584
echo -e "${lightblue}glibc required:\t${green}${glibc}${default}"

lgsm/modules/install_ut2k4_key.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -z "${autoinstall}" ]; then
1818
echo -e "Once you have the key enter it below"
1919
echo -n "KEY: "
2020
read -r CODE
21-
echo -e ""\""CDKey"\""="\""${CODE}"\""" > "${systemdir}/cdkey"
21+
printf '"CDKey"="%s"\n' "${CODE}" > "${systemdir}/cdkey"
2222
if [ -f "${systemdir}/cdkey" ]; then
2323
fn_script_log_info "UT2K4 Server CD Key created"
2424
fi

lgsm/modules/mods_core.sh

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ fn_mod_get_info() {
197197
# Variable to know when job is done.
198198
modinfocommand="0"
199199
# Find entry in global array.
200-
for ((index = 0; index <= ${#mods_global_array[@]}; index++)); do
200+
for ((index = 0; index < ${#mods_global_array[@]}; index++)); do
201201
# When entry is found.
202202
if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
203203
# Go back to the previous "MOD" separator.
204-
for ((index = index; index <= ${#mods_global_array[@]}; index--)); do
204+
for ((index_search = index; index_search >= 0; index_search--)); do
205205
# When "MOD" is found.
206-
if [ "${mods_global_array[index]}" == "MOD" ]; then
206+
if [ "${mods_global_array[index_search]}" == "MOD" ]; then
207207
# Get info.
208+
index=${index_search}
208209
fn_mods_define
209210
modinfocommand="1"
210211
break
@@ -331,7 +332,7 @@ fn_compatible_mod_engines() {
331332
# How many engines we need to test.
332333
enginesamount=$(echo -e "${modengines}" | awk -F ';' '{ print NF }')
333334
# Test all subvalue of "modengines" using the ";" separator.
334-
for ((gamevarindex = 1; gamevarindex < ${enginesamount}; gamevarindex++)); do
335+
for ((gamevarindex = 1; gamevarindex < enginesamount; gamevarindex++)); do
335336
# Put current engine name into modtest variable.
336337
enginemodtest=$(echo -e "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
337338
# If engine name matches.
@@ -472,7 +473,7 @@ fn_mods_check_installed() {
472473
# Count installed mods.
473474
fn_mods_count_installed
474475
# If no mods are found.
475-
if [ ${installedmodscount} -eq 0 ]; then
476+
if [ "${installedmodscount}" -eq 0 ]; then
476477
echo -e ""
477478
fn_print_failure_nl "No installed mods or addons were found"
478479
echo -e " * Install mods using LinuxGSM first with: ./${selfname} mods-install"
@@ -689,13 +690,9 @@ fn_mod_install_amxmodx_file() {
689690
# since it does exist, is the entry already in plugins.ini
690691
logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) inserted into ${modinstalldir}/addons/metamod/plugins.ini"
691692
echo -en "adding amxmodx_mm_i386.so in plugins.ini..."
692-
grep -q "amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"
693-
exitcode=$?
694-
if [ "${exitcode}" -ne 0 ]; then
693+
if ! grep -q "amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"; then
695694
# file exists but the entry does not, let's add it
696-
echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" >> "${modinstalldir}/addons/metamod/plugins.ini"
697-
exitcode=$?
698-
if [ "${exitcode}" -ne 0 ]; then
695+
if ! echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" >> "${modinstalldir}/addons/metamod/plugins.ini"; then
699696
fn_script_log_fail "${logentry}"
700697
fn_print_fail_eol_nl
701698
else
@@ -705,9 +702,7 @@ fn_mod_install_amxmodx_file() {
705702
fi
706703
else
707704
# create new file and add the mod to it
708-
echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > "${modinstalldir}/addons/metamod/plugins.ini"
709-
exitcode=$?
710-
if [ "${exitcode}" -ne 0 ]; then
705+
if ! echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > "${modinstalldir}/addons/metamod/plugins.ini"; then
711706
fn_script_log_fail "${logentry}"
712707
fn_print_fail_eol_nl
713708
core_exit.sh
@@ -723,10 +718,8 @@ fn_mod_remove_amxmodx_file() {
723718
# since it does exist, is the entry already in plugins.ini
724719
logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) removed from ${modinstalldir}/addons/metamod/plugins.ini"
725720
echo -en "removing amxmodx_mm_i386.so in plugins.ini..."
726-
grep -q "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"
727-
# iIs it found? If so remove it and clean up
728-
exitcode=$?
729-
if [ "${exitcode}" -eq 0 ]; then
721+
# is it found? If so remove it and clean up
722+
if grep -q "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"; then
730723
# delete the line we inserted
731724
sed -i '/linux addons\/amxmodx\/dlls\/amxmodx_mm_i386.so/d' "${modinstalldir}/addons/metamod/plugins.ini"
732725
# remove empty lines

linuxgsm.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ fn_install_menu() {
330330
# Gets server info from serverlist.csv and puts in to array.
331331
fn_server_info() {
332332
IFS=","
333-
server_info_array=($(grep -aw "${userinput}" "${serverlist}"))
333+
server_info_line="$(grep -aw "${userinput}" "${serverlist}" | head -n 1)"
334+
read -r -a server_info_array <<< "${server_info_line}"
334335
shortname="${server_info_array[0]}" # csgo
335336
gameservername="${server_info_array[1]}" # csgoserver
336337
gamename="${server_info_array[2]}" # Counter Strike: Global Offensive

0 commit comments

Comments
 (0)