Skip to content

Commit 7731e9e

Browse files
committed
Fixes and improves server list validation scripts
Addresses issues in the server list validation scripts: - Fixes potential issues with parsing curl custom arguments in telegram alerts. - Corrects the shortname array generation. - Implements more robust checks for validating game icons. - Ensures the consistency of server counts across different CSV files.
1 parent 52ae5d0 commit 7731e9e

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

.github/workflows/details-check-generate-matrix.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ while read -r line; do
1414
export gamename
1515
distro=$(echo "$line" | awk -F, '{ print $4 }')
1616
export distro
17-
echo -n "{" >> "shortnamearray.json"
18-
echo -n "\"shortname\":" >> "shortnamearray.json"
19-
echo -n "\"${shortname}\"" >> "shortnamearray.json"
20-
echo -n "}," >> "shortnamearray.json"
17+
{
18+
echo -n "{";
19+
echo -n "\"shortname\":";
20+
echo -n "\"${shortname}\"";
21+
echo -n "},";
22+
} >> "shortnamearray.json"
2123
done < <(tail -n +2 serverlist.csv)
2224
sed -i '$ s/.$//' "shortnamearray.json"
2325
echo -n "]" >> "shortnamearray.json"

.github/workflows/serverlist-validate-game-icons.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
cd "${datadir}" || exit
44

5+
exitcode=0
6+
57
echo ""
68
echo "Checking that all the game servers listed in serverlist.csv have a shortname-icon.png file"
79
for shortname in $(tail -n +2 serverlist.csv | cut -d ',' -f1); do
@@ -16,9 +18,11 @@ done
1618

1719
echo ""
1820
echo "Checking if an unexpected gameicon exists"
19-
for gameicon in $(ls -1 gameicons); do
21+
shopt -s nullglob
22+
for gameiconpath in gameicons/*; do
23+
gameicon="$(basename "${gameiconpath}")"
2024
# check if $gameicon is in serverlist.csv
21-
if ! grep -q "${gameicon%-icon.png}" serverlist.csv; then
25+
if ! grep -q -F "${gameicon%-icon.png}" serverlist.csv; then
2226
echo "ERROR: gameicon ${gameicon} is not in serverlist.csv"
2327
exitcode=1
2428
else
@@ -28,7 +32,7 @@ done
2832

2933
echo ""
3034
echo "Checking that the number of gameicons matches the number of servers in serverlist.csv"
31-
gameiconcount="$(ls -1 gameicons | wc -l)"
35+
gameiconcount="$(find gameicons -mindepth 1 -maxdepth 1 -type f | wc -l)"
3236
serverlistcount="$(tail -n +2 serverlist.csv | wc -l)"
3337
if [ "${gameiconcount}" -ne "${serverlistcount}" ]; then
3438
echo "ERROR: game icons (${gameiconcount}) does not match serverlist.csv ($serverlistcount)"
@@ -37,4 +41,4 @@ else
3741
echo "OK: gameiconcount ($gameiconcount) matches serverlistcount ($serverlistcount)"
3842
fi
3943

40-
exit ${exitcode}
44+
exit "${exitcode}"

.github/workflows/serverlist-validate.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ echo "Checking that all the game servers are listed in all csv files"
33
echo "this check will ensure serverlist.csv has the same number of lines (-2 lines) as the other csv files"
44
# count the number of lines in the serverlist.csv
55
cd "${datadir}" || exit
6+
7+
exitcode=0
68
serverlistcount="$(tail -n +2 serverlist.csv | wc -l)"
79
echo "serverlistcount: $serverlistcount"
810
# get list of all csv files starting with ubunutu debian centos
9-
csvlist="$(ls -1 | grep -E '^(ubuntu|debian|centos|rhel|almalinux|rocky).*\.csv$')"
11+
shopt -s nullglob
12+
csvlist=(ubuntu*.csv debian*.csv centos*.csv rhel*.csv almalinux*.csv rocky*.csv)
1013
# loop though each csv file and make sure the number of lines is the same as the serverlistcount
11-
for csv in $csvlist; do
14+
for csv in "${csvlist[@]}"; do
1215
csvcount="$(wc -l < "${csv}")"
1316
csvcount=$((csvcount - 2))
1417
if [ "$csvcount" -ne "$serverlistcount" ]; then
@@ -35,4 +38,4 @@ for shortname in $(tail -n +2 serverlist.csv | cut -d ',' -f1); do
3538
fi
3639
done
3740

38-
exit ${exitcode}
41+
exit "${exitcode}"

lgsm/modules/alert_telegram.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ EOF
4343
)
4444

4545
fn_print_dots "Sending Telegram alert"
46-
telegramsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" ${curlcustomstring} "https://${telegramapi}/bot${telegramtoken}/sendMessage" | grep "error_code")
46+
47+
curlcustomargs=()
48+
if [ -n "${curlcustomstring}" ]; then
49+
read -r -a curlcustomargs <<< "${curlcustomstring}"
50+
fi
51+
52+
telegramsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${curlcustomargs[@]}" "https://${telegramapi}/bot${telegramtoken}/sendMessage" | grep "error_code")
4753

4854
if [ -n "${telegramsend}" ]; then
4955
fn_print_fail_nl "Sending Telegram alert: ${telegramsend}"

0 commit comments

Comments
 (0)