Skip to content

Commit 91d5fe8

Browse files
authored
Refactor Asterisk installation process
Refactor Asterisk installation script to fetch versions directly from Asterisk download URLs and streamline dependency installation.
1 parent 0cbce22 commit 91d5fe8

File tree

1 file changed

+38
-50
lines changed

1 file changed

+38
-50
lines changed

install/asterisk-install.sh

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ setting_up_container
1313
network_check
1414
update_os
1515

16-
ASTERISK_VERSIONS_URL="https://www.asterisk.org/downloads/asterisk/all-asterisk-versions/"
17-
html=$(curl -fsSL "$ASTERISK_VERSIONS_URL")
18-
19-
LTS_VERSION=""
20-
for major in 20 22 24 26; do
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)
23-
if [ -n "$ver" ]; then
24-
LTS_VERSION="$LTS_VERSION $ver"
25-
fi
26-
unset ver block
27-
done
28-
LTS_VERSION=$(echo "$LTS_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1)
29-
30-
STD_VERSION=""
31-
for major in 21 23 25 27; do
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)
34-
if [ -n "$ver" ]; then
35-
STD_VERSION="$STD_VERSION $ver"
36-
fi
37-
unset ver block
38-
done
39-
STD_VERSION=$(echo "$STD_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1)
16+
msg_info "Installing Dependencies"
17+
$STD apt install -y \
18+
libsrtp2-dev \
19+
build-essential \
20+
libedit-dev \
21+
uuid-dev \
22+
libjansson-dev \
23+
libxml2-dev \
24+
libsqlite3-dev
25+
msg_ok "Installed Dependencies"
4026

41-
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/.* - //' || true)
27+
msg_info "Fetching Asterisk Versions"
28+
ASTERISK_LIST=$(curl -fsSL https://downloads.asterisk.org/pub/telephony/asterisk/ \
29+
| grep -oE 'asterisk-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' \
30+
| sed 's/asterisk-//' \
31+
| sed 's/\.tar\.gz//' \
32+
| sort -V)
33+
# LTS: Major 20, 22, 24, 26
34+
LTS_VERSION=$(echo "$ASTERISK_LIST" | grep -E '^2(0|2|4|6)\.' | tail -n1 || true)
35+
# Standard: Major 21, 23, 25, 27
36+
STD_VERSION=$(echo "$ASTERISK_LIST" | grep -E '^2(1|3|5|7)\.' | tail -n1 || true)
37+
CERT_VERSION=$(curl -fsSL https://downloads.asterisk.org/pub/telephony/certified-asterisk/ \
38+
| grep -oE 'asterisk-certified-[0-9]+\.[0-9]+-cert[0-9]+\.tar\.gz' \
39+
| sed -E 's/asterisk-certified-//' \
40+
| sed -E 's/\.tar\.gz//' \
41+
| sort -V | tail -n1 || true)
42+
msg_ok "Fetched Versions"
4343

4444
cat <<EOF
4545
Choose Asterisk version to install:
@@ -51,38 +51,27 @@ read -rp "Enter choice [1-3]: " ASTERISK_CHOICE
5151

5252
CERTIFIED=0
5353
case "$ASTERISK_CHOICE" in
54-
2)
55-
ASTERISK_VERSION="$LTS_VERSION"
56-
;;
57-
3)
58-
ASTERISK_VERSION="$CERT_VERSION"
59-
CERTIFIED=1
60-
;;
61-
*)
62-
ASTERISK_VERSION="$STD_VERSION"
63-
;;
54+
2)
55+
ASTERISK_VERSION="$LTS_VERSION"
56+
;;
57+
3)
58+
ASTERISK_VERSION="$CERT_VERSION"
59+
CERTIFIED=1
60+
;;
61+
*)
62+
ASTERISK_VERSION="$STD_VERSION"
63+
;;
6464
esac
6565

6666
if [[ "$CERTIFIED" == "1" ]]; then
67-
RELEASE="certified-asterisk-${ASTERISK_VERSION}.tar.gz"
67+
RELEASE="asterisk-certified-${ASTERISK_VERSION}.tar.gz"
6868
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/certified-asterisk/$RELEASE"
6969
else
7070
RELEASE="asterisk-${ASTERISK_VERSION}.tar.gz"
7171
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/asterisk/$RELEASE"
7272
fi
7373

74-
msg_info "Installing Dependencies"
75-
$STD apt install -y \
76-
libsrtp2-dev \
77-
build-essential \
78-
libedit-dev \
79-
uuid-dev \
80-
libjansson-dev \
81-
libxml2-dev \
82-
libsqlite3-dev
83-
msg_ok "Installed Dependencies"
84-
85-
msg_info "Downloading Asterisk"
74+
msg_info "Downloading Asterisk ($RELEASE)"
8675
temp_file=$(mktemp)
8776
curl -fsSL "$DOWNLOAD_URL" -o "$temp_file"
8877
mkdir -p /opt/asterisk
@@ -107,4 +96,3 @@ msg_ok "Installed Asterisk"
10796
motd_ssh
10897
customize
10998
cleanup_lxc
110-

0 commit comments

Comments
 (0)