Skip to content

Commit bfeece6

Browse files
authored
Asterisk: handle errors in version retrieval commands (#8844)
1 parent bc7bf8d commit bfeece6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

install/asterisk-install.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ html=$(curl -fsSL "$ASTERISK_VERSIONS_URL")
1818

1919
LTS_VERSION=""
2020
for major in 20 22 24 26; do
21-
block=$(echo "$html" | awk "/Asterisk $major - LTS/,/<ul>/")
22-
ver=$(echo "$block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | sed -E 's/.* - //')
21+
block=$(echo "$html" | awk "/Asterisk $major - LTS/,/<ul>/" || true)
22+
ver=$(echo "$block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | sed -E 's/.* - //' || true)
2323
if [ -n "$ver" ]; then
2424
LTS_VERSION="$LTS_VERSION $ver"
2525
fi
@@ -29,8 +29,8 @@ LTS_VERSION=$(echo "$LTS_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1)
2929

3030
STD_VERSION=""
3131
for major in 21 23 25 27; do
32-
block=$(echo "$html" | awk "/Asterisk $major</,/<ul>/")
33-
ver=$(echo "$block" | grep -oE 'Download (Latest - )?[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | sed -E 's/.* - //;s/Download //')
32+
block=$(echo "$html" | grep -A 20 "Asterisk $major</h3>" | head -n 20 || true)
33+
ver=$(echo "$block" | grep -oE 'Download (Latest - )?'"$major"'\.[0-9]+\.[0-9]+' | head -n1 | sed -E 's/Download (Latest - )?//' || true)
3434
if [ -n "$ver" ]; then
3535
STD_VERSION="$STD_VERSION $ver"
3636
fi
@@ -39,7 +39,7 @@ done
3939
STD_VERSION=$(echo "$STD_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1)
4040

4141
cert_block=$(echo "$html" | awk '/Certified Asterisk/,/<ul>/')
42-
CERT_VERSION=$(echo "$cert_block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+-cert[0-9]+' | head -n1 | sed -E 's/.* - //')
42+
CERT_VERSION=$(echo "$cert_block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+-cert[0-9]+' | head -n1 | sed -E 's/.* - //' || true)
4343

4444
cat <<EOF
4545
Choose Asterisk version to install:
@@ -49,6 +49,7 @@ Choose Asterisk version to install:
4949
EOF
5050
read -rp "Enter choice [1-3]: " ASTERISK_CHOICE
5151

52+
CERTIFIED=0
5253
case "$ASTERISK_CHOICE" in
5354
2)
5455
ASTERISK_VERSION="$LTS_VERSION"

0 commit comments

Comments
 (0)