Skip to content

Commit c6f08d0

Browse files
authored
Asterisk: add interactive version selection to installer (#8726)
1 parent 851f0dc commit c6f08d0

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

install/asterisk-install.sh

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,65 @@ 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>/")
22+
ver=$(echo "$block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | sed -E 's/.* - //')
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" | 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 //')
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)
40+
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/.* - //')
43+
44+
cat <<EOF
45+
Choose Asterisk version to install:
46+
1) Latest Standard ($STD_VERSION)
47+
2) Latest LTS ($LTS_VERSION)
48+
3) Latest Certified ($CERT_VERSION)
49+
EOF
50+
read -rp "Enter choice [1-3]: " ASTERISK_CHOICE
51+
52+
case "$ASTERISK_CHOICE" in
53+
2)
54+
ASTERISK_VERSION="$LTS_VERSION"
55+
;;
56+
3)
57+
ASTERISK_VERSION="$CERT_VERSION"
58+
CERTIFIED=1
59+
;;
60+
*)
61+
ASTERISK_VERSION="$STD_VERSION"
62+
;;
63+
esac
64+
65+
if [[ "$CERTIFIED" == "1" ]]; then
66+
RELEASE="certified-asterisk-${ASTERISK_VERSION}.tar.gz"
67+
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/certified-asterisk/$RELEASE"
68+
else
69+
RELEASE="asterisk-${ASTERISK_VERSION}.tar.gz"
70+
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/asterisk/$RELEASE"
71+
fi
72+
1673
msg_info "Installing Dependencies"
17-
$STD apt-get install -y \
74+
$STD apt install -y \
1875
libsrtp2-dev \
1976
build-essential \
2077
libedit-dev \
@@ -25,13 +82,12 @@ $STD apt-get install -y \
2582
msg_ok "Installed Dependencies"
2683

2784
msg_info "Downloading Asterisk"
28-
RELEASE=$(curl -fsSL https://downloads.asterisk.org/pub/telephony/asterisk/ | grep -o 'asterisk-[0-9]\+-current\.tar\.gz' | sort -V | tail -n1)
2985
temp_file=$(mktemp)
30-
curl -fsSL "https://downloads.asterisk.org/pub/telephony/asterisk/${RELEASE}" -o "$temp_file"
86+
curl -fsSL "$DOWNLOAD_URL" -o "$temp_file"
3187
mkdir -p /opt/asterisk
3288
tar zxf "$temp_file" --strip-components=1 -C /opt/asterisk
3389
cd /opt/asterisk
34-
msg_ok "Downloaded Asterisk"
90+
msg_ok "Downloaded Asterisk ($RELEASE)"
3591

3692
msg_info "Installing Asterisk"
3793
$STD ./contrib/scripts/install_prereq install
@@ -51,6 +107,7 @@ customize
51107

52108
msg_info "Cleaning up"
53109
rm -f "$temp_file"
54-
$STD apt-get -y autoremove
55-
$STD apt-get -y autoclean
110+
$STD apt -y autoremove
111+
$STD apt -y autoclean
112+
$STD apt -y clean
56113
msg_ok "Cleaned"

0 commit comments

Comments
 (0)