Skip to content

Commit bce5ae3

Browse files
committed
install: Add support for Alpine Linux.
Add support and workarounds for Alpine Linux / musl systems.
1 parent e7204a7 commit bce5ae3

File tree

4 files changed

+118
-30
lines changed

4 files changed

+118
-30
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ jobs:
180180
run: |
181181
./phreaknet.sh make
182182
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
183+
alpine-linux:
184+
runs-on: ubuntu-24.04
185+
name: Alpine Linux
186+
container: alpine:latest
187+
steps:
188+
- uses: actions/checkout@v4
189+
- name: Build DAHDI and Asterisk
190+
run: |
191+
./phreaknet.sh make
192+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --autokvers --drivers --devmode
183193
fedora-42:
184194
runs-on: ubuntu-24.04
185195
name: Fedora 42

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ For further details, please refer to the Docs: https://docs.phreaknet.org/#phrea
160160
161161
> [!CAUTION]
162162
> PhreakScript is primarily supported on Debian-based Linux systems, and DAHDI and Asterisk are best supported on these platforms.
163-
> Limited support is available for other Linux distros (Fedora, RHEL, Rocky Linux, SUSE, Arch Linux, etc.).
163+
> Limited support is available for other Linux distros (Fedora, RHEL, Rocky Linux, SUSE, Arch Linux, Alpine Linux, etc.).
164164
> Extremely limited support exists for FreeBSD, and BSDs (and UNIX in general) are not recommended for running Asterisk/DAHDI - use Linux instead if possible.
165165
166166
### License

phreaknet.sh

Lines changed: 106 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ elif [ "$OS_DIST_INFO" = "openSUSE Tumbleweed" ]; then
319319
PAC_MAN="zypper"
320320
elif [ -r /etc/arch-release ]; then
321321
PAC_MAN="pacman"
322+
elif [ -r /etc/alpine-release ]; then
323+
PAC_MAN="apk"
322324
elif [ ! -f /etc/debian_version ]; then # Default is Debian
323325
echoerr "Support for this platform ($OS_DIST_INFO) is limited... use at your own risk..."
324326

