2
2
3
3
# PhreakScript
4
4
# (C) 2021-2024 Naveen Albert, PhreakNet, and others - https://github.com/InterLinked1/phreakscript ; https://portal.phreaknet.org ; https://docs.phreaknet.org
5
- # v1.1.4 (2024-09-11 )
5
+ # v1.1.5 (2024-09-15 )
6
6
7
7
# Setup (as root):
8
8
# cd /usr/local/src
13
13
# phreaknet install
14
14
15
15
# # Begin Change Log:
16
+ # 2024-09-15 1.1.5 DAHDI: Massive overhaul to DAHDI stop/start/restart logic, fixes for manual span assignment
16
17
# 2024-09-11 1.1.4 DAHDI: Target DAHDI 3.4.0, update patches
17
18
# 2024-03-17 1.1.3 DAHDI: Only build wanpipe if requested
18
19
# 2024-03-09 1.1.2 Asterisk: fix broken patches that no longer applied
@@ -444,6 +445,7 @@ Commands:
444
445
applist List Asterisk dialplan applications in current source
445
446
funclist List Asterisk dialplan functions in current source
446
447
edit Edit PhreakScript
448
+ touch Show PhreakScript file path and last modification
447
449
448
450
Options:
449
451
-b, --backtraces Enables getting backtraces
@@ -579,9 +581,12 @@ stop_telephony() {
579
581
printf " Asterisk not currently running...\n"
580
582
fi
581
583
lsmod | grep dahdi
582
- curdrivers=` lsmod | grep " dahdi " | xargs | cut -d' ' -f4-`
584
+ curdrivers=` lsmod | grep " dahdi " | xargs | cut -d' ' -f4-` # Space intentionally included, add dahdi_vpmadt032_loader later manually
583
585
printf " Current drivers: --- %s ---\n" , " $curdrivers "
584
586
stop_wanpipe
587
+ echo " $curdrivers " | tr ' ,' ' \n' | xargs -i sh -c ' echo Stopping driver: {}; modprobe -r {}'
588
+ modprobe -r dahdi_vpmadt032_loader
589
+ modprobe -r dahdi_voicebus
585
590
service dahdi status
586
591
# WARNING WARNING WARNING
587
592
# It seems that on a system where wanpipe is in use,
@@ -604,49 +609,7 @@ stop_telephony() {
604
609
printf " DAHDI shutdown complete\n"
605
610
else
606
611
printf " DAHDI is not running, skipping...\n"
607
- fi
608
- }
609
-
610
- restart_start_telephony () {
611
- printf " Starting DAHDI...\n"
612
- start_wanpipe
613
- modprobe dahdi
614
- # e.g. modprobe wcte13xp
615
- echo " $curdrivers " | tr ' ,' ' \n' | xargs -i sh -c ' echo Starting driver: {}; modprobe {}'
616
- if ! service dahdi start; then
617
- die " DAHDI failed to start"
618
- fi
619
- if ! dahdi_cfg; then # reload configs for all spans
620
- # I've noticed before the case where the order of the modprobes seems to matter
621
- # For example, with wcte13xp on span 1 and wctdm on span 2,
622
- # it loads fine if wcte13xp is loaded before wctdm, but not vice versa
623
- # Reversing the order has a good chance of making it work on "simple" systems
624
- # that only have a couple cards. More than that, and if it's failing here,
625
- # you might need to debug the modprobe order manually.
626
- printf " First initialization attempt failed, retrying modprobes in reverse order...\n"
627
- # WARNING As above, need to ensure wanpipe is STOPPED before we attempt to stop DAHDI
628
- # And yes, from testing, it really is necessary to do service dahdi restart,
629
- # before we trying modprobing the modules again
630
- stop_wanpipe
631
- service dahdi restart
632
- modprobe dahdi
633
- start_wanpipe
634
- printf " Previously loaded drivers: %s\n" , " $curdrivers "
635
- # Reverse the order of the driver modprobes
636
- echo " $curdrivers " | tr ' ,' ' \n' | tac | xargs -i sh -c ' echo Starting driver: {}; modprobe {}'
637
- dahdi_cfg
638
- if [ $? -ne 0 ]; then
639
- dahdi_hardware
640
- die " DAHDI failed to initialize... please try manually modprobe'ing the drivers and rerunning dahdi_genconf and dahdi_cfg."
641
- fi
642
- fi
643
- printf " DAHDI is now running normally...\n"
644
- if [ " $1 " = " 1" ]; then
645
- rasterisk -x " module load chan_dahdi"
646
- else
647
- service asterisk start
648
- astpid=$( ps -aux | grep " asterisk" | grep -v " grep" | head -n 1 | xargs | cut -d' ' -f2 )
649
- printf " Asterisk now running on pid %s\n" " $astpid "
612
+ modprobe -r dahdi # In case the service was already stopped but dahdi module was not yet unloaded
650
613
fi
651
614
}
652
615
@@ -655,31 +618,103 @@ restart_start_telephony() {
655
618
# $1 to restart without completely restarting Asterisk
656
619
restart_telephony () {
657
620
stop_telephony " $1 "
658
- restart_start_telephony
621
+ start_telephony
659
622
}
660
623
661
624
# Mainly intended to start the telephony drivers on bootup, since this doesn't always happen automatically
662
625
start_telephony () {
626
+ if [ ! -f /etc/udev/rules.d/dahdi.rules ]; then
627
+ echoerr " DAHDI udev rules are missing..."
628
+ fi
629
+
630
+ modprobe --first-time dahdi
631
+ if [ $? -ne 0 ]; then
632
+ echoerr " DAHDI is still running... stop these modules and try again"
633
+ lsmod | grep " dahdi" | xargs | cut -d' ' -f4- # No space in this grep
634
+ exit 1
635
+ fi
636
+ start_wanpipe # This can fail, if wanpipe isn't being used, and that's fine
637
+
638
+ printf " DAHDI hardware:\n"
639
+ dahdi_hardware # List DAHDI hardware. The dahdi module must first be running for this to work.
640
+
641
+ # Start drivers for any telephony cards, which is needed for span assignment
663
642
# sed: Each one ends in - or +, need to ignore that
664
- service dahdi start
665
- modprobe dahdi
666
- start_wanpipe
667
643
for driver in $( dahdi_hardware | awk ' {print $2}' | tr ' ,' ' \n' | sed ' s/.$//' ) ; do
668
- printf " Starting driver: %s\n " " $driver "
669
- modprobe $driver
644
+ printf " Starting driver: %s... " " $driver "
645
+ modprobe --first-time $driver
670
646
if [ $? -ne 0 ]; then
671
- echoerr " Failed to start driver $driver "
647
+ echoerr " \nFailed to start driver $driver "
648
+ else
649
+ printf " started!\n"
672
650
fi
673
651
done
674
- dahdi_cfg
652
+
653
+ # Dump detected configuration since span stuff is VERY fickle and prone to breakage
654
+ printf " DAHDI module options: "
655
+ cat /etc/modprobe.d/dahdi.conf # Dump DAHDI module options
656
+ AUTO_ASSIGN_SPANS=$( cat /sys/module/dahdi/parameters/auto_assign_spans | tr -d ' \n' )
657
+ printf " DAHDI span auto-assignment: %d\n" " $AUTO_ASSIGN_SPANS "
658
+ printf " Detected spans:\n"
659
+ dahdi_span_assignments list # List detected spans
660
+
661
+ # Get the spans assigned.
662
+ printf " Assigning DAHDI spans...\n"
663
+ dahdi_span_assignments remove
664
+ if [ " $AUTO_ASSIGN_SPANS " = " 0" ]; then
665
+ printf " Manually assigning spans according to /etc/dahdi/assigned-spans.conf\n"
666
+ dahdi_span_assignments add
667
+ else
668
+ printf " Automatically assigning spans, ignoring /etc/dahdi/assigned-spans.conf\n"
669
+ num_spans=$( dahdi_span_assignments list | wc -l )
670
+ if [ $num_spans -gt 1 ]; then
671
+ echoerr " Detected that this machine has more than 1 DAHDI span.\nYou are HIGHLY ENCOURAGED to assign the span order explicitly in /etc/dahdi/assigned-spans.conf!"
672
+ echoerr " To do this, add 'options dahdi auto_assign_spans=0' to /etc/modprobe.d/dahdi.conf and run 'phreaknet restart'"
673
+ sleep 1
674
+ fi
675
+ dahdi_span_assignments auto
676
+ fi
677
+
678
+ # Run dahdi_genconf to validate that the spans are assigned properly.
679
+ # However, don't actually replace /etc/dahdi/system.conf, since that
680
+ # would overwrite span configuration and break the system setup...
681
+ # just use a temporary configuration file to catch it and compare.
682
+ printf " Generating DAHDI channel configuration and checking differences...\n"
683
+
684
+ # XXX BUGBUG There seems to be a bug where if (and even if?) dahdi_span_assignments auto is not run
685
+ # (even if we're manually assigning spans), dahdi_genconf will just hang.
686
+ # We can kill it and all the gubbins DAHDI spawns with "pkill dahdi",
687
+ # and then things seem to work.
688
+ if [ -f /etc/dahdi/system.conf ]; then
689
+ # Per the BUGBUG note above: If dahdi_genconf is still running after 2 seconds, kill it and proceed. Don't ask me to explain it, but it works...
690
+ DAHDI_CONF_FILE=/tmp/system.conf dahdi_genconf system & (sleep 2; ps -aux | grep " dahdi_genconf" | grep -v " grep" > /dev/null && pkill dahdi && echoerr " Forcibly killed dahdi_genconf" )
691
+ # The second time around, it SHOULD work instantly and properly dump dahdi_genconf output into /tmp/system.conf
692
+ DAHDI_CONF_FILE=/tmp/system.conf dahdi_genconf system & (sleep 2; ps -aux | grep " dahdi_genconf" | grep -v " grep" > /dev/null && pkill dahdi && echoerr " Forcibly killed dahdi_genconf a second time???" )
693
+ # This will show us what's different between the system.conf dahdi_genconf just wrote to /tmp/system.conf
694
+ # and the actual /etc/dahdi/system.conf
695
+ # There are likely to be a few changes, but there shouldn't be anything major if everything went well.
696
+ # If there's a big deviation, then manual intervention is likely required.
697
+ diff -U 0 /etc/dahdi/system.conf /tmp/system.conf # Output with no context, since basically every line is unique already
698
+ else
699
+ dahdi_genconf -vvvvv
700
+ fi
701
+
702
+ # Finally, run dahdi_cfg
703
+ printf " Applying DAHDI channel configuration...\n"
704
+ dahdi_cfg -v 2> /dev/null | grep " to configure" # Show number of channels that will be configured
675
705
if [ $? -ne 0 ]; then
676
706
lsdahdi
677
707
die " DAHDI initialization failed... check to ensure all your spans are online and in the expected order"
678
708
fi
679
- # Asterisk likely starts automatically, but reload anything DAHDI related
680
- service asterisk start
681
- /sbin/rasterisk -x " module refresh chan_dahdi"
682
- printf " Telephony initialization completed\n"
709
+ printf " DAHDI channel configuration applied successfully!\n"
710
+
711
+ # Finally, make sure the DAHDI service is running so that systemd can keep track of it...
712
+ service dahdi start
713
+
714
+ service asterisk start # Start Asterisk if it's not running already
715
+ /sbin/rasterisk -x " module load chan_dahdi" # Load chan_dahdi if Asterisk was already running
716
+ /sbin/rasterisk -x " dahdi show channels" # The ultimate test is what DAHDI channels actually show up in Asterisk
717
+ echog " Telephony initialization completed"
683
718
}
684
719
685
720
assert_root () {
@@ -1482,6 +1517,9 @@ install_dahdi() {
1482
1517
phreak_fuzzy_patch " dahdi_kern_61.diff"
1483
1518
fi
1484
1519
1520
+ # Merged in master, but not yet in a current release
1521
+ git_custom_patch " https://github.com/asterisk/dahdi-linux/commit/d932d9fbc8b3559829a76fffcedceb78d1fc1887.diff"
1522
+
1485
1523
KERN_VER_MM=$( uname -r | cut -d. -f1-2 )
1486
1524
OS_DIST_2=$( printf " $OS_DIST_INFO " | cut -d' ' -f1-2)
1487
1525
if [ " $KERN_VER_MM " = " 4.18" ] && [ " $OS_DIST_2 " = " Rocky Linux" ]; then
@@ -2695,7 +2733,7 @@ elif [ "$cmd" = "make" ]; then
2695
2733
# phreaknet install
2696
2734
2697
2735
assert_root
2698
- ln $FILE_PATH /usr/local/sbin/phreaknet
2736
+ ln -nsf $FILE_PATH /usr/local/sbin/phreaknet
2699
2737
if [ $? -eq 0 ]; then
2700
2738
echo " PhreakScript added to path."
2701
2739
else
@@ -3710,6 +3748,9 @@ elif [ "$cmd" = "start" ]; then
3710
3748
start_telephony
3711
3749
elif [ " $cmd " = " edit" ]; then
3712
3750
exec nano $FILE_PATH
3751
+ elif [ " $cmd " = " touch" ]; then
3752
+ printf " %s: " " $FILE_PATH "
3753
+ date -r $FILE_PATH
3713
3754
elif [ " $cmd " = " validate" ]; then
3714
3755
run_rules
3715
3756
elif [ " $cmd " = " trace" ]; then
0 commit comments