-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
phreaknet.sh
executable file
·4530 lines (4274 loc) · 193 KB
/
phreaknet.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# PhreakScript
# (C) 2021-2024 Naveen Albert, PhreakNet, and others - https://github.com/InterLinked1/phreakscript ; https://portal.phreaknet.org ; https://docs.phreaknet.org
# v1.2.0 (2024-11-03)
# Setup (as root):
# cd /usr/local/src
# wget https://raw.githubusercontent.com/InterLinked1/phreakscript/master/phreaknet.sh
# chmod +x phreaknet.sh
# ./phreaknet.sh make
# phreaknet update
# phreaknet install
## Begin Change Log:
# 2024-11-03 1.2.0 Asterisk: Install Asterisk 22 by default
# 2024-10-16 1.1.8 wanpipe: Installation procedure improvements
# 2024-09-19 1.1.7 DAHDI: Slipstream critical build fixes, fix build issues on various distros and kernels
# 2024-09-16 1.1.6 DAHDI: Add patch to enable building of XPP drivers on 32-bit architectures
# 2024-09-15 1.1.5 DAHDI: Massive overhaul to DAHDI stop/start/restart logic, fixes for manual span assignment
# 2024-09-11 1.1.4 DAHDI: Target DAHDI 3.4.0, update patches
# 2024-03-17 1.1.3 DAHDI: Only build wanpipe if requested
# 2024-03-09 1.1.2 Asterisk: fix broken patches that no longer applied
# 2024-01-12 1.1.1 Asterisk: target Asterisk 21.1.0-rc1, fix 'phreaknet restart' command
# 2023-10-26 1.1.0 Asterisk/DAHDI: target Asterisk 21, DAHDI 3.3.0-rc1
# 2023-09-27 1.0.5 DAHDI: restore tor2 and pciradio drivers, PhreakScript: pull update script from GitHub
# 2023-09-16 1.0.4 DAHDI: Fix DAHDI driver restoral, fix wcte12xp compilation on kernels >= 5.16
# 2023-09-08 1.0.3 wanpipe: Use wanpipe 7.0.36
# 2023-08-30 1.0.2 wanpipe: Use wanpipe 7.0.35
# 2023-08-28 1.0.1 PhreakScript: remove gerrit commands
# 2023-07-27 1.0.0 Asterisk: target 20.4.0
# 2023-06-18 0.3.4 PhreakScript: add source command
# 2023-05-25 0.3.3 Asterisk: target 20.3.0
# 2023-03-16 0.3.2 Asterisk: target 20.2.0
# 2023-03-03 0.3.1 DAHDI: disable XPP drivers on all 32-bit architectures to fix build failures
# 2023-02-26 0.2.7 PhreakScript: fix install user (again)
# 2023-02-25 0.2.6 PhreakScript: fix install user
# 2023-02-13 0.2.5 Asterisk: remove merged patches
# 2023-01-28 0.2.4 PhreakScript: fix GDB installation detection
# 2023-01-17 0.2.3 DAHDI: Correct for DAHDI no longer including CONFIG_PCI and patch cdd6ddd0fd08cb8b7313b16074882439fbb58045 failing
# 2023-01-17 0.2.2 DAHDI: Correct for DAHDI no longer including CONFIG_PCI and patch 45ac6a30f922f4eef54c0120c2a537794b20cf5c failing
# 2023-01-12 0.2.1 Asterisk: target 20.1.0
# 2023-01-07 0.2.0 Asterisk: readd chan_sip support for master
# 2022-11-27 0.1.99 Asterisk/DAHDI: add app_loopdisconnect
# 2022-11-25 0.1.98 Asterisk: add unmerged patches
# 2022-11-20 0.1.97 Asterisk: update usecallmanager target
# 2022-11-16 0.1.96 Asterisk: add out of tree modules
# 2022-11-05 0.1.95 PhreakScript: add minimal external codec handling
# 2022-10-27 0.1.94 PhreakScript: add keyperms command
# 2022-10-27 0.1.93 Asterisk: add unmerged patches, PhreakScript: add threads command
# 2022-10-20 0.1.92 Asterisk: target Asterisk 20.0.0
# 2022-10-15 0.1.91 PhreakScript: add reftrace command
# 2022-09-28 0.1.90 DAHDI: remove merged DAHDI compiler fix, add libpri compiler fix
# 2022-09-16 0.1.89 Asterisk: add unmerged patches
# 2022-09-03 0.1.88 Asterisk: add unmerged patches
# 2022-09-03 0.1.87 DAHDI: Add support for Raspberry Pi
# 2022-09-02 0.1.86 Test Suite: upgraded for python3
# 2022-08-31 0.1.85 DAHDI: support kernel version mismatches
# 2022-08-25 0.1.84 PhreakScript: improved rundump
# 2022-08-06 0.1.83 PhreakScript: added version command
# 2022-07-30 0.1.82 PhreakScript: streamline prereq install
# 2022-07-29 0.1.81 DAHDI: fix wanpipe compiling, target DAHDI 3.2.0
# 2022-07-24 0.1.80 Asterisk: remove merged patches
# 2022-07-20 0.1.79 Asterisk: fix memory issue in app_signal
# 2022-07-20 0.1.78 PhreakScript: add fullpatch command
# 2022-07-11 0.1.77 PhreakScript: added package audit
# 2022-07-11 0.1.76 PhreakScript: streamline enhanced dependencies
# 2022-07-05 0.1.75 Asterisk: update usecallmanager target
# 2022-07-01 0.1.74 Asterisk: add res_irc
# 2022-07-01 0.1.73 PhreakScript: fix RSA chown
# 2022-06-26 0.1.72 PhreakScript: added wizard command
# 2022-06-23 0.1.71 Asterisk: target 18.13.0
# 2022-06-01 0.1.70 PhreakScript: fix patch conflicts
# 2022-05-17 0.1.69 Asterisk: readd hearpulsing
# 2022-05-17 0.1.68 PhreakScript: enhanced install control
# 2022-05-16 0.1.67 Asterisk: add func_query and app_callback
# 2022-05-14 0.1.66 PhreakScript: add trace notify and custom expiry
# 2022-05-12 0.1.65 Asterisk: target 18.12.0
# 2022-05-05 0.1.64 PhreakScript: enhance installation compatibility
# 2022-05-01 0.1.63 Asterisk: add app_predial
# 2022-04-26 0.1.62 PhreakScript: add restart command
# 2022-04-25 0.1.61 PhreakScript: remove antipatterns
# 2022-04-24 0.1.60 DAHDI: add critical DAHDI Tools fix
# 2022-04-07 0.1.59 PhreakScript: improved odbc installation
# 2022-04-07 0.1.58 PhreakScript: add autocompletion integration
# 2022-04-05 0.1.57 PhreakScript: added res_dialpulse, misc. fixes
# 2022-04-03 0.1.56 PhreakScript: move boilerplate configs to GitHub
# 2022-04-03 0.1.55 Asterisk: add app_selective
# 2022-04-01 0.1.54 PhreakScript: warn about updates only if behind master
# 2022-04-01 0.1.53 PhreakScript: allow standalone DAHDI install
# 2022-03-27 0.1.52 PhreakScript: added dialplanfiles
# 2022-03-25 0.1.51 PhreakScript: add fail2ban
# 2022-03-25 0.1.50 PhreakScript: add paste_post error handling
# 2022-03-20 0.1.49 Asterisk: add func_dtmf_flash
# 2022-03-17 0.1.48 PhreakScript: added swap commands
# 2022-03-11 0.1.47 DAHDI: fix compiler error in DAHDI Tools
# 2022-03-06 0.1.46 Asterisk: added app_featureprocess
# 2022-03-05 0.1.45 PhreakScript: added cppcheck
# 2022-03-04 0.1.44 PhreakScript: add apiban
# 2022-03-01 0.1.43 Asterisk: update Call Manager to 18.10
# 2022-02-25 0.1.42 Asterisk: Fix xmldocs bug with SET MUSIC AGI
# 2022-02-23 0.1.41 PhreakScript: add out-of-tree tests for app_assert
# 2022-02-23 0.1.40 PhreakScript: minor test suite fixes
# 2022-02-23 0.1.39 PhreakScript: minor refactoring
# 2022-02-11 0.1.38 Asterisk: refined freepbx support
# 2022-02-10 0.1.37 Asterisk: target 18.10.0
# 2022-02-05 0.1.36 Asterisk: add hearpulsing to DAHDI
# 2022-02-03 0.1.35 PhreakScript: added preliminary freepbx flag
# 2022-01-27 0.1.34 PhreakScript: added master branch install option
# 2022-01-22 0.1.33 Asterisk: removed func_frameintercept
# 2022-01-19 0.1.32 Asterisk: add app_playdigits
# 2022-01-18 0.1.31 Asterisk: Temper SRTCP warnings
# 2022-01-10 0.1.30 Asterisk: add res_coindetect
# 2022-01-08 0.1.29 Asterisk: add app_randomplayback
# 2022-01-07 0.1.28 Asterisk: add app_pulsar
# 2022-01-04 0.1.27 Asterisk: add app_saytelnumber
# 2022-01-01 0.1.26 PhreakScript: removed hardcoded paths
# 2021-12-31 0.1.25 PhreakScript: added ulaw command, Asterisk: added func_frameintercept, app_fsk
# 2021-12-27 0.1.24 PhreakScript: add tests for func_dbchan
# 2021-12-26 0.1.23 PhreakScript: added Asterisk build info to trace, Asterisk: added app_loopplayback, func_numpeer
# 2021-12-24 0.1.22 PhreakScript: fix path issues, remove upgrade command
# 2021-12-20 0.1.21 Asterisk: update target usecallmanager
# 2021-12-17 0.1.20 PhreakScript: add tests for verify, added backtrace enable
# 2021-12-16 0.1.19 PhreakScript: added support for building chan_sip with Cisco Call Manager phone support
# 2021-12-15 0.1.18 PhreakScript: added runtests, Asterisk: update func_evalexten
# 2021-12-14 0.1.17 Asterisk: update func_evalexten, PhreakScript: added gerrit command
# 2021-12-13 0.1.16 Asterisk: patch updates, compiler fixes
# 2021-12-12 0.1.15 Asterisk: add ReceiveText application
# 2021-12-12 0.1.14 Asterisk: add app_verify, PhreakScript: fix double compiling with test framework
# 2021-12-11 0.1.13 PhreakScript: update backtrace
# 2021-12-09 0.1.12 Asterisk: updates to target 18.9.0
# 2021-12-05 0.1.11 PhreakScript: allow overriding installed version
# 2021-12-04 0.1.10 Asterisk Test Suite: added sipp installation, bug fixes to PhreakScript directory check
# 2021-11-30 0.1.9 Asterisk: add chan_sccp channel driver
# 2021-11-29 0.1.8 PhreakScript: fix trace bugs and add error checking
# 2021-11-26 0.1.7 PhreakScript: added docgen
# 2021-11-26 0.1.6 Asterisk: app_tdd (Bug Fix): added patch to fix compiler warnings, decrease buffer threshold
# 2021-11-25 0.1.5 PhreakScript: removed unnecessary file deletion in dev mode
# 2021-11-25 0.1.4 PhreakScript: changed upstream for app_softmodem
# 2021-11-24 0.1.3 PhreakScript: refactored out-of-tree module code and sources
# 2021-11-14 0.1.2 Asterisk: chan_sip (New Feature): Add fax control using FAX_DETECT_SECONDS and FAX_DETECT_OFF variables, PhreakScript: path improvements
# 2021-11-12 0.1.1 PhreakScript: (PHREAKSCRIPT-1) fixed infinite loop with --help argument
# 2021-11-09 0.1.0 PhreakScript: changed make to use hard link instead of alias, FreeBSD linking fixes
# 2021-11-09 0.0.54 PhreakScript: lots and lots of POSIX compatibility fixes, added info command, flag test option
# 2021-11-08 0.0.53 PhreakScript: fixed realpath for POSIX compliance
# 2021-11-08 0.0.52 PhreakScript: POSIX compatibility fixes for phreaknet validate
# 2021-11-08 0.0.51 PhreakScript: compatibility changes to make POSIX compliant
# 2021-11-07 0.0.50 PhreakScript: added app_dialtone
# 2021-11-06 0.0.49 PhreakScript: added debug to trace
# 2021-11-03 0.0.48 PhreakScript: added basic dialplan validation
# 2021-11-02 0.0.47 PhreakScript: switched upstream Asterisk to 18.8.0
# 2021-11-01 0.0.46 PhreakScript: added boilerplate asterisk.conf
# 2021-10-30 0.0.45 PhreakScript: add IAX2 dynamic RSA outdialing
# 2021-10-25 0.0.44 PhreakScript: bug fixes to compiler options for menuselect, temp. bug fix for app_read and addition of func_json
# 2021-10-24 0.0.43 PhreakScript: temporarily added app_assert and sig_analog compiler fix
# 2021-10-16 0.0.42 PhreakScript: Added preliminary pubdocs command for Wiki-format documentation generation
# 2021-10-15 0.0.41 PhreakScript: remove chan_iax2 RSA patch (available upstream in 18.8.0-rc1)
# 2021-10-14 0.0.40 PhreakScript: Added GitHub integration
# 2021-10-14 0.0.39 Asterisk: change upstream Asterisk from 18.7 to 18.8.0-rc1, remove custom patches for logger, app_queue, CHANNEL_EXISTS, func_vmcount, app_mf (available upstream in 18.8.0-rc1)
# 2021-10-14 0.0.38 PhreakScript: Added update protection (against corrupted upstream) and ability to set custom upstream source for PhreakScript
# 2021-10-12 0.0.37 Asterisk: Pat Fleet sounds, boilerplate audio files, pulsar AGI
# 2021-10-12 0.0.34 DAHDI: Changed upstream from master to next branch by manually incorporating these patches
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29681): chan_sip (New Feature): Add SIPAddParameter application and SIP_PARAMETER function
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29496): app_mf (New Feature): Add SendMF application and PlayMF AMI action
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29661): func_vmcount (Improvement): Add support for multiple mailboxes
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29656): func_channel (New Feature): Add CHANNEL_EXISTS function
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29578): app_queue (Bug Fix): Fix hints for included contexts
# 2021-10-08 0.0.2 Asterisk (ASTERISK-29529): logger (Improvement): Add custom logging
# 2021-10-07 0.0.1 Asterisk: app_tdd (New Feature): Add TddRx/TddTx applications and AMI events
# 2021-10-07 0.0.1 Asterisk: app_softmodem (New Feature): Add Softmodem application (will eventually be removed and replaced with a new module) # TODO
# 2021-10-07 0.0.1 Asterisk: func_dbchan (New Feature): Add DB_CHAN, DB_PRUNE functions
# 2021-10-07 0.0.1 Asterisk: app_tonetest (New Feature): Add ToneSweep application
# 2021-10-07 0.0.1 Asterisk: app_streamsilence (New Feature): Add StreamSilence application
# 2021-10-07 0.0.1 Asterisk: app_frame (New Feature): Add SendFrame application
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29486): func_evalexten (New Feature): Add EVAL_EXTEN function
# 2021-10-07 0.0.1 Asterisk: app_memory (New Feature): Add MallocTrim application
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29489): app_mail (New Feature): Add SendMail application
# 2021-10-07 0.0.1 Asterisk: func_notchfilter (New Feature): Add NOTCH_FILTER function
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29432): func_ochannel (New Feature): Add OTHER_CHANNEL function
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29497): app_if (New Feature): Add If, EndIf, ExitIf applications
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29428): app_dial (Bug Fix): prevent infinite loop from hanging calls when Dial D option used with progress
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29455): translate.c (Bug Fix): prevent translator from choosing gsm to ulaw, all else equal
# 2021-10-07 0.0.1 Asterisk (ASTERISK-29493): app_stack (New Feature): Add ReturnIf application
# 2021-10-07 0.0.1 Asterisk (ASTERISK-20219): chan_iax2 (Improvement): Add encryption to RSA authentication (merged as of Oct. 2021, patch will be removed soon)
## End Change Log
# User environment variables
AST_CONFIG_DIR="/etc/asterisk"
AST_VARLIB_DIR="/var/lib/asterisk"
AST_SOURCE_PARENT_DIR="/usr/src"
# Script environment variables
AST_ALT_VER=""
AST_MIN_PREFERRED_VER=20
AST_DEFAULT_MAJOR_VER=22
AST_NEXT_MAJOR_VER=23
AST_MAJOR_VER=$AST_DEFAULT_MAJOR_VER
AST_MM_VER=0
AST_SOURCE_NAME="asterisk-${AST_DEFAULT_MAJOR_VER}-current"
AST_RC_SOURCE_NAME="asterisk-${AST_DEFAULT_MAJOR_VER}-testing"
# DAHDI_MM_VER="${DAHDI_VERSION:0:1}${DAHDI_VERSION:2:1}" Requires bash
DAHDI_MM_VER=34
DAHDI_VERSION="3.4.0"
#DAHLIN_SRC_URL="https://github.com/asterisk/dahdi-linux/releases/download/v${DAHDI_VERSION}/${DAHLIN_SRC_NAME}"
#DAHTOOL_SRC_URL="https://github.com/asterisk/dahdi-tools/releases/download/v${DAHDI_VERSION}/${DAHTOOL_SRC_NAME}"
DAHLIN_SRC_NAME="dahdi-linux-current.tar.gz"
DAHTOOL_SRC_NAME="dahdi-tools-current.tar.gz"
DAHLIN_SRC_URL="http://downloads.asterisk.org/pub/telephony/dahdi-linux/dahdi-linux-current.tar.gz"
DAHTOOL_SRC_URL="http://downloads.asterisk.org/pub/telephony/dahdi-tools/dahdi-tools-current.tar.gz"
LIBPRI_SOURCE_NAME="libpri-1.6.1"
LIBSS7_VERSION="2.0.1"
WANPIPE_SOURCE_NAME="wanpipe-current" # wanpipe-latest (7.0.38, 2024-02-05)
ODBC_VER="3.1.14"
CISCO_CM_SIP="cisco-usecallmanager-20.10.0"
MIN_ARGS=1
FILE_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
FILE_NAME=$( basename $0 ) # grr... why is realpath not in the POSIX standard?
FILE_PATH="$FILE_DIR/$FILE_NAME"
PATCH_DIR=https://docs.phreaknet.org/script
OS=$(uname -s)
OS_DIST_INFO="(lsb_release -ds || cat /etc/*release || uname -om ) 2>/dev/null | head -n1 | cut -d'=' -f2"
OS_DIST_INFO=$(eval "$OS_DIST_INFO" | tr -d '"')
PAC_MAN="apt-get"
AST_SOUNDS_DIR="$AST_VARLIB_DIR/sounds/en"
AST_MOH_DIR="$AST_VARLIB_DIR/moh"
AST_MAKE="make"
WGET="wget -q"
XMLSTARLET="/usr/bin/xmlstarlet"
PATH="/sbin:$PATH" # in case su used without path
# Defaults
AST_CC=1 # Country Code (default: 1 - NANPA)
AST_USER=""
EXTRA_FEATURES=1
ALSA=0
WEAK_TLS=0
CHAN_SIP=0
ENHANCED_CHAN_SIP=0
SIP_CISCO=0
CHAN_SCCP=0
CHAN_DAHDI=0
DAHDI_OLD_DRIVERS=0
EMPULSE=1 # Automatically enable EMPULSE, cause why not?
DAHDI_WANPIPE=0 # wanpipe only needed for Sangoma cards
DEVMODE=0
TEST_SUITE=0
FORCE_INSTALL=0
IGNORE_FAILURES=0
ENHANCED_INSTALL=1
PREFER_RELEASE_CANDIDATES=1
EXPERIMENTAL_FEATURES=0
LIGHTWEIGHT=0
FAST_COMPILE=0
PKG_AUDIT=0
MANUAL_MENUSELECT=0
ENABLE_BACKTRACES=0
ASTKEYGEN=0
DEFAULT_PATCH_DIR="/tmp" # for new patches
PHREAKNET_CLLI=""
INTERLINKED_APIKEY=""
BOILERPLATE_SOUNDS=0
SCRIPT_UPSTREAM="$PATCH_DIR/phreaknet.sh"
DEBUG_LEVEL=0
FREEPBX_GUI=0
GENERIC_HEADERS=0
EXTERNAL_CODECS=0
RTPULSING=1
HEARPULSING=1
HAVE_COMPATIBLE_SPANDSP=1
PACMAN_UPDATED=0 # Internal flag
handler() {
kill $BGPID
}
# FreeBSD doesn't support this escaping, so just do a simple print.
echog() {
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
printf "%s\n" "$*" >&2;
else
printf "\e[32;1m%s\e[0m\n" "$*" >&2;
fi
}
echoerr() { # https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
printf "%s\n" "$*" >&2;
else
printf "\e[31;1m%s\e[0m\n" "$*" >&2;
fi
}
die() {
echoerr "$1"
exit 1
}
if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' -a "$OS" != 'DragonFly' ]; then
die "Your OS ($OS) is definitely not supported... aborting."
fi
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
PAC_MAN="pkg"
AST_SOURCE_PARENT_DIR="/usr/local/src"
AST_CONFIG_DIR="/usr/local/etc/asterisk"
AST_MAKE="gmake"
XMLSTARLET="/usr/local/bin/xml"
elif [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
PAC_MAN="yum"
elif [ -f /etc/redhat-release ]; then
PAC_MAN="yum"
elif [ "$OS_DIST_INFO" = "SLES" ]; then
PAC_MAN="zypper"
elif [ "$OS_DIST_INFO" = "openSUSE Tumbleweed" ]; then
PAC_MAN="zypper"
elif [ -r /etc/arch-release ]; then
PAC_MAN="pacman"
elif [ ! -f /etc/debian_version ]; then # Default is Debian
echoerr "Support for this platform ($OS_DIST_INFO) is limited... use at your own risk..."
# Try to automatically detect the right package manager, at least...
if ! which "yum" > /dev/null; then
PAC_MAN="yum"
elif ! which "dnf" > /dev/null; then
PAC_MAN="dnf"
elif ! which "pkg" > /dev/null; then
PAC_MAN="pkg"
AST_SOURCE_PARENT_DIR="/usr/local/src"
elif which "apt-get" > /dev/null; then # apt-get is default, so check last
echoerr "Failed to automatically determine your package manager... script will likely fail"
fi
fi
update_packages() {
printf "Updating package manager...\n"
PACMAN_UPDATED=1
if [ "$PAC_MAN" = "apt-get" ]; then
if [ $PACMAN_UPDATED = 0 ]; then
# Ubuntu 22.04 prompts for restarts by default, inhibit this: https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services
if [ -f /etc/needrestart/needrestart.conf ]; then
sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf
fi
if [ -f /var/cache/apt/pkgcache.bin ] && [ "$FORCE_INSTALL" != "1" ]; then
echo $(( ($(date +%s) - $(stat /var/cache/apt/pkgcache.bin -c %Y)) ))
if [ $(( ($(date +%s) - $(stat /var/cache/apt/pkgcache.bin -c %Y)) )) -lt 300 ]; then # within last 5 minutes
printf "Package updates occured recently, skipping...\n"
return
fi
fi
fi
apt-get update -y
apt-get upgrade -y
elif [ "$PAC_MAN" = "yum" ]; then
yum update -y
elif [ "$PAC_MAN" = "zypper" ]; then
zypper update -y
elif [ "$PAC_MAN" = "pacman" ]; then
pacman -Syu --noconfirm
elif [ "$PAC_MAN" = "pkg" ]; then
pkg install -y
pkg upgrade -y
fi
}
install_package() {
if [ $PACMAN_UPDATED -eq 0 ]; then
update_packages
fi
echo "Installing package(s): " $1 # unquoted, to trim any leading whitespace
if [ "$PAC_MAN" = "apt-get" ]; then
apt-get install -y $1
elif [ "$PAC_MAN" = "yum" ]; then
yum install -y $1
elif [ "$PAC_MAN" = "zypper" ]; then
zypper install -y $1
elif [ "$PAC_MAN" = "pacman" ]; then
pacman -Sy --noconfirm $1
elif [ "$PAC_MAN" = "pkg" ]; then
pkg install -y $1
else
echoerr "Not sure how to satisfy requirement: $1"
fi
if [ $? -ne 0 ]; then
echoerr "Package installation failed: $1"
fi
}
# If which is not installed, get that before anything
if ! which "which" > /dev/null; then
printf "which does not appear to be present... installing...\n"
if [ "$PAC_MAN" = "apt-get" ]; then
install_package "debianutils"
elif [ "$PAC_MAN" = "yum" ]; then
install_package "which"
elif [ "$PAC_MAN" = "pacman" ]; then
install_package "which"
fi
if ! which "which" > /dev/null; then
echoerr "which is still not installed?"
fi
fi
ensure_installed() {
if ! which "$1" > /dev/null; then
install_package "$1"
fi
}
# Now that packages are detected, install wget if necessary
ensure_installed "wget"
# Wget2 does not support --show-progress, uses --force-progress instead
WGET_VERSION=$( wget --version | head -n 1 )
if [ "${WGET_VERSION#*"Wget2"}" != "$WGET_VERSION" ]; then
WGET="$WGET --force-progress"
else
WGET="$WGET --show-progress"
fi
if [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
WGET="wget -q" # --show-progress not supported by yum/Sangoma Linux?
fi
# If getopt is not present, install it
if ! which "getopt" > /dev/null; then
install_package "util-linux" # named the same in most every distro
fi
ensure_installed "hostname"
phreakscript_info() {
printf "%s" "Hostname: "
hostname
printf "OS: %s\n" "$OS"
printf "Dist Info: "
echo $OS_DIST_INFO
uname -a
echo "Package Manager: $PAC_MAN"
echo "wget version: $WGET_VERSION"
gcc -v 2>&1 | grep "gcc version"
asterisk -V 2> /dev/null # Asterisk might or might not exist...
if [ -d /etc/dahdi ]; then
dahdi_cfg -tv 2>&1 | grep "ersion"
fi
printf "%s" "PhreakScript "
grep "# v" $FILE_PATH | head -1 | cut -d'v' -f2
echo "https://github.com/InterLinked1/phreakscript"
echo "(C) 2021-2024 PhreakNet - https://portal.phreaknet.org https://docs.phreaknet.org"
echo "To report bugs or request feature additions, please report at https://issues.interlinked.us (also see https://docs.phreaknet.org/#contributions) and/or post to the PhreakNet mailing list: https://groups.io/g/phreaknet" | fold -s -w 120
}
if [ "$1" = "commandlist" ]; then
echo "about help version examples info wizard make man mancached install source experimental dahdi odbc installts fail2ban apiban freepbx pulsar sounds boilerplate-sounds ulaw remsil uninstall uninstall-all bconfig config keygen keyperms update astpr patch genpatch alembic freedisk topdir topdisk enable-swap disable-swap start restart stop kill forcerestart ban applist funclist dialplanfiles validate trace paste iaxping pcap pcaps sngrep enable-backtraces backtrace backtrace-only rundump threads reftrace valgrind cppcheck docverify runtests runtest stresstest ccache fullpatch docgen mkdocs pubdocs edit"
exit 0
fi
usage() {
#complete -W "make help install installts pulsar sounds config keygen edit genpatch patch update upgrade trace backtrace" phreaknet # has to be manually entered, at present
#source ~/.bash_profile
echo "Usage: phreaknet [command] [options]
Commands:
*** Getting Started ***
about About PhreakScript
help Program usage
version Program version
examples Example usages
info System info
wizard Interactive installation command wizard
*** First Use / Installation ***
make Add PhreakScript to path
man Compile and install PhreakScript man page
mancached Install cached man page (may be outdated)
install Install or upgrade PhreakNet-enhanced Asterisk
source Prepare PhreakNet-enhanced Asterisk source code only
experimental Add experimental features to an existing Asterisk source
dahdi Install or upgrade PhreakNet-enhanced DAHDI
wanpipe Install wanpipe
odbc Install ODBC (MariaDB)
installts Install Asterisk Test Suite
fail2ban Install Asterisk fail2ban configuration
apiban Install apiban client
freepbx Install FreePBX GUI (not recommended)
pulsar Install Revertive Pulsing simulator
sounds Install Pat Fleet sound library
boilerplate-sounds Install boilerplate sounds only
ulaw Convert wav to ulaw (specific file or all in current directory)
remsil Remove silence from file(s)
uninstall Uninstall Asterisk, but leave configuration behind
uninstall-all Uninstall Asterisk, and completely remove all traces of it (configs, etc.)
*** Initial Configuration ***
bconfig Install PhreakNet boilerplate config
config Install PhreakNet boilerplate config and autoconfigure PhreakNet variables
keygen Install and update PhreakNet RSA keys
keyperms Ensure that TLS keys are readable
*** Maintenance ***
update Update PhreakScript
astpr Apply an Asterisk PR patch
patch Patch PhreakNet Asterisk configuration
genpatch Generate a PhreakPatch
alembic Generate an Asterisk Alembic revision
freedisk Free up disk space
topdir Show largest directories in current directory
topdisk Show top files taking up disk space
enable-swap Temporarily allocate and enable swap file
disable-swap Disable and deallocate temporary swap file
start Fully start DAHDI, wanpipe, and Asterisk
restart Fully restart DAHDI, wanpipe, and Asterisk
stop Fully stop DAHDI, wanpipe, and Asterisk
kill Forcibly kill Asterisk
forcerestart Forcibly restart Asterisk
ban Manually ban an IP address using iptables
*** Debugging ***
dialplanfiles Verify what files are being parsed into the dialplan
validate Run dialplan validation and diagnostics and look for problems
trace Capture a CLI trace and upload to InterLinked Paste
paste Upload an arbitrary existing file to InterLinked Paste
iaxping Check if a remote IAX2 listener is reachable
pcap Perform a packet capture, optionally against a specific IP address
pcaps Same as pcap, but open in sngrep afterwards
sngrep Perform SIP message debugging
enable-backtraces Enables backtraces to be extracted from the core dumper (new or existing installs)
backtrace Use astcoredumper to process a backtrace and upload to InterLinked Paste
backtrace-only Use astcoredumper to process a backtrace
rundump Get a backtrace from the running Asterisk process
threads Get information about current Asterisk threads
reftrace Process reference count logs
*** Developer Debugging ***
valgrind Run Asterisk under valgrind
cppcheck Run cppcheck on Asterisk for static code analysis
*** Development & Testing ***
docverify Show documentation validation errors and details
runtests Run differential PhreakNet tests
runtest Run any specified test (argument to command)
stresstest Run any specified test multiple times in a row
fullpatch Redownload an entire PhreakNet source file
ccache Globally install ccache to speed up recompilation
*** Miscellaneous ***
docgen Generate Asterisk user documentation, using astdocgen (deprecated)
mkdocs Generate Asterisk user documentation, using Asterisk documentation generator
pubdocs Generate Asterisk user documentation (deprecated)
applist List Asterisk dialplan applications in current source
funclist List Asterisk dialplan functions in current source
edit Edit PhreakScript
touch Show PhreakScript file path and last modification
Options:
-b, --backtraces Enables getting backtraces
-c, --cc Country Code (default is 1)
-d, --dahdi Install DAHDI
-f, --force Force install or config
-h, --help Display usage
-n, --no-rc Do not install release candidate versions
-o, --flag-test Option flag test
-s, --sip Install chan_sip instead of or in addition to chan_pjsip
-t, --testsuite Compile with developer support for Asterisk test suite and unit tests
-u, --user User as which to run Asterisk (non-root)
-v, --version Specific version of Asterisk to install (M.m.b e.g. 18.8.0). Also, see --vanilla.
-w, --weaktls Allow less secure TLS versions down to TLS 1.0 (default is 1.2+)
--api-key config: InterLinked API key
--clli config: CLLI code
--disa config: DISA number
--rotate keygen: Rotate/create keys
--upstream update: Specify upstream source
--debug trace: Debug level (default is 0/OFF, max is 10)
--boilerplate sounds: Also install boilerplate sounds
--audit install: Audit package installation
--devmode install: Compile with devmode enabled
--experimental install: Install experimental features that may not be production ready
--fast install: Compile as fast as possible
--lightweight install: Only install basic, required modules for basic Asterisk functionality
--alsa install: Ensure ALSA library detection exists in the build system. This does NOT readd the deprecated/removed chan_alsa module.
--cisco install: Add full support for Cisco Call Manager phones (chan_sip only)
--sccp install: Install chan_sccp channel driver (Cisco Skinny)
--drivers install: Also install DAHDI drivers removed in 2018
--generic install: Use generic kernel headers that do not match the installed kernel version
--extcodecs install: Specify this if any external codecs are being or will be installed
--freepbx install: Install FreePBX GUI (not recommended)
--manselect install: Manually run menuselect yourself
--minimal install: Do not upgrade the kernel or install nonrequired dependencies (such as utilities that may be useful on typical Asterisk servers)
--vanilla install: Do not install extra features or enhancements. Bug fixes are always installed. (May be required for older versions)
"
phreakscript_info
exit 2
}
get_newest_astdir() {
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
ls -d ./*/ | cut -c 3- | grep "^asterisk" | tail -1 # FreeBSD doesn't have the same GNU ls options: https://stackoverflow.com/a/31603260/
else
ls -d -v */ | grep "^asterisk" | tail -1
fi
}
cd_ast() {
cd $AST_SOURCE_PARENT_DIR
AST_SRC_DIR=`get_newest_astdir`
cd $AST_SRC_DIR
}
ast_kill() {
pid=`cat /var/run/asterisk/asterisk.pid`
if [ ${#pid} -eq 0 ]; then
echoerr "Asterisk is not currently running."
elif ! kill -9 $pid; then
echoerr "Failed to stop Asterisk ($pid)"
else
echog "Successfully killed Asterisk ($pid)"
fi
}
start_wanpipe() {
if which wanrouter > /dev/null; then
printf "Starting wanpipe\n"
service wanrouter start
if [ $? -ne 0 ]; then
wanrouter start
fi
wanrouter status
fi
}
stop_wanpipe() {
if which wanrouter > /dev/null; then
service wanrouter status
if [ $? -eq 0 ]; then
printf "Stopping wanpipe spans\n"
if ! wanrouter stop all; then # stop all T1 spans on wanpipe
die "Failed to stop wanpipe spans"
elif ! service wanrouter stop; then # stop wanpipe service
die "Failed to stop wanrouter"
elif ! modprobe -r dahdi_echocan_mg2; then # remove DAHDI echocan
die "Failed to remove DAHDI echocan"
fi
else
wanrouter status
if [ $? -eq 0 ]; then
printf "Unsure if wanpipe is in use, stopping it just to be sure...\n"
wanrouter stop all
if [ $? -ne 0 ]; then
die "Failed to stop wanpipe, aborting to prevent potential system crash - please manually stop wanpipe and rerun"
fi
fi
fi
wanrouter status | grep "stopped"
if [ $? -ne 0 ]; then
die "Could not verify wanpipe is really stopped... to prevent system instability, please manually stop it and rerun"
fi
else
printf "wanpipe not present on this system, no need to stop it\n"
fi
}
stop_telephony() {
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
if [ "$astpid" != "" ]; then
if [ "$1" = "1" ]; then
# Only need to unload chan_dahdi if it's loaded
rasterisk -x "module show like chan_dahdi" | grep "chan_dahdi"
if [ $? -eq 0 ]; then
rasterisk -x "module unload chan_dahdi" | grep "Unloaded chan_dahdi"
if [ $? -ne 0 ]; then
die "chan_dahdi could not be unloaded"
fi
fi
else
service asterisk stop # stop Asterisk
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
if [ "$astpid" != "" ]; then
# if that didn't work, kill it manually
kill -9 $astpid
printf "Killed Asterisk process %s\n" "$astpid"
else
printf "Asterisk not currently running...\n"
fi
fi
else
printf "Asterisk not currently running...\n"
fi
lsmod | grep dahdi
curdrivers=`lsmod | grep "dahdi " | xargs | cut -d' ' -f4-` # Space intentionally included, add dahdi_vpmadt032_loader later manually
printf "Current drivers: --- %s ---\n", "$curdrivers"
stop_wanpipe
echo "$curdrivers" | tr ',' '\n' | xargs -i sh -c 'echo Stopping driver: {}; modprobe -r {}'
modprobe -r dahdi_vpmadt032_loader
modprobe -r dahdi_voicebus
service dahdi status
# WARNING WARNING WARNING
# It seems that on a system where wanpipe is in use,
# stopping DAHDI without ensuring wanpipe is really stopped
# will lead to the system crashing
# Noticed this since wanpipe wasn't registered as a service,
# so "service wanpipe status" wouldn't work, even though wanpipe was installed.
# This is why there are now checks above to ensure wanrouter is stopped before stopping DAHDI.
# Also noted here: https://sangomakb.atlassian.net/wiki/spaces/TC/pages/53772451/Driver+Debugging
if [ $? -eq 0 ]; then
printf "Stopping DAHDI...\n"
if ! service dahdi stop; then
printf "Returned %d\n" $?
die "Failed to stop DAHDI"
elif ! modprobe -r dahdi; then
die "Failed to remove DAHDI from kernel"
elif ! service dahdi stop; then # do it again, just to be sure
die "Failed to stop DAHDI the second time"
fi
printf "DAHDI shutdown complete\n"
else
printf "DAHDI is not running, skipping...\n"
modprobe -r dahdi # In case the service was already stopped but dahdi module was not yet unloaded
fi
}
# Completely restart wanpipe, DAHDI (and any DAHDI drivers), and Asterisk
# This is surprisingly complicated, and can be dangerous if done incorrectly
# $1 to restart without completely restarting Asterisk
restart_telephony() {
stop_telephony "$1"
start_telephony
}
# Mainly intended to start the telephony drivers on bootup, since this doesn't always happen automatically
start_telephony() {
if [ ! -f /etc/udev/rules.d/dahdi.rules ]; then
echoerr "DAHDI udev rules are missing..."
fi
modprobe --first-time dahdi
if [ $? -ne 0 ]; then
echoerr "DAHDI is still running... stop these modules and try again"
lsmod | grep "dahdi" | xargs | cut -d' ' -f4- # No space in this grep
exit 1
fi
start_wanpipe # This can fail, if wanpipe isn't being used, and that's fine
printf "DAHDI hardware:\n"
dahdi_hardware # List DAHDI hardware. The dahdi module must first be running for this to work.
# Start drivers for any telephony cards, which is needed for span assignment
# sed: Each one ends in - or +, need to ignore that
for driver in $( dahdi_hardware | awk '{print $2}' | tr ',' '\n' | sed 's/.$//' ) ; do
printf "Starting driver: %s... " "$driver"
modprobe --first-time $driver
if [ $? -ne 0 ]; then
echoerr "\nFailed to start driver $driver"
else
printf "started!\n"
fi
done
# Dump detected configuration since span stuff is VERY fickle and prone to breakage
printf "DAHDI module options: "
cat /etc/modprobe.d/dahdi.conf # Dump DAHDI module options
AUTO_ASSIGN_SPANS=$( cat /sys/module/dahdi/parameters/auto_assign_spans | tr -d '\n' )
printf "DAHDI span auto-assignment: %d\n" "$AUTO_ASSIGN_SPANS"
printf "Detected spans:\n"
dahdi_span_assignments list # List detected spans
# Get the spans assigned.
printf "Assigning DAHDI spans...\n"
dahdi_span_assignments remove
if [ "$AUTO_ASSIGN_SPANS" = "0" ]; then
printf "Manually assigning spans according to /etc/dahdi/assigned-spans.conf\n"
dahdi_span_assignments add
else
printf "Automatically assigning spans, ignoring /etc/dahdi/assigned-spans.conf\n"
num_spans=$( dahdi_span_assignments list | wc -l )
if [ $num_spans -gt 1 ]; then
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!"
echoerr "To do this, add 'options dahdi auto_assign_spans=0' to /etc/modprobe.d/dahdi.conf and run 'phreaknet restart'"
sleep 1
fi
dahdi_span_assignments auto
fi
# Run dahdi_genconf to validate that the spans are assigned properly.
# However, don't actually replace /etc/dahdi/system.conf, since that
# would overwrite span configuration and break the system setup...
# just use a temporary configuration file to catch it and compare.
printf "Generating DAHDI channel configuration and checking differences...\n"
# XXX BUGBUG There seems to be a bug where if (and even if?) dahdi_span_assignments auto is not run
# (even if we're manually assigning spans), dahdi_genconf will just hang.
# We can kill it and all the gubbins DAHDI spawns with "pkill dahdi",
# and then things seem to work.
if [ -f /etc/dahdi/system.conf ]; then
# 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...
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")
# The second time around, it SHOULD work instantly and properly dump dahdi_genconf output into /tmp/system.conf
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???")
# This will show us what's different between the system.conf dahdi_genconf just wrote to /tmp/system.conf
# and the actual /etc/dahdi/system.conf
# There are likely to be a few changes, but there shouldn't be anything major if everything went well.
# If there's a big deviation, then manual intervention is likely required.
diff -U 0 /etc/dahdi/system.conf /tmp/system.conf # Output with no context, since basically every line is unique already
else
dahdi_genconf -vvvvv
fi
# Finally, run dahdi_cfg
printf "Applying DAHDI channel configuration...\n"
dahdi_cfg -v 2>/dev/null | grep "to configure" # Show number of channels that will be configured
if [ $? -ne 0 ]; then
lsdahdi
die "DAHDI initialization failed... check to ensure all your spans are online and in the expected order"
fi
printf "DAHDI channel configuration applied successfully!\n"
# Finally, make sure the DAHDI service is running so that systemd can keep track of it...
service dahdi start
service asterisk start # Start Asterisk if it's not running already
/sbin/rasterisk -x "module load chan_dahdi" # Load chan_dahdi if Asterisk was already running
/sbin/rasterisk -x "dahdi show channels" # The ultimate test is what DAHDI channels actually show up in Asterisk
echog "Telephony initialization completed"
}
assert_root() {
if [ $(id -u) -ne 0 ]; then
echoerr "PhreakScript make must be run as root. Aborting..."
exit 2
fi
}
download_if_missing() {
if [ ! -f "$1" ]; then
wget "$2"
else
printf "Audio file already present, not overwriting: %s\n" "$1"
fi
}
make_file_readable() { # $1 = file to make readable.
bottomdir=`dirname "$1"`
realfilename=`printf '%s' "$1" | xargs | cut -d' ' -f 1`
if [ ! -f "$realfilename" ]; then
echoerr "File $realfilename does not exist"
# If the file doesn't exist, forget about it.
return
fi
newfilename=`realpath $realfilename`
if [ "${#newfilename}" -gt 0 ]; then
# If we have realpath, follow symlinks too.
if [ "$newfilename" != "$realfilename" ]; then
printf "Followed symlink from %s to %s\n" "$realfilename" "$newfilename"
realfilename="$newfilename"
fi
else
echoerr "realpath is not supported on this system"
fi
printf "chmod -R +r %s\n" "$bottomdir"
chmod -R +r "$bottomdir" # This directory should contain only keys.
cd "$bottomdir"
if [ $? -eq 0 ]; then
chmod +r "$realfilename" # Make the file itself readable.
# Make all its parent directories readable.
# FYI: Stop when we get to /etc, because if you chmod 744 /etc, you will have a VERY BAD DAY.
# If you're reading this and already having a bad day, do chmod 755 /etc and that will fix it.
# You need +x permissions to go into directories, not just read permissions.
while [ `pwd` != "/" ] && [ `pwd` != "/etc" ] ; do
ls -dla $curdir
curdir=`pwd`
printf "chmod 755 %s\n" "$curdir"
cd ..
chmod 755 $curdir
ls -dla $curdir
if [ $? -ne 0 ]; then
echoerr "Failed to set key permissions"
break
fi
done
fi
}
make_keys_readable() {
# Bad things will happen if Asterisk cannot read the TLS keys that it needs.
# This will do a directory traversal to the location(s) of TLS keys and make sure
# that the keys and all their parent directories are readable. If any parent
# directory in the chain doesn't have the right permissions then things will fail.
# Save the current working directory.
curdir=`pwd`
# grep commands: Don't show filename in output. Ignore files with <. Remove leading whitespace, eliminate lines beginning with ; (comment), take only the first word
# tlscertfile used by http.conf and sip.conf
# Simpler methods of looping on each line of output only work in bash and not POSIX sh
echo -n "" > /tmp/astkeylist.txt
grep -h -R "tlscertfile" $AST_CONFIG_DIR | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
grep -h -R "priv_key_file" $AST_CONFIG_DIR | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
while read filename
do
printf "Processing potential key: %s\n" "$filename"
make_file_readable "$filename"
done < /tmp/astkeylist.txt # POSIX compliant
rm /tmp/astkeylist.txt
cd $curdir # Restore original working directory.
}
# $1 = include Asterisk-only pre-reqs (not needed for DAHDI-only builds)
install_prereq() {
# wget should already be installed at this point, so it's not included here
PREREQ_PACKAGES=""
RHEL_MAJOR_VERSION_8=0
printf "Installing prerequisites for %s..." "$OS_DIST_INFO"
# Even if we are just installing DAHDI (without Asterisk), $CHAN_DAHDI should be set to 1 at this point.
# libnewt-dev is needed for newt, which dahdi_tool requires. If it's not available, it won't get built.
# dwarves is needed for pahole, which DAHDI Linux install needs for BTF generation
if [ "$PAC_MAN" = "apt-get" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES git patch gcc pkg-config autoconf automake m4 libtool build-essential"
if [ "$CHAN_DAHDI" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES libnewt-dev dwarves"
fi
if [ "$1" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES curl subversion libcurl4-openssl-dev"
if [ "$ENHANCED_INSTALL" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES dnsutils bc mpg123 ntp tcpdump festival"
fi
if [ "$DEVMODE" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES xmlstarlet" # only needed in developer mode for doc validation.
fi
fi
PREREQ_PACKAGES="$PREREQ_PACKAGES libedit-dev" # Ubuntu also needs this package
# apt-get install libcurl3-gnutls=7.64.0-4+deb10u2 # fix git clone not working: upvoted comment at https://superuser.com/a/1642989
PREREQ_PACKAGES="$PREREQ_PACKAGES debconf-utils" # used to feed the country code non-interactively
elif [ "$PAC_MAN" = "yum" ]; then
# Format is something like: Rocky Linux release 8.10 (Green Obsidian)
RHEL_MAJOR_VERSION=$( cat /etc/redhat-release | cut -d'(' -f1 | awk '{print $(NF)}' | cut -d'.' -f1 )
if [ -f /etc/redhat-release ] && [ "$RHEL_MAJOR_VERSION" = "8" ]; then # RHEL or Rocky Linux major version 8
RHEL_MAJOR_VERSION_8=1
fi
PREREQ_PACKAGES="$PREREQ_PACKAGES git patch gcc gcc-c++ pkg-config autoconf automake m4 libtool"
if [ "$CHAN_DAHDI" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES newt-devel"
if [ $RHEL_MAJOR_VERSION_8 -eq 0 ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES dwarves" # Not available on 8.9
fi
fi
if [ "$1" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES subversion libuuid-devel libxml2-devel sqlite-devel"
if [ $RHEL_MAJOR_VERSION_8 -eq 0 ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES libedit-devel" # Required on Fedora, may fail initially on Rocky Linux 8.9
fi
fi
elif [ "$PAC_MAN" = "zypper" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES git-core make patch gawk subversion bzip2 gcc-c++"
if [ "$CHAN_DAHDI" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES newt-devel dwarves"
fi
if [ "$1" = "1" ]; then
# TODO Some of these should be in Asterisk's install_prereq script
PREREQ_PACKAGES="$PREREQ_PACKAGES libedit-devel libuuid-devel libxml2-devel sqlite3-devel"
fi
elif [ "$PAC_MAN" = "pacman" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES git make patch gcc pkg-config autoconf automake m4 libtool"
if [ "$CHAN_DAHDI" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES libnewt pahole"
fi
if [ "$1" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES subversion libedit"
fi
elif [ "$PAC_MAN" = "pkg" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES git gmake"
if [ "$CHAN_DAHDI" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES newt dwarves"
fi
if [ "$1" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES curl subversion e2fsprogs-libuuid sqlite3 xmlstarlet libsysinfo"
if [ "$ENHANCED_INSTALL" = "1" ]; then
PREREQ_PACKAGES="$PREREQ_PACKAGES ntp tcpdump mpg123 bind-tools" # bind-tools for dig
fi
fi
else
echoerr "Could not determine what package manager to use..."
return
fi
install_package "$PREREQ_PACKAGES"
# Any followup work
if [ "$PAC_MAN" = "yum" ]; then
# Stop on RHEL systems without an active subscription since packages are failing to install
if ! which git > /dev/null; then
if [ -f /etc/redhat-release ]; then
echoerr "Subscription required to use RHEL package manager"
fi
die "Git does not appear to be installed"
fi
if [ "$1" = "1" ]; then
if [ $RHEL_MAJOR_VERSION_8 -eq 1 ]; then
# Rocky Linux seems to be missing libedit-devel, and this package is "missing"