Skip to content

Commit 7c4caaf

Browse files
committed
phreaknet.sh, phreakscript_update.sh: Improve script portability.
Several portability fixes and some other general maintenance: * Use curl instead of wget on systems with BusyBox. As part of this, use $WGET instead of wget wherever possible. * Fix Asterisk PID detection on systems with BusyBox. * Use more canonical path for rasterisk binary. * If --offline is specified, do not check if a newer version of PhreakScript is available (since we should not be using the Internet). * Add missing slipstream call for res_telos_1a2.
1 parent 3fd6127 commit 7c4caaf

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
PhreakScript installs:
66

7-
- Asterisk 22.5.0 (latest LTS release[1] of Asterisk)
7+
- Asterisk 22.6.0 (latest LTS release[1] of Asterisk)
88
- DAHDI Linux 3.4.0 (with optional DAHDI install flag)
99
- DAHDI Tools 3.4.0 (with optional DAHDI install flag)
1010
- wanpipe 7.0.38 (with optional wanpipe install flag)

phreaknet.sh

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# PhreakScript
44
# (C) 2021-2025 Naveen Albert, PhreakNet, and others - https://github.com/InterLinked1/phreakscript ; https://portal.phreaknet.org ; https://docs.phreaknet.org
5-
# v1.3.0 (2025-07-07)
5+
# v1.3.1 (2025-09-22)
66

77
# Setup (as root):
88
# cd /usr/local/src
@@ -13,6 +13,7 @@
1313
# phreaknet install
1414

1515
## Begin Change Log:
16+
# 2025-09-22 1.3.1 Improve script portability
1617
# 2025-07-07 1.3.0 Use GitHub API to download patches
1718
# 2025-01-24 1.2.2 Asterisk: Target 22.2.0
1819
# 2024-12-30 1.2.1 DAHDI Linux: Work around compilation failure for newer kernels
@@ -229,7 +230,7 @@ PAC_MAN="apt-get"
229230
AST_SOUNDS_DIR="$AST_VARLIB_DIR/sounds/en"
230231
AST_MOH_DIR="$AST_VARLIB_DIR/moh"
231232
AST_MAKE="make"
232-
WGET="wget -q"
233+
WGET="wget -q --no-cache"
233234
CURL="curl --silent --show-error -L -f"
234235
CURL_HEADERS_DUMPFILE="/tmp/ps_patchreq_headers.txt"
235236
CURL_DEBUG="curl -L --verbose"
@@ -448,6 +449,10 @@ if [ "$WGET" = "" ]; then
448449
WGET="$WGET --show-progress"
449450
fi
450451
fi
452+
if test -h /bin/ls && [[ `readlink /bin/ls` =~ busybox ]] && [ "$PAC_MAN" != "apk" ]; then
453+
# wget is useless on BusyBox (at least with AstLinux, but not Alpine Linux), use curl instead
454+
WGET="curl -s -O"
455+
fi
451456