@@ -360,6 +362,8 @@ update_packages() {
360362
zypper update -y
361363
elif [ "$PAC_MAN" = "pacman" ]; then
362364
pacman -Syu --noconfirm
365+
elif [ "$PAC_MAN" = "apk" ]; then
366+
apk update
363367
elif [ "$PAC_MAN" = "pkg" ]; then
364368
pkg install -y
365369
pkg upgrade -y
@@ -374,11 +378,13 @@ install_package() {
374378
if [ "$PAC_MAN" = "apt-get" ]; then
375379
apt-get install -y $1
376380
elif [ "$PAC_MAN" = "yum" ]; then
377-
yum install -y $1
381+
yum install -y --allowerasing $1
378382
elif [ "$PAC_MAN" = "zypper" ]; then
379383
zypper install -y $1
380384
elif [ "$PAC_MAN" = "pacman" ]; then
381385
pacman -Sy --noconfirm $1
386+
elif [ "$PAC_MAN" = "apk" ]; then
387+
apk add $1
382388
elif [ "$PAC_MAN" = "pkg" ]; then
383389
pkg install -y $1
384390
else
@@ -398,6 +404,8 @@ if ! which "which" > /dev/null; then
398404
install_package "which"
399405
elif [ "$PAC_MAN" = "pacman" ]; then
400406
install_package "which"
407+
elif [ "$PAC_MAN" = "apk" ]; then
408+
install_package "apk"
401409
fi
402410
if ! which "which" > /dev/null; then
403411
echoerr "which is still not installed?"
@@ -414,11 +422,17 @@ ensure_installed() {
414422
ensure_installed "wget"
415423

416424
# Wget2 does not support --show-progress, uses --force-progress instead
417-
WGET_VERSION=$( wget --version | head -n 1 )
418-
if [ "${WGET_VERSION#*"Wget2"}" != "$WGET_VERSION" ]; then
419-
WGET="$WGET --force-progress"
420-
else
421-
WGET="$WGET --show-progress"
425+
if [ "$PAC_MAN" = "apk" ]; then
426+
# Alpine's wget is part of BusyBox and doesn't have any progress options anyways
427+
WGET="$WGET"
428+
fi
429+
if [ "$WGET" = "" ]; then
430+
WGET_VERSION=$( wget --version | head -n 1 )
431+
if [ "${WGET_VERSION#*"Wget2"}" != "$WGET_VERSION" ]; then
432+
WGET="$WGET --force-progress"
433+
else
434+
WGET="$WGET --show-progress"
435+
fi
422436
fi
423437

424438
if [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
@@ -431,6 +445,13 @@ if ! which "getopt" > /dev/null; then
431445
fi
432446
ensure_installed "hostname"
433447

448+
AST_CONFIGURE_FLAGS="--with-jansson-bundled"
449+
if [ "$PAC_MAN" = "apk" ]; then
450+
AST_CONFIGURE_FLAGS="$AST_CONFIGURE_FLAGS --without-pjproject-bundled --without-execinfo"
451+
else
452+
AST_CONFIGURE_FLAGS="$AST_CONFIGURE_FLAGS --with-pjproject-bundled" # default
453+
fi
454+
434455
phreakscript_info() {
435456
printf "%s" "Hostname: "
436457
hostname
@@ -972,6 +993,15 @@ install_prereq() {
972993
if [ "$1" = "1" ]; then
973994
PREREQ_PACKAGES="$PREREQ_PACKAGES subversion libedit"
974995
fi
996+
elif [ "$PAC_MAN" = "apk" ]; then
997+
PREREQ_PACKAGES="$PREREQ_PACKAGES build-base git"
998+
if [ "$CHAN_DAHDI" = "1" ]; then
999+
PREREQ_PACKAGES="$PREREQ_PACKAGES autoconf automake m4 libtool newt-dev"
1000+
fi
1001+
if [ "$1" = "1" ]; then
1002+
PREREQ_PACKAGES="$PREREQ_PACKAGES libedit-dev libxml2-dev subversion"
1003+
PREREQ_PACKAGES="$PREREQ_PACKAGES util-linux-dev" # uuid development
1004+
fi
9751005
elif [ "$PAC_MAN" = "pkg" ]; then
9761006
PREREQ_PACKAGES="$PREREQ_PACKAGES git gmake"
9771007
if [ "$CHAN_DAHDI" = "1" ]; then
@@ -994,9 +1024,6 @@ install_prereq() {
9941024
if [ "$PAC_MAN" = "yum" ]; then
9951025
# Stop on RHEL systems without an active subscription since packages are failing to install
9961026
if ! which git > /dev/null; then
997-
if [ -f /etc/redhat-release ]; then
998-
echoerr "Subscription required to use RHEL package manager"
999-
fi
10001027
die "Git does not appear to be installed"
10011028
fi
10021029
if [ "$1" = "1" ]; then
@@ -1350,7 +1377,7 @@ install_testsuite_itself() {
13501377
}
13511378

13521379
configure_devmode() {
1353-
./configure --enable-dev-mode --with-jansson-bundled --with-pjproject-bundled
1380+
./configure --enable-dev-mode $AST_CONFIGURE_FLAGS
13541381
if [ $? -ne 0 ]; then
13551382
exit 2
13561383
fi
@@ -1739,6 +1766,32 @@ install_dahdi() {
17391766
install_package "kmod kernel-source"
17401767
elif [ "$PAC_MAN" = "pacman" ]; then
17411768
install_package "kmod linux-headers"
1769+
elif [ "$PAC_MAN" = "apk" ]; then
1770+
install_package "linux-headers linux-lts-dev"
1771+
apk search linux-headers
1772+
ls -la /usr/src
1773+
KERNEL_HEADERS_DETECTED_VER=$( ls /usr/src/ | grep linux-headers | cut -d'-' -f3- )
1774+
kernel_ver=$( uname -r | cut -d'.' -f1-5 )
1775+
if [ "$KERNEL_HEADERS_DETECTED_VER" != "$kernel_ver" ]; then
1776+
echoerr "Kernel headers mismatch present? ($KERNEL_HEADERS_DETECTED_VER != $kernel_ver)"
1777+
if [ "$AUTOSET_KVERS" = "1" ]; then
1778+
printf "Auto-setting KVERS=%s\n" "$KERNEL_HEADERS_DETECTED_VER"
1779+
KVERS="$KERNEL_HEADERS_DETECTED_VER"
1780+
fi
1781+
if [ "$KVERS" != "" ]; then
1782+
# Kernel version override for GitHub CI builds
1783+
ksrc_dir=$( ls /usr/src/ | grep linux-headers | grep "${KVERS}" | head -n 1 | tr -d '\n' )
1784+
printf "Kernel source dir: %s\n" "$ksrc_dir"
1785+
new_ksrc="/usr/src/${ksrc_dir}"
1786+
if [ "$new_ksrc" == "" ]; then
1787+
printf "Installed kernels:\n"
1788+
ls /usr/src/ | grep linux-headers
1789+
die "Couldn't autodetermine KSRC from KVERS"
1790+
fi
1791+
printf "Setting KSRC to %s\n" "$new_ksrc"
1792+
export KSRC="$new_ksrc"
1793+
fi
1794+
fi
17421795
elif [ "$PAC_MAN" = "pkg" ]; then
17431796
echoerr "DAHDI is not supported on FreeBSD! Proceed at your own risk!"
17441797
sleep 2
@@ -2416,7 +2469,7 @@ phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
24162469

24172470
if [ $AST_MAJOR_VER -lt 21 ]; then
24182471
if [ "$EXTERNAL_CODECS" = "1" ]; then
2419-
phreak_nontree_patch "main/translate.c" "translate.diff" "https://issues.asterisk.org/jira/secure/attachment/60464/translate.diff" # Bug fix to translation code
2472+
phreak_nontree_patch "main/translate.c" "translate.diff" "https://issues-archive.asterisk.org/attachments/29/ASTERISK-29455/00-translate.diff" # Bug fix to translation code
24202473
else
24212474
# WARNING: This will cause a crash due to ABI incompatibility if any external codecs are used. Use the older translate.diff patch in that case.
24222475
# This has been merged into master, but for the above reason will not appear in Asterisk until v21 when new binary codec modules are created for external codecs.
@@ -2961,6 +3014,12 @@ get_source() {
29613014
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
29623015
freebsd_port_patches
29633016
fi
3017+
if [ "$PAC_MAN" = "apk" ]; then
3018+
custom_fuzzy_patch "10-musl-mutex-init.patch" "https://git.alpinelinux.org/aports/plain/main/asterisk/10-musl-mutex-init.patch"
3019+
custom_fuzzy_patch "20-musl-astmm-fix.patch" "https://git.alpinelinux.org/aports/plain/main/asterisk/20-musl-astmm-fix.patch"
3020+
custom_fuzzy_patch "40-asterisk-cdefs.patch" "https://git.alpinelinux.org/aports/plain/main/asterisk/40-asterisk-cdefs.patch"
3021+
custom_fuzzy_patch "41-asterisk-ALLPERMS.patch" "https://git.alpinelinux.org/aports/plain/main/asterisk/41-asterisk-ALLPERMS.patch"
3022+
fi
29643023
}
29653024

29663025
# Minimum argument check
@@ -3182,12 +3241,15 @@ elif [ "$cmd" = "make" ]; then
31823241
if [ "$FILE_PATH" = "/usr/local/sbin/phreaknet" ]; then
31833242
die "PhreakScript is already installed, to reinstall, execute 'make' using the new script, e.g. ./phreaknet.sh make"
31843243
fi
3244+
if [ ! -d /usr/local/sbin ]; then # Doesn't exist out of the box on Alpine Linux
3245+
mkdir /usr/local/sbin
3246+
fi
31853247
ln -nsf $FILE_PATH /usr/local/sbin/phreaknet
31863248
if [ $? -eq 0 ]; then
31873249
echo "PhreakScript added to path."
31883250
else
3189-
echo "PhreakScript could not be added to path. Is it already there?"
3190-
echo "If it's not, move the source file (phreaknet.sh) to /usr/local/src and try again"
3251+
echoerr "PhreakScript could not be added to path. Is it already there?"
3252+
echoerr "If it's not, move the source file (phreaknet.sh) to /usr/local/src and try again"
31913253
fi
31923254
elif [ "$cmd" = "man" ]; then
31933255
cd /tmp
@@ -3321,10 +3383,26 @@ elif [ "$cmd" = "install" ]; then
33213383
fi
33223384
./contrib/scripts/install_prereq install
33233385

3386+
if [ "$PAC_MAN" = "apk" ]; then
3387+
# No bundled pjproject for Alpine Linux
3388+
cd /usr/src
3389+
PJPROJECT_VER="2.15.1"
3390+
$WGET https://github.com/pjsip/pjproject/archive/refs/tags/$PJPROJECT_VER.tar.gz
3391+
tar -zxvf $PJPROJECT_VER.tar.gz && rm $PJPROJECT_VER.tar.gz
3392+
cd pjproject-$PJPROJECT_VER
3393+
./configure --prefix=/usr --enable-shared --enable-ext-sound --disable-opencore-amr --disable-pjsua2 CFLAGS="-O2 -DNDEBUG"
3394+
make dep
3395+
echo "export LDFLAGS += -lexecinfo" > user.mak # for backtrace using musl
3396+
make
3397+
make install
3398+
ldconfig
3399+
cd $AST_SOURCE_PARENT_DIR/$AST_SRC_DIR
3400+
fi
3401+
33243402
if [ "$DEVMODE" = "1" ]; then
33253403
configure_devmode
33263404
else
3327-
./configure --with-jansson-bundled --with-pjproject-bundled
3405+
./configure $AST_CONFIGURE_FLAGS
33283406
fi
33293407
if [ $? -ne 0 ]; then
33303408
exit 2
@@ -3441,28 +3519,27 @@ elif [ "$cmd" = "install" ]; then
34413519
sed -i "" -e 's|WRAP_LIBC_MALLOC|ASTMM_LIBC ASTMM_REDIRECT|g' addons/mp3/interface.c # for format_mp3
34423520
sed -i "" -e 's|\\s|s|g' build_tools/make_xml_documentation # fix sed command in this script to remove the backslash for BSD sed
34433521
$AST_MAKE "ASTLDFLAGS=-lcrypt -lsysinfo" main
3444-
if [ $? -eq 0 ]; then
3445-
$AST_MAKE -j$(nproc) # compile Asterisk. This is the longest step, if you are installing for the first time. Also, don't let it take over the server.
3446-
fi
3447-
else
3522+
fi
3523+
3524+
if [ "$PAC_MAN" = "apk" ]; then
3525+
$AST_MAKE -j$(nproc) ASTCFLAGS="-w" utils # for astdb2sqlite3.c, #warning usage of non-standard #include <sys/cdefs.h> is deprecated [-Werror=cpp]
3526+
$AST_MAKE -j$(nproc) ASTCFLAGS="-w" addons # for format_mp3, error: #warning redirecting incorrect #include <sys/signal.h> to <signal.h> [-Werror=cpp]
3527+
$AST_MAKE -j$(nproc) ASTCFLAGS="-w" main # for ast_expr2.c, #warning usage of non-standard #include <sys/cdefs.h> is deprecated [-Werror=cpp]
3528+
$AST_MAKE -j$(nproc) ASTCFLAGS="-w" channels # XXX: Temporary, for chan_dahdi.c:7840:18: error: unused variable 'x' [-Werror=unused-variable]
3529+
fi
3530+
3531+
# Compile Asterisk. This is the longest step, if you are installing for the first time.
3532+
if [ $? -eq 0 ]; then
34483533
$AST_MAKE -j$(nproc) main # compile 'main' subdirectory first
3449-
if [ $? -eq 0 ]; then
3450-
$AST_MAKE -j$(nproc) # compile Asterisk. This is the longest step, if you are installing for the first time. Also, don't let it take over the server.
3451-
fi
3534+
fi
3535+
if [ $? -eq 0 ]; then
3536+
$AST_MAKE -j$(nproc)
34523537
fi
34533538

34543539
if [ $? -ne 0 ]; then
34553540
gcc -v
34563541
$AST_MAKE # Finish compiling antyhing that would build successfully, from the parallel build, so the noisy build only builds the offending target
34573542
$AST_MAKE NOISY_BUILD=1 # show actual compilation command that failed, with no parallelism
3458-
#if [ ! -f channels/chan_dahdi.o ]; then
3459-
# echoerr "Compilation of chan_dahdi failed?" # Only suggest this if we got around to compiling some channel drivers to begin with
3460-
# ls -la /usr/include/dahdi
3461-
# # Debug failed chan_dahdi compilation
3462-
# # chan_dahdi.c:7677:18: error: unused variable 'x' [-Werror=unused-variable]
3463-
# # 7677 | int res, x;
3464-
# sed -n 7677,7800p channels/chan_dahdi.c
3465-
#fi
34663543
if [ "$DEVMODE" = "1" ] && [ -f doc/core-en_US.xml ]; then # run just make validate-docs for doc validation
34673544
$XMLSTARLET val -d doc/appdocsxml.dtd -e doc/core-en_US.xml # by default, it doesn't tell you whether the docs failed to validate. So if validation failed, print that out.
34683545
fi

res/res_smdr_whozz.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "asterisk.h"
3131

3232
#include <pthread.h>
33+
#include <signal.h>
3334

3435
#include "asterisk/file.h"
3536
#include "asterisk/pbx.h"

0 commit comments

Comments
 (0)