Refactor Asterisk installation process (#9429)

Refactor Asterisk installation script to fetch versions directly from Asterisk download URLs and streamline dependency installation.
This commit is contained in:
CanbiZ 2025-11-25 20:31:00 +01:00 committed by GitHub
parent e13119250d
commit a9c08a611e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,33 +13,33 @@ setting_up_container
network_check network_check
update_os update_os
ASTERISK_VERSIONS_URL="https://www.asterisk.org/downloads/asterisk/all-asterisk-versions/" msg_info "Installing Dependencies"
html=$(curl -fsSL "$ASTERISK_VERSIONS_URL") $STD apt install -y \
libsrtp2-dev \
build-essential \
libedit-dev \
uuid-dev \
libjansson-dev \
libxml2-dev \
libsqlite3-dev
msg_ok "Installed Dependencies"
LTS_VERSION="" msg_info "Fetching Asterisk Versions"
for major in 20 22 24 26; do ASTERISK_LIST=$(curl -fsSL https://downloads.asterisk.org/pub/telephony/asterisk/ \
block=$(echo "$html" | awk "/Asterisk $major - LTS/,/<ul>/" || true) | grep -oE 'asterisk-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' \
ver=$(echo "$block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | sed -E 's/.* - //' || true) | sed 's/asterisk-//' \
if [ -n "$ver" ]; then | sed 's/\.tar\.gz//' \
LTS_VERSION="$LTS_VERSION $ver" | sort -V)
fi # LTS: Major 20, 22, 24, 26
unset ver block LTS_VERSION=$(echo "$ASTERISK_LIST" | grep -E '^2(0|2|4|6)\.' | tail -n1 || true)
done # Standard: Major 21, 23, 25, 27
LTS_VERSION=$(echo "$LTS_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1) STD_VERSION=$(echo "$ASTERISK_LIST" | grep -E '^2(1|3|5|7)\.' | tail -n1 || true)
CERT_VERSION=$(curl -fsSL https://downloads.asterisk.org/pub/telephony/certified-asterisk/ \
STD_VERSION="" | grep -oE 'asterisk-certified-[0-9]+\.[0-9]+-cert[0-9]+\.tar\.gz' \
for major in 21 23 25 27; do | sed -E 's/asterisk-certified-//' \
block=$(echo "$html" | grep -A 20 "Asterisk $major</h3>" | head -n 20 || true) | sed -E 's/\.tar\.gz//' \
ver=$(echo "$block" | grep -oE 'Download (Latest - )?'"$major"'\.[0-9]+\.[0-9]+' | head -n1 | sed -E 's/Download (Latest - )?//' || true) | sort -V | tail -n1 || true)
if [ -n "$ver" ]; then msg_ok "Fetched Versions"
STD_VERSION="$STD_VERSION $ver"
fi
unset ver block
done
STD_VERSION=$(echo "$STD_VERSION" | xargs | tr ' ' '\n' | sort -V | tail -n1)
cert_block=$(echo "$html" | awk '/Certified Asterisk/,/<ul>/')
CERT_VERSION=$(echo "$cert_block" | grep -oE 'Download Latest - [0-9]+\.[0-9]+-cert[0-9]+' | head -n1 | sed -E 's/.* - //' || true)
cat <<EOF cat <<EOF
Choose Asterisk version to install: Choose Asterisk version to install:
@ -64,25 +64,14 @@ case "$ASTERISK_CHOICE" in
esac esac
if [[ "$CERTIFIED" == "1" ]]; then if [[ "$CERTIFIED" == "1" ]]; then
RELEASE="certified-asterisk-${ASTERISK_VERSION}.tar.gz" RELEASE="asterisk-certified-${ASTERISK_VERSION}.tar.gz"
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/certified-asterisk/$RELEASE" DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/certified-asterisk/$RELEASE"
else else
RELEASE="asterisk-${ASTERISK_VERSION}.tar.gz" RELEASE="asterisk-${ASTERISK_VERSION}.tar.gz"
DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/asterisk/$RELEASE" DOWNLOAD_URL="https://downloads.asterisk.org/pub/telephony/asterisk/$RELEASE"
fi fi
msg_info "Installing Dependencies" msg_info "Downloading Asterisk ($RELEASE)"
$STD apt install -y \
libsrtp2-dev \
build-essential \
libedit-dev \
uuid-dev \
libjansson-dev \
libxml2-dev \
libsqlite3-dev
msg_ok "Installed Dependencies"
msg_info "Downloading Asterisk"
temp_file=$(mktemp) temp_file=$(mktemp)
curl -fsSL "$DOWNLOAD_URL" -o "$temp_file" curl -fsSL "$DOWNLOAD_URL" -o "$temp_file"
mkdir -p /opt/asterisk mkdir -p /opt/asterisk
@ -107,4 +96,3 @@ msg_ok "Installed Asterisk"
motd_ssh motd_ssh
customize customize
cleanup_lxc cleanup_lxc