452457
if [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
453458
WGET="wget -q" # --show-progress not supported by yum/Sangoma Linux?
@@ -633,7 +638,7 @@ Options:
633638
--manselect install: Manually run menuselect yourself
634639
--minimal install: Do not upgrade the kernel or install nonrequired dependencies (such as utilities that may be useful on typical Asterisk servers)
635640
--vanilla install: Do not install extra features or enhancements. Bug fixes are always installed. (May be required for older versions)
636-
--offline install: Use an offline installation source for disconnected environments.
641+
--offline install: Use an offline installation source for disconnected environments / do not check for PhreakScript updates
637642
--noupdate install: Do not update the package manager
638643
"
639644
phreakscript_info
@@ -715,8 +720,18 @@ stop_wanpipe() {
715720
fi
716721
}
717722

723+
get_ast_pid() {
724+
if test -h /bin/ls && [[ `readlink /bin/ls` =~ busybox ]]; then
725+
# Busy Box doesn't support ps -u or -x
726+
astpid=$( ps | grep asterisk | grep -v grep | grep -v canary | grep -v rasterisk | head -n1 | xargs | cut -d' ' -f1 )
727+
else
728+
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
729+
fi
730+
return $astpid
731+
}
732+
718733
stop_telephony() {
719-
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
734+
astpid=$( get_ast_pid )
720735
if [ "$astpid" != "" ]; then
721736
if [ "$1" = "1" ]; then
722737
# Only need to unload chan_dahdi if it's loaded
@@ -729,7 +744,7 @@ stop_telephony() {
729744
fi
730745
else
731746
service asterisk stop # stop Asterisk
732-
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
747+
astpid=$( get_ast_pid )
733748
if [ "$astpid" != "" ]; then
734749
# if that didn't work, kill it manually
735750
kill -9 $astpid
@@ -875,8 +890,8 @@ start_telephony() {
875890
service dahdi start
876891

877892
service asterisk start # Start Asterisk if it's not running already
878-
/sbin/rasterisk -x "module load chan_dahdi" # Load chan_dahdi if Asterisk was already running
879-
/sbin/rasterisk -x "dahdi show channels" # The ultimate test is what DAHDI channels actually show up in Asterisk
893+
/usr/sbin/rasterisk -x "module load chan_dahdi" # Load chan_dahdi if Asterisk was already running
894+
/usr/sbin/rasterisk -x "dahdi show channels" # The ultimate test is what DAHDI channels actually show up in Asterisk
880895
echog "Telephony initialization completed"
881896
}
882897

@@ -889,7 +904,7 @@ assert_root() {
889904

890905
download_if_missing() {
891906
if [ ! -f "$1" ]; then
892-
wget "$2"
907+
$WGET "$2"
893908
else
894909
printf "Audio file already present, not overwriting: %s\n" "$1"
895910
fi
@@ -1195,7 +1210,7 @@ install_freepbx() { # https://www.atlantic.net/vps-hosting/how-to-install-asteri
11951210
# PHP 7.4 is supported: https://www.freepbx.org/freepbx-16-is-now-released-for-general-availability/
11961211
apt-get -y install apache2 mariadb-server php libapache2-mod-php7.4 php7.4 php-pear php7.4-cgi php7.4-common php7.4-curl php7.4-mbstring php7.4-gd php7.4-mysql php7.4-bcmath php7.4-zip php7.4-xml php7.4-imap php7.4-json php7.4-snmp
11971212
cd $AST_SOURCE_PARENT_DIR
1198-
wget http://mirror.freepbx.org/modules/packages/freepbx/$FREEPBX_VERSION.tgz -O $AST_SOURCE_PARENT_DIR/$FREEPBX_VERSION.tgz
1213+
$WGET http://mirror.freepbx.org/modules/packages/freepbx/$FREEPBX_VERSION.tgz
11991214
tar -xvzf $FREEPBX_VERSION.tgz
12001215
cd $AST_SOURCE_PARENT_DIR/freepbx
12011216
rm ../$FREEPBX_VERSION.tgz
@@ -2346,7 +2361,7 @@ phreak_tree_module() { # $1 = file to patch, $2 = whether failure is acceptable
23462361

23472362
phreak_nontree_patch() { # $1 = patched file, $2 = patch name
23482363
printf "Applying patch %s to %s\n" "$2" "$1"
2349-
$WGET "$3" -O "/tmp/$2" --no-cache
2364+
$WGET "$3" -O "/tmp/$2"
23502365
if [ $? -ne 0 ]; then
23512366
die "Failed to download patch: $2"
23522367
fi
@@ -2396,7 +2411,7 @@ phreak_fuzzy_patch() {
23962411

23972412
custom_fuzzy_patch() {
23982413
printf "Applying patch %s to %s\n" "$1" "$1"
2399-
$WGET "$2" -O "/tmp/$1" --no-cache
2414+
$WGET "$2" -O "/tmp/$1"
24002415
if [ $? -ne 0 ]; then
24012416
die "Failed to download patch: $1"
24022417
fi
@@ -2446,9 +2461,10 @@ asterisk_pr_unconditional() {
24462461

24472462
custom_module() { # $1 = filename, $2 = URL to download
24482463
printf "Adding new module: %s\n" "$1"
2449-
$WGET "$2" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1" --no-cache
2464+
$WGET "$2" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1"
24502465
if [ $? -ne 0 ]; then
2451-
wget "$2" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1" --no-cache
2466+
# Use wget without -q to see more details
2467+
wget "$2" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1"
24522468
fi
24532469
if [ $? -ne 0 ]; then
24542470
echoerr "Failed to download module: $1"
@@ -2569,6 +2585,7 @@ phreak_patches() {
25692585
phreak_tree_module "res/res_phreaknet.c"
25702586
phreak_tree_module "res/res_pjsip_presence.c"
25712587
phreak_tree_module "res/res_smdr_whozz.c"
2588+
phreak_tree_module "res/res_telos_1a2.c"
25722589

25732590
if [ "$DEVMODE" = "1" ]; then
25742591
phreak_tree_module "res/res_deadlock.c" # this is not possibly useful to non-developers
@@ -2625,6 +2642,7 @@ phreak_patches() {
26252642
asterisk_pr_if 1302 220600 211100 201600 # sig_analog: Fix STP, ST2P, ST3P for fgccamamf
26262643
asterisk_pr_if 1376 220600 211100 201600 # dsp.c debug - needed for blueboxing patch to apply
26272644
asterisk_pr_if 1379 220600 211100 201600 # chan_dahdi: permdialmode - needed for rtoutpulsing patches to apply
2645+
asterisk_pr_if 1456 230100 220700 211200 201700 # chan_dahdi: Add DAHDI_CHANNEL function
26282646

26292647
## Unmerged patches: remove or switch to asterisk_pr_if once merged
26302648

@@ -2708,7 +2726,7 @@ install_odbc() {
27082726
# https://mariadb.com/downloads/#connectors
27092727
# |-> https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.1.11/
27102728
# |---> https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.1.11/mariadb-connector-odbc-3.1.11-debian-buster-amd64.tar.gz
2711-
wget https://downloads.mariadb.com/Connectors/odbc/connector-odbc-$ODBC_VER/mariadb-connector-odbc-$ODBC_VER-debian-buster-amd64.tar.gz
2729+
$WGET https://downloads.mariadb.com/Connectors/odbc/connector-odbc-$ODBC_VER/mariadb-connector-odbc-$ODBC_VER-debian-buster-amd64.tar.gz
27122730
if [ $? -ne 0 ]; then
27132731
die "MariaDB ODBC download failed"
27142732
fi
@@ -3325,7 +3343,7 @@ if [ -z "${AST_CC##*[!0-9]*}" ]; then # POSIX compliant: https://unix.stackexcha
33253343
exit 1
33263344
fi
33273345

3328-
if which curl > /dev/null; then # only execute if we have curl
3346+
if which curl > /dev/null && [ "$OFFLINE_INSTALL" != "1" ]; then # only execute if we have curl
33293347
self=`grep "# v" $FILE_PATH | head -1 | cut -d'v' -f2`
33303348
# Only download the first few lines of the file, to get the latest version number, and only check every so often
33313349
if [ -f /tmp/phreaknet_upstream_version.txt ]; then
@@ -3824,7 +3842,7 @@ elif [ "$cmd" = "install" ]; then
38243842
printf "RPT sounds don't exist yet, adding them now...\n"
38253843
mkdir $AST_SOUNDS_DIR/rpt
38263844
cd $AST_SOUNDS_DIR/rpt
3827-
wget "http://downloads.allstarlink.org/asterisk-asl-sounds-en-ulaw.tar.gz"
3845+
$WGET "http://downloads.allstarlink.org/asterisk-asl-sounds-en-ulaw.tar.gz"
38283846
# Sounds are extracted directly into the dir
38293847
tar -xvzf asterisk-asl-sounds-en-ulaw.tar.gz
38303848
rm asterisk-asl-sounds-en-ulaw.tar.gz
@@ -3854,7 +3872,7 @@ elif [ "$cmd" = "install" ]; then
38543872
$AST_MAKE config # install init script (to run Asterisk as a service)
38553873
ldconfig # update shared libraries cache
38563874
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
3857-
wget net/asterisk18/files/asterisk.in
3875+
$WGET net/asterisk18/files/asterisk.in
38583876
cp asterisk.in /usr/local/etc/rc.d/asterisk
38593877
chmod +x /usr/local/etc/rc.d/asterisk
38603878
fi
@@ -3957,7 +3975,7 @@ elif [ "$cmd" = "install" ]; then
39573975
printf "%s\n" "Asterisk installation has completed. You may now connect to the Asterisk CLI: asterisk -r"
39583976
printf "%s\n" "If you upgraded Asterisk, you will need to run 'core restart now' for the new version to load."
39593977
if [ "$CHAN_DAHDI" = "1" ]; then
3960-
echog "Note that DAHDI was installed and requires a reboot before it can be used."
3978+
echog "Note that DAHDI was installed and requires a reboot (or hotswap of kernel modules, e.g. phreaknet restart) before it can be used."
39613979
echog "Note that you will need to manually configure /etc/dahdi/system.conf appropriately for your spans."
39623980
fi
39633981
if [ "$FREEPBX_GUI" = "1" ]; then
@@ -4026,8 +4044,8 @@ elif [ "$cmd" = "pulsar" ]; then
40264044
require_installed_asterisk
40274045
cd $AST_SOURCE_PARENT_DIR
40284046
# Certificate has expired (unmaintained)
4029-
wget --no-check-certificate https://octothorpe.info/downloads/pulsar-agi.tar.gz
4030-
wget https://code.phreaknet.org/asterisk/pulsar-noanswer.agi # bug fix to pulsar.agi, to fix broken answer supervision:
4047+
$WGET --no-check-certificate https://octothorpe.info/downloads/pulsar-agi.tar.gz
4048+
$WGET https://code.phreaknet.org/asterisk/pulsar-noanswer.agi # bug fix to pulsar.agi, to fix broken answer supervision:
40314049
mv pulsar-agi.tar.gz $AST_VARLIB_DIR
40324050
cd $AST_VARLIB_DIR
40334051
tar xvfz pulsar-agi.tar.gz # automatically creates $AST_VARLIB_DIR/sounds/pulsar/
@@ -4292,7 +4310,7 @@ elif [ "$cmd" = "keygen" ]; then
42924310
PHREAKNET_CLLI=`grep -R "clli=" $AST_CONFIG_DIR | grep -v "5551111" | grep -v "curl " | grep -v "<switch-clli>" | cut -d'=' -f2 | awk '{print $1;}'`
42934311
if [ ${#PHREAKNET_CLLI} -ne 11 ]; then
42944312
printf "Failed to find CLLI by grepping configs, querying Asterisk...\n"
4295-
PHREAKNET_CLLI=`/sbin/rasterisk -x "dialplan show globals" | grep "clli=" | cut -d'=' -f2 | awk '{print $1;}'`
4313+
PHREAKNET_CLLI=`/usr/sbin/rasterisk -x "dialplan show globals" | grep "clli=" | cut -d'=' -f2 | awk '{print $1;}'`
42964314
fi
42974315
if [ ${#PHREAKNET_CLLI} -ne 11 ]; then
42984316
echoerr "Failed to find PhreakNet CLLI. For future use, please set your [globals] variables, e.g. by running phreaknet config"
@@ -4697,7 +4715,7 @@ elif [ "$cmd" = "reftrace" ]; then
46974715
ls -la /tmp/refs.txt
46984716
elif [ "$cmd" = "ccache" ]; then
46994717
cd $AST_SOURCE_PARENT_DIR
4700-
wget https://github.com/ccache/ccache/releases/download/v4.5.1/ccache-4.5.1.tar.gz
4718+
$WGET https://github.com/ccache/ccache/releases/download/v4.5.1/ccache-4.5.1.tar.gz
47014719
if [ $? -ne 0 ]; then
47024720
exit 1
47034721
fi
@@ -4724,7 +4742,7 @@ elif [ "$cmd" = "apiban" ]; then # install apiban-client: https://github.com/pal
47244742
fi
47254743
cd /usr/local/bin/apiban
47264744
if [ ! -f apiban-iptables-client ]; then
4727-
wget https://github.com/palner/apiban/raw/v0.7.0/clients/go/apiban-iptables-client
4745+
$WGET https://github.com/palner/apiban/raw/v0.7.0/clients/go/apiban-iptables-client
47284746
fi
47294747
if [ ! -f config.json ]; then
47304748
download_github_file "palner/apiban" "v0.7.0" "clients/go/apiban-iptables/config.json"

phreakscript_update.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ if [ "$src" = "https://docs.phreaknet.org/script" ]; then
88
src="https://docs.phreaknet.org/script/phreaknet.sh" # needed for compatability with < 0.0.38, can be removed eventually
99
fi
1010
printf "Upstream: %s\n" "$src"
11-
wget -q $src -O $tmp --no-cache # always replace
11+
if test -h /bin/ls && [[ `readlink /bin/ls` =~ busybox ]]; then
12+
curl -s $src > $tmp
13+
else
14+
wget -q $src -O $tmp --no-cache # always replace
15+
fi
16+
if [ ! -f $tmp ]; then
17+
err "File $tmp not found"
18+
exit 1
19+
fi
1220
chmod +x $tmp
1321
test=`$tmp help 2>&- | grep "PhreakScript" | grep "(" | wc -l`
1422
if [ "$test" = "1" ]; then

0 commit comments

Comments
 (0)