forked from InterLinked1/phreakscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphreaknet.sh
3541 lines (3359 loc) · 152 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-2023 Naveen Albert, PhreakNet, and others - https://github.com/InterLinked1/phreakscript ; https://portal.phreaknet.org ; https://docs.phreaknet.org
# v0.3.1 (2023-03-03)
# Setup (as root):
# cd /usr/local/src
# wget https://docs.phreaknet.org/script/phreaknet.sh
# chmod +x phreaknet.sh
# ./phreaknet.sh make
# phreaknet update
# phreaknet install
## Begin Change Log:
# 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_SOURCE_NAME="asterisk-20-current"
LIBPRI_SOURCE_NAME="libpri-1.6.0"
WANPIPE_SOURCE_NAME="wanpipe-7.0.34" # wanpipe-latest
ODBC_VER="3.1.14"
CISCO_CM_SIP="cisco-usecallmanager-18.15.0"
AST_ALT_VER=""
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_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 --show-progress"
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
WEAK_TLS=0
CHAN_SIP=0
ENHANCED_CHAN_SIP=0
SIP_CISCO=0
CHAN_SCCP=0
CHAN_DAHDI=0
DAHDI_OLD_DRIVERS=0
DEVMODE=0
TEST_SUITE=0
FORCE_INSTALL=0
ENHANCED_INSTALL=1
EXPERIMENTAL_FEATURES=0
LIGHTWEIGHT=0
FAST_COMPILE=0
PKG_AUDIT=0
MANUAL_MENUSELECT=0
ENABLE_BACKTRACES=0
ASTKEYGEN=0
DEFAULT_PATCH_DIR="/var/www/html/interlinked/sites/phreak/code/asterisk/patches" # 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
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_DIST_INFO" = "FreeBSD" ]; then
PAC_MAN="pkg"
AST_SOURCE_PARENT_DIR="/usr/local/src"
AST_MAKE="gmake"
XMLSTARLET="/usr/local/bin/xml"
elif [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
PAC_MAN="yum"
fi
phreakscript_info() {
printf "%s" "Hostname: "
hostname
echo $OS_DIST_INFO
uname -a
echo "Package Manager: $PAC_MAN"
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-2023 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 dahdi odbc installts fail2ban apiban freepbx pulsar sounds boilerplate-sounds ulaw remsil uninstall uninstall-all bconfig config keygen keyperms update patch genpatch alembic freedisk topdir topdisk enable-swap disable-swap restart 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 gerrit fuzzygerrit ccache fullpatch docgen 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
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
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
restart Fully restart DAHDI 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
gerrit Manually install a custom patch set from Gerrit
fuzzygerrit Manually install a custom patch set from Gerrit, using patch (not recommended)
fullpatch Redownload an entire PhreakNet source file
ccache Globally install ccache to speed up recompilation
*** Miscellaneous ***
docgen Generate Asterisk user documentation
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
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
-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
--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
--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
--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
}
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" /etc/asterisk | 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" /etc/asterisk | 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.
}
install_prereq() {
if [ "$PAC_MAN" = "apt-get" ]; 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
apt-get clean
apt-get update -y
apt-get upgrade -y
if [ "$ENHANCED_INSTALL" = "1" ]; then
apt-get dist-upgrade -y
fi
apt-get install -y wget curl libcurl4-openssl-dev dnsutils bc git mpg123 # necessary for install and basic operation.
if [ "$ENHANCED_INSTALL" = "1" ]; then # not strictly necessary, but likely useful on many Asterisk systems.
apt-get install -y ntp tcpdump festival
fi
if [ "$DEVMODE" = "1" ]; then
apt-get install -y xmlstarlet # only needed in developer mode for doc validation.
fi
apt-get install -y 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
# used to feed the country code non-interactively
apt-get install -y debconf-utils
apt-get -y autoremove
# TODO: missing yum support
elif [ "$PAC_MAN" = "pkg" ]; then
pkg update -f
pkg upgrade -y
pkg install -y e2fsprogs-libuuid wget sqlite3 ntp tcpdump curl mpg123 git bind-tools gmake subversion xmlstarlet # bind-tools for dig
pkg info e2fsprogs-libuuid
#if [ $? -ne 0 ]; then
# if [ ! -d /usr/ports/misc/e2fsprogs-libuuid/ ]; then # https://www.freshports.org/misc/e2fsprogs-libuuid/
# portsnap fetch extract
# fi
# cd /usr/ports/misc/e2fsprogs-libuuid/ && make install clean # for uuid-dev
# pkg install misc/e2fsprogs-libuuid
#fi
else
echoerr "Could not determine what package manager to use..."
fi
apt autoremove
}
ensure_installed() {
if ! which "$1" > /dev/null; then
if [ "$PAC_MAN" = "apt-get" ]; then
apt-get install -y "$1"
elif [ "$PAC_MAN" = "yum" ]; then
yum install -y "$1"
else
echoerr "Not sure how to satisfy requirement $1"
fi
fi
}
install_boilerplate() {
if [ ! -d $AST_CONFIG_DIR/dialplan ]; then
mkdir -p $AST_CONFIG_DIR/dialplan
cd $AST_CONFIG_DIR/dialplan
elif [ ! -d $AST_CONFIG_DIR/dialplan/phreaknet ]; then
mkdir -p $AST_CONFIG_DIR/dialplan/phreaknet
cd $AST_CONFIG_DIR/dialplan/phreaknet
else
if [ "$FORCE_INSTALL" != "1" ]; then
echoerr "It looks like you already have configs. Proceed and overwrite? (y/n) "
printf '\a'
read -r -p "" ans
if [ "$ans" != "y" ]; then
echo "Cancelling config installation."
exit 1
fi
fi
fi
printf "Backing up %s configs, just in case...\n" $AST_CONFIG_DIR
mkdir -p /tmp/etc_asterisk
cp $AST_CONFIG_DIR/*.conf /tmp/etc_asterisk # do we really trust users not to make a mistake? backup to tmp, at least...
EXTENSIONS_CONF_FILE="extensions.conf"
if [ -f $AST_CONFIG_DIR/freepbx_module_admin.conf ]; then
printf "%s\n" "Detected FreePBX installation..."
EXTENSIONS_CONF_FILE="extensions_custom.conf"
fi
printf "%s" "Installing boilerplate code to "
pwd
printf "\n"
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/dialplan/verification.conf -O verification.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/dialplan/phreaknet.conf -O phreaknet.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/dialplan/phreaknet-aux.conf -O phreaknet-aux.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/dialplan/phreaknet-coin.conf -O phreaknet-coin.conf --no-cache
cd $AST_CONFIG_DIR
pwd
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/asterisk.conf -O $AST_CONFIG_DIR/asterisk.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/modules.conf -O $AST_CONFIG_DIR/modules.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/chan_dahdi.conf -O $AST_CONFIG_DIR/chan_dahdi.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/iax.conf -O $AST_CONFIG_DIR/iax.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/sip.conf -O $AST_CONFIG_DIR/sip.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/pjsip.conf -O $AST_CONFIG_DIR/pjsip.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/musiconhold.conf -O $AST_CONFIG_DIR/musiconhold.conf --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/extensions.conf -O $AST_CONFIG_DIR/$EXTENSIONS_CONF_FILE --no-cache
$WGET https://raw.githubusercontent.com/InterLinked1/phreaknet-boilerplate/master/verify.conf -O $AST_CONFIG_DIR/verify.conf --no-cache
printf "%s\n" "Boilerplate config installed! Note that these files may still require manual editing before use."
}
install_boilerplate_sounds() {
cd $AST_SOUNDS_DIR
mkdir -p custom/signal
cd custom/signal
download_if_missing "dialtone.ulaw" "https://audio.phreaknet.org/stock/dialtone.ulaw"
download_if_missing "busy.ulaw" "https://audio.phreaknet.org/stock/busy.ulaw"
download_if_missing "reorder.ulaw" "https://audio.phreaknet.org/stock/reorder.ulaw"
download_if_missing "ccad.ulaw" "https://audio.phreaknet.org/stock/ccad.ulaw"
download_if_missing "acbn.ulaw" "https://audio.phreaknet.org/stock/acbn.ulaw"
cd $AST_MOH_DIR
mkdir -p ringback
cd ringback
download_if_missing "ringback.ulaw" "https://audio.phreaknet.org/stock/ringback.ulaw"
}
install_freepbx_checks() {
if [ "$AST_USER" != "asterisk" ]; then
echoerr "FreePBX requires installing as asterisk user (use --user asterisk)"
exit 2
fi
if [ -f $AST_CONFIG_DIR/extensions.conf ]; then
if [ "$FORCE_INSTALL" != "1" ]; then
echoerr "An existing /etc/asterisk/extensions.conf has been detected on the file system. Installing FreePBX will overwrite ALL OF YOUR CONFIGURATION!!!"
printf "%s\n" "If this is intended, rerun the command with the -f or --force flag. Be sure to backup your configuration first if desired."
exit 2
fi
fi
}
install_freepbx() { # https://www.atlantic.net/vps-hosting/how-to-install-asterisk-and-freepbx-on-ubuntu-20-04/
FREEPBX_VERSION="freepbx-16.0-latest"
# avoid using if possible
# PHP 7.4 is supported: https://www.freepbx.org/freepbx-16-is-now-released-for-general-availability/
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
cd $AST_SOURCE_PARENT_DIR
wget http://mirror.freepbx.org/modules/packages/freepbx/$FREEPBX_VERSION.tgz -O $AST_SOURCE_PARENT_DIR/$FREEPBX_VERSION.tgz
tar -xvzf $FREEPBX_VERSION.tgz
cd $AST_SOURCE_PARENT_DIR/freepbx
rm ../$FREEPBX_VERSION.tgz
if [ $? -ne 0 ]; then
echoerr "Failed to find FreePBX source directory"
return
fi
apt-get install -y nodejs
phreak_tree_patch "installlib/installcommand.class.php" "freepbx_installvercheck.diff" # bug fix to installer
./install -n
if [ $? -ne 0 ]; then
echoerr "Installation failed"
return
fi
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
PHP_VERSION=`ls /etc/php | tr -d '\n'`
printf "System version of PHP is %s\n" "$PHP_VERSION"
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/$PHP_VERSION/apache2/php.ini
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/$PHP_VERSION/cli/php.ini
printf "%s\n" "Reloading and restarting Apache web server..."
a2enmod rewrite
systemctl restart apache2
PUBLIC_IP=`dig +short myip.opendns.com @resolver1.opendns.com`
printf "Public IP address is: %s\n" "$PUBLIC_IP"
hostname -I
printf "%s\n" "FreePBX has been installed and can be accessed at http://IP-ADDRESS/admin"
printf "%s\n" "Use the appropriate IP address for your system, as indicated above."
printf "%s\n" "You will need to navigate to this page to complete setup."
printf "%s\n" "If this system is Internet facing, you are urged to secure your system"
printf "%s\n" "by restricting access to specific IP addresses only."
}
uninstall_freepbx() {
printf "%s\n" "Uninstalling and removing FreePBX-specific stuff"
# ./install_amp --uninstall # where is this file even located?
rm /usr/sbin/amportal
# rm -rf /var/lib/asterisk/bin/* # there could be other stuff in here
rm -rf /var/www/html/admin/*
rm /etc/amportal.conf
rm /etc/asterisk/amportal.conf
rm /etc/freepbx.conf
rm /etc/asterisk/freepbx.conf
}
run_testsuite_test() {
testcount=$(($testcount + 1))
./runInVenv.sh python3 runtests.py --test=tests/$1
# XXX It also seems that if pre-reqs are not satisfied, exit code is 0?
if [ $? -ne 0 ]; then # test failed
printf "Exit code was %d\n" $?
ls
lastrun=`get_newest_astdir` # get the directory containing the logs from the most recently run test
if [ "$lastrun" = "" ]; then
echoerr "No test executions found in $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/"
ls -la $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/
exit 1
fi
ls "$lastrun/ast1/var/log/asterisk/full.txt"
if [ -f "$lastrun/ast1/var/log/asterisk/full.txt" ]; then
grep -B 12 "UserEvent(" $lastrun/ast1/var/log/asterisk/full.txt | grep -v "pbx.c: Launching" | grep -v "stasis.c: Topic" # this should provide a good idea of what failed (or at least, what didn't succeed)
fi
else # test succeeded
testsuccess=$(($testsuccess + 1))
fi
}
run_testsuite_test_only() { # $2 = stress test
cd $AST_SOURCE_PARENT_DIR/testsuite # required, full paths are not sufficient, we must cd into the dir...
if [ $? -ne 0 ]; then
exit 2
fi
if [ ! -d "$AST_SOURCE_PARENT_DIR/testsuite/tests/$1" ]; then
echoerr "No such directory: $AST_SOURCE_PARENT_DIR/testsuite/tests/$1"
exit 2
fi
echo "$AST_SOURCE_PARENT_DIR/testsuite/runtests.py --test=tests/$1"
iterations=1
if [ "$2" = "1" ]; then
iterations=7
fi
while [ $iterations -gt 0 ]; do # POSIX for loop
./runInVenv.sh python3 $AST_SOURCE_PARENT_DIR/testsuite/runtests.py --test=tests/$1
if [ $? -ne 0 ]; then # test failed
echo "ls -d -v $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/* | tail -1"
lastrun=`ls -d -v $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/* | tail -1` # get the directory containing the logs from the most recently run test ############# this is not FreeBSD compatible.
if [ "$lastrun" = "" ]; then
echoerr "No test executions found in $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/"
ls -la $AST_SOURCE_PARENT_DIR/testsuite/logs/$1/
exit 1
fi
ls "$lastrun/ast1/var/log/asterisk/full.txt"
grep -B 12 "UserEvent(" $lastrun/ast1/var/log/asterisk/full.txt | grep -v "pbx.c: Launching" | grep -v "stasis.c: Topic" # this should provide a good idea of what failed (or at least, what didn't succeed)
exit 1
fi
iterations=$(( iterations - 1 ))
done
if [ "$2" = "1" ]; then
printf "Stress test passed: %s\n" "$1"
fi
}
run_testsuite_tests() {
testcount=0
testsuccess=0
if [ ! -d "$AST_SOURCE_PARENT_DIR/testsuite" ]; then
echoerr "Directory $AST_SOURCE_PARENT_DIR/testsuite does not exist!"
exit 1
fi
if [ ! -f "$AST_CONFIG_DIR/asterisk.conf" ]; then
echoerr "$AST_CONFIG_DIR/asterisk.conf not found"
exit 1
fi
ls -la /usr/sbin/asterisk
cd $AST_SOURCE_PARENT_DIR/testsuite
# run manually for good measure, and so we get the full output
./setupVenv.sh
run_testsuite_test "apps/assert"
run_testsuite_test "apps/dialtone"
run_testsuite_test "apps/verify"
run_testsuite_test "funcs/func_dbchan"
printf "%d of %d test(s) passed\n" $testsuccess $testcount
if [ $testcount -ne $testsuccess ]; then
exit 1
fi
exit 0
}
install_phreak_testsuite_test() { # $1 = test path
parent=`dirname "$1"`
base=`basename "$1"`
if [ ! -d "testsuite/tests/$parent" ]; then
echoerr "Directory testsuite/tests/$parent does not exist!"
exit 2
fi
if [ ! -f "testsuite/tests/$parent/tests.yaml" ]; then
echoerr "File tests/$parent/tests.yaml does not exist!"
exit 2
fi
if [ ! -d "phreakscript/testsuite/tests/$1" ]; then
echoerr "Directory phreakscript/testsuite/tests/$1 does not exist!"
ls -la phreakscript/testsuite/tests
exit 2
fi
cp -r "phreakscript/testsuite/tests/$1" "testsuite/tests/$parent"
echo " - test: '$base'" >> "testsuite/tests/$parent/tests.yaml" # rather than have a patch for this file, which could be subject to frequent change and result in a finicky patch that's likely to fail, simply append it to the list of tests to run
printf "Installed test: %s\n" "$1"
}
add_phreak_testsuite() {
printf "%s\n" "Applying PhreakNet test suite additions"
cd $AST_SOURCE_PARENT_DIR
if [ ! -d phreakscript ]; then # if dir exists, assume it's the repo
git clone https://github.com/InterLinked1/phreakscript.git
fi
cd phreakscript
if [ $? -ne 0 ]; then
echoerr "Failed to find phreakscript directory"
pwd
exit 1
fi
git config pull.rebase false # this is the default. Do this solely to avoid those annoying "Pulling without specifying" warnings...
git pull # in case it already existed, update the repo
cd $AST_SOURCE_PARENT_DIR
install_phreak_testsuite_test "apps/assert"
install_phreak_testsuite_test "apps/dialtone"
install_phreak_testsuite_test "apps/verify"
install_phreak_testsuite_test "funcs/func_dbchan"
printf "%s\n" "Finished patching testsuite"
}
gerrit_patch() {
printf "%s\n" "Downloading and applying Gerrit patch $1"
wget -q $2 -O $1.patch.base64
if [ $? -ne 0 ]; then
echoerr "Patch download failed"
exit 2
fi
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
b64decode -r $1.patch.base64 > $1.patch
if [ $? -ne 0 ]; then
exit 2
fi
else
base64 --decode $1.patch.base64 > $1.patch
fi
# Apply the patch file
git apply $1.patch
if [ $? -ne 0 ]; then
echoerr "Failed to apply Gerrit patch $1 ($2)... this should be reported..."
if [ "$FORCE_INSTALL" = "1" ]; then
sleep 2
else
exit 2
fi
fi
rm $1.patch.base64 $1.patch
}
gerrit_fuzzy_patch() {
printf "%s\n" "Downloading and applying Gerrit patch $1"
wget -q $2 -O $1.patch.base64
if [ $? -ne 0 ]; then
echoerr "Patch download failed"
exit 2
fi
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
b64decode -r $1.patch.base64 > $1.patch
if [ $? -ne 0 ]; then
exit 2
fi
else
base64 --decode $1.patch.base64 > $1.patch
fi
# Apply the patch file
patch -p1 < $1.patch
if [ $? -ne 0 ]; then
echoerr "Failed to apply fuzzy Gerrit patch $1 ($2)... this should be reported..."
if [ "$FORCE_INSTALL" = "1" ]; then
sleep 2
else
exit 2
fi
fi
rm $1.patch.base64 $1.patch
}
install_testsuite_itself() {
apt-get clean
apt-get update -y
apt-get upgrade -y
cd $AST_SOURCE_PARENT_DIR
if [ -d "testsuite" ]; then
if [ "$FORCE_INSTALL" = "1" ]; then
printf "%s\n" "Reinstalling testsuite..."
rm -rf testsuite
else
echoerr "Test Suite already exists... specify --force flag to reinstall"
fi
fi
git clone https://gerrit.asterisk.org/testsuite
if [ $? -ne 0 ]; then
echoerr "Failed to download testsuite..."
return 1
fi
cd testsuite
./contrib/scripts/install_prereq install
# In theory, the below is not necessary:
pip3 install pyyaml
pip3 install twisted
cd $AST_SOURCE_PARENT_DIR
cd testsuite
./setupVenv.sh
# ./runInVenv.sh python3 ./runtests.py -t tests/channels/iax2/basic-call/ # run a single basic test
#./runInVenv.sh python3 ./runtests.py -l # list all tests
if [ ! -f "$AST_SOURCE_PARENT_DIR/testsuite/tests/apps/tests.yaml" ]; then
echoerr "tests/apps/tests.yaml doesn't exist?"
exit 1
else
# fix testsuite regression caused by c930bfec37118e37ff271bf381825408d2409fec (missing newline at EOF)
echo "" >> "$AST_SOURCE_PARENT_DIR/testsuite/tests/apps/tests.yaml"
fi
add_phreak_testsuite
printf "%s\n" "Asterisk Test Suite installation complete"
}
configure_devmode() {
./configure --enable-dev-mode --with-jansson-bundled
make menuselect.makeopts
menuselect/menuselect --enable DONT_OPTIMIZE --enable BETTER_BACKTRACES --enable COMPILE_DOUBLE --enable DO_CRASH menuselect.makeopts
menuselect/menuselect --enable DEBUG_THREADS --enable MALLOC_DEBUG --enable DEBUG_FD_LEAKS menuselect.makeopts
menuselect/menuselect --enable TEST_FRAMEWORK --enable-category MENUSELECT_TESTS menuselect.makeopts
}
install_testsuite() { # $1 = $FORCE_INSTALL
cd $AST_SOURCE_PARENT_DIR
# in case we're not already in the right directory
AST_SRC_DIR=`ls -d */ | grep "^asterisk-" | tail -1`
if [ "$AST_SRC_DIR" = "" ]; then
echoerr "Asterisk source not found. Aborting..."
pwd
ls -la
return 1
fi
cd $AST_SOURCE_PARENT_DIR/$AST_SRC_DIR
configure_devmode
make
make install
install_testsuite_itself
}
install_samples() {
# Only install sample config files if this is the first time (configs aren't already present on the system)
if [ ! -f "$AST_CONFIG_DIR/asterisk.conf" ]; then
if [ -d "$AST_CONFIG_DIR" ]; then
printf "$AST_CONFIG_DIR existed but not $AST_CONFIG_DIR/asterisk.conf... Installing sample configs now."
fi
# the phoneprov files will fail to install if make install has not been run yet, so we do this AFTER make install.
$AST_MAKE samples # do not run this on upgrades or it will wipe out your config!
rm $AST_CONFIG_DIR/users.conf # remove users.conf, because a) it's stupid, and shouldn't be used, and b) it creates warnings when reloading other modules, e.g. chan_dahdi.
# Change a few defaults for our sanity. This makes Asterisk more usable immediately without modifying or replacing the configs.
sed -i 's/;verbose =/verbose =/' $AST_CONFIG_DIR/asterisk.conf
sed -i 's/;timestamp =/timestamp =/' $AST_CONFIG_DIR/asterisk.conf
else
printf "Skipping sample config installation, since %s already exists\n" $AST_CONFIG_DIR
fi
}
dahdi_undo() {
printf "Restoring drivers by undoing PATCH: %s\n" "$3"
wget -q "https://git.asterisk.org/gitweb/?p=dahdi/linux.git;a=patch;h=$4" -O /tmp/$2.patch --no-cache
patch -u -b -p 1 --reverse -i /tmp/$2.patch
if [ $? -ne 0 ]; then
echoerr "Failed to reverse DAHDI patch... this should be reported..."
exit 2
fi
rm /tmp/$2.patch
}
dahdi_custom_undo() {
printf "Applying custom reverse DAHDI patch: %s\n" "$3"
wget -q "$4" -O /tmp/$2.patch --no-cache
patch -u -p 1 --reverse -i /tmp/$2.patch
if [ $? -ne 0 ]; then
echoerr "Failed to reverse custom DAHDI patch... this should be reported..."
exit 2
fi
rm /tmp/$2.patch
}
dahdi_custom_patch() {
printf "Applying custom DAHDI patch: %s\n" "$1"