-
Notifications
You must be signed in to change notification settings - Fork 7
/
ngrok_install_en.sh
1616 lines (1494 loc) · 51.8 KB
/
ngrok_install_en.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/bash
trap 'rm -f "$TMPFILE"' EXIT
blue() {
echo -e "\033[34m\033[01m$1\033[0m"
}
green() {
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow() {
echo -e "\033[33m\033[01m$1\033[0m"
}
red() {
echo -e "\033[31m\033[01m$1\033[0m"
}
CHECK_STATUS_FILE=$(mktemp) || exit 1
START_FROM_FILE=$(mktemp) || exit 1
echo "0" 1>$CHECK_STATUS_FILE
echo "0" 1>$START_FROM_FILE
function delay() { sleep 0.1; }
function bar_continue() {
echo "1" 1>$CHECK_STATUS_FILE
wait
echo -ne ' \r'
}
function bar_start_from() {
echo "$1" 1>$START_FROM_FILE
echo "0" 1>$CHECK_STATUS_FILE
}
function bar_hold_at() {
custom_progress=$1;
custom_phase=$2;
num=0
postfix=('|' '/' '-' '\')
read check_start_from <$START_FROM_FILE
read check_status <$CHECK_STATUS_FILE
while [ $check_start_from -le 0 -a $custom_progress -ge 0 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [..........................] (0%)" "$custom_phase"
let num++
sleep 0.1
if [ $custom_progress -gt 0 ]; then
let check_start_from=5
break
elif [ "$check_status" = "1" ]; then
echo "5" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 5 -a $custom_progress -ge 5 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#.........................] (5%)" "$custom_phase"
let num++
sleep 0.1
if [ $custom_progress -gt 5 ]; then
let check_start_from=10
break
elif [ "$check_status" = "1" ]; then
echo "10" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 10 -a $custom_progress -ge 10 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [##........................] (10%)" "$custom_phase"
let num++
sleep 0.1
if [ $custom_progress -gt 10 ]; then
let check_start_from=15
break
elif [ "$check_status" = "1" ]; then
echo "15" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 15 -a $custom_progress -ge 15 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [###.......................] (15%)" "$custom_phase"
let num++
sleep 0.1
if [ $custom_progress -gt 15 ]; then
let check_start_from=20
break
elif [ "$check_status" = "1" ]; then
echo "20" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 20 -a $custom_progress -ge 20 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [####......................] (20%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 20 ]; then
let check_start_from=25
break
elif [ "$check_status" = "1" ]; then
echo "25" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 25 -a $custom_progress -ge 25 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#####.....................] (25%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 25 ]; then
let check_start_from=30
break
elif [ "$check_status" = "1" ]; then
echo "30" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 30 -a $custom_progress -ge 30 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [######....................] (30%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 30 ]; then
let check_start_from=35
break
elif [ "$check_status" = "1" ]; then
echo "35" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 35 -a $custom_progress -ge 35 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#######...................] (35%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 35 ]; then
let check_start_from=40
break
elif [ "$check_status" = "1" ]; then
echo "40" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 40 -a $custom_progress -ge 40 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [########..................] (40%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 40 ]; then
let check_start_from=45
break
elif [ "$check_status" = "1" ]; then
echo "45" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 45 -a $custom_progress -ge 45 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#########.................] (45%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 45 ]; then
let check_start_from=50
break
elif [ "$check_status" = "1" ]; then
echo "50" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 50 -a $custom_progress -ge 50 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [##########................] (50%) " "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 50 ]; then
let check_start_from=55
break
elif [ "$check_status" = "1" ]; then
echo "55" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 55 -a $custom_progress -ge 55 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [###########...............] (55%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 55 ]; then
let check_start_from=60
break
elif [ "$check_status" = "1" ]; then
echo "60" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 60 -a $custom_progress -ge 60 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [############..............] (60%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 60 ]; then
let check_start_from=65
break
elif [ "$check_status" = "1" ]; then
echo "65" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 65 -a $custom_progress -ge 65 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#############.............] (65%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 65 ]; then
let check_start_from=70
break
elif [ "$check_status" = "1" ]; then
echo "70" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 70 -a $custom_progress -ge 70 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [##############............] (70%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 70 ]; then
let check_start_from=75
break
elif [ "$check_status" = "1" ]; then
echo "75" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 75 -a $custom_progress -ge 75 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [################..........] (75%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 75 ]; then
let check_start_from=80
break
elif [ "$check_status" = "1" ]; then
echo "80" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 80 -a $custom_progress -ge 80 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [###################.......] (80%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 80 ]; then
let check_start_from=85
break
elif [ "$check_status" = "1" ]; then
echo "85" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 85 -a $custom_progress -ge 85 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#####################.....] (85%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 85 ]; then
let check_start_from=90
break
elif [ "$check_status" = "1" ]; then
echo "90" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 90 -a $custom_progress -ge 90 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [#######################...] (90%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 95 ]; then
let check_start_from=95
break
elif [ "$check_status" = "1" ]; then
echo "95" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
while [ $check_start_from -le 95 -a $custom_progress -ge 95 ]
do
let index=num%4
printf "%-31s %-50s \r" "[ ${postfix[$index]} ] [########################..] (95%)" "$custom_phase"
let num++
sleep 0.1
read check_status <$CHECK_STATUS_FILE
if [ $custom_progress -gt 95 ]; then
let check_start_from=100
break
elif [ "$check_status" = "1" ]; then
echo "100" 1>$START_FROM_FILE
exit 0
else
continue
fi
done
if [ $check_start_from -le 100 -a $custom_progress -ge 100 ]; then echo -ne "[ - ] [##########################] (100%) $custom_phase \r" ; delay; fi;
if [ $check_start_from -le 100 -a $custom_progress -ge 100 ];then echo -ne 'done! \r' ; delay; fi;
}
mkdir -p /opt/new_ngrok/log
touch /opt/new_ngrok/log/ngrok_log.log
log_file=/opt/new_ngrok/log/ngrok_log.log
function exit_program() {
echo "exit program"
exit 0
}
# get system release info ok
function get_release() {
source /etc/os-release
RELEASE=$ID
VERSION=$VERSION
CONF=`getconf LONG_BIT`
CPU=`uname -m`
}
# check release ok
function check_release() {
get_release
echo "[ * ] checking system release infomation "
if [ "$RELEASE" == "centos" ]; then
red "[ × ] Sorry, CentOS is currently not supported. More functions are developing, thanx for your support! "
exit_program
elif [ "$RELEASE" == "debian" ]; then
yellow "[ √ ] Detected system: $RELEASE, version: $VERSION_ID $CONF, chip arch: $CPU"
green "[ √ ] check completed "
elif [ "$RELEASE" == "ubuntu" ]; then
yellow "[ √ ] Detected system: $RELEASE, version: $VERSION_ID $CONF, chip arch: $CPU"
green "[ √ ] check completed "
else
red "[ × ] Sorry, $RELEASE is currently not supported. More functions are developing, thanx for your support! "
exit_program
fi
}
# check network whether could access youtube ok
function check_network() {
if ping -c 3 -w 3 www.baidu.com >/dev/null;then
if ping -c 3 -w 3 www.youtube.com >/dev/null;then
green "[ √ ] Current internet detected: international "
network=international >/dev/null
else
yellow "[ √ ] Current internet detected: cn "
network=mainland >/dev/null
sed -i '$a\13.114.40.48 github.com' /etc/hosts
if ping -c 3 -w 5 github.com >/dev/null;then
green "[ √ ] Internet configuration complete! "
else
red "[ × ] Cannot access to github, please check internet before continue! "
exit_program
fi
fi
else
red "[ × ] Internet configuration error! Please check internet before continue! "
exit_program
fi
}
# check log file ok
function check_log() {
if [ ! -f "$log_file" ]; then
mkdir -p /opt/new_ngrok/log >/dev/null
fi
}
apt_source_debian() {
cat > /etc/apt/sources.list <<-EOF
deb http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free
deb http://mirrors.ustc.edu.cn/debian buster-backports main contrib non-free
deb http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster-backports main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
EOF
}
apt_source_ubuntu() {
cat > /etc/apt/sources.list <<-EOF
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
EOF
}
# apt update and choose whether to change source
apt_update() {
yellow "[ - ] Do you want to update apt?(y/n)"
read apt_update
if [[ $apt_update == "y" ]]||[[ $apt_update == "Y" ]]; then
yellow "[ - ] Do you want to change apt source?(y/n)"
read apt_source
if [[ $apt_source == "y" ]]||[[ $apt_source == "Y" ]]; then
if [ "$RELEASE" == "debian" ]; then
apt_source_debian
green "[ √ ] apt source changed to USTC!"
elif [ "$RELEASE" == "ubuntu" ]; then
apt_source_ubuntu
green "[ √ ] apt source changed to USTC! "
else
red "[ × ] Sorry, $RELEASE is currently not supported. More functions are developing, thanx for your support!"
exit_program
fi
elif [[ $apt_source == "n" ]]||[[ $apt_source == "N" ]]; then
echo "[ * ] skipped"
else
red "[ x ] error! Exiting program"
fi
echo "[ * ] Start updating apt"
bar_start_from 0
bar_hold_at 25 "apt updating" &
sudo apt update -y >/dev/null 2>&1
bar_continue
bar_start_from 25
bar_hold_at 50 "apt upgrading" &
sudo apt upgrade -y >/dev/null 2>&1
bar_continue
bar_start_from 50
bar_hold_at 75 "apt-get updating" &
sudo apt-get update -y >/dev/null 2>&1
bar_continue
bar_start_from 75
bar_hold_at 95 "apt-get upgrading" &
sudo apt-get upgrade -y >/dev/null 2>&1
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] Successfully updated apt! "
elif [[ $apt_update == "n" ]]||[[ $apt_update == "N" ]]; then
green "[ * ] Jumped update apt "
else
red "[ x ] error! Exiting program"
exit_program
fi
}
# # 检查apt是否能正常使用 ok
# function check_apt() {
# echo "[ * ] 即将开始检查apt环境"
# bar_start_from 0
# bar_hold_at 50 "checking apt" &
# apt update -y 2> /opt/new_ngrok/log/ngrok_log.log >/dev/null
# # if cat $log_file| grep "apt" >> /dev/null; then
# # bar_continue
# # red "[ × ] apt error,please check apt before run the script! "
# # :> $log_file
# # exit_program
# # else
# # apt_update -y >/dev/null 2>&1
# # bar_continue
# # bar_hold_at 100 "done! "
# # green "[ √ ] apt检测完成 "
# # fi
# bar_continue
# bar_hold_at 100 "done!"
# green "[ √ ] apt检测完成 "
# }
function check_firewalld() {
firewalld 2> /opt/new_ngrok/log/ngrok_log.log
if cat $log_file| grep "firewalld" >> /dev/null; then
red "[ × ] Firewalld not detected, now start installing firewalld "
:> $log_file
apt install firewalld -y >/dev/null 2>&1
else
green "[ √ ] Firewall checked! "
fi
}
# check git ok
function check_git() {
git version 2> /opt/new_ngrok/log/ngrok_log.log >/dev/null
if cat $log_file| grep "git" >> /dev/null; then
red "[ × ] Git not detected, now start installing git"
:> $log_file
apt install git -y >/dev/null
if [ "$network" == "mainland" ]; then
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
else
pass
fi
else
green "[ √ ] Git checked! "
fi
}
# check other tools ok
function check_tools() {
apt install wget -y >/dev/null 2>&1
green "[ √ ] Wget checked! "
apt install curl -y >/dev/null 2>&1
green "[ √ ] Curl checkded! "
apt install sudo -y >/dev/null 2>&1
green "[ √ ] Sudo checked! "
apt install make -y >/dev/null 2>&1
green "[ √ ] Make checked! "
apt install firewalld -y >/dev/null 2>&1
green "[ √ ] Firewalld checked! "
}
# install go 1.12.6 ok
function install_go() {
yellow "[ - ] Start installing go 1.12.6"
sleep 0.5s
bar_start_from 0
mkdir /opt/new_ngrok >/dev/null 2>&1
cd /opt/new_ngrok/ >/dev/null
get_release
bar_hold_at 50 "downloading go packages" &
if [ "$CONF" == "32" ]; then
if [ "${CPU%v}" == "arm" -o "${CPU%v}" == "ARM" ]; then # arm arm32
go_pack="/opt/new_ngrok/go1.12.6.linux-armv6l.tar.gz"
if [ ! -f "/opt/new_ngrok/$go_pack" ]; then
wget -P /opt/new_ngrok/ -q -c https://golang.google.cn/dl/go1.12.6.linux-armv6l.tar.gz
else
yellow "[ * ] $go_pack detected,skip downloading "
fi
else #x86/amd 32
go_pack="/opt/new_ngrok/go1.12.6.linux-386.tar.gz"
if [ ! -f "/opt/new_ngrok/$go_pack" ]; then
wget -P /opt/new_ngrok/ -q -c https://golang.google.cn/dl/go1.12.6.linux-386.tar.gz
else
yellow "[ * ] $go_pack detected,skip downloading "
fi
fi
elif [ "$CONF" == "64" ]; then
if [ "${CPU%64}" == "aarch" -o "${CPU%64}" == "arm" ]; then # arm arm64
go_pack="/opt/new_ngrok/go1.12.6.linux-arm64.tar.gz"
if [ ! -f "/opt/new_ngrok/$go_pack" ]; then
wget -P /opt/new_ngrok/ -q -c https://golang.google.cn/dl/go1.12.6.linux-arm64.tar.gz
else
yellow "[ * ] $go_pack detected,skip downloading "
fi
else # x86/amd 64
go_pack="/opt/new_ngrok/go1.12.6.linux-amd64.tar.gz"
if [ ! -f "/opt/new_ngrok/$go_pack" ]; then
wget -P /opt/new_ngrok/ -q -c https://golang.google.cn/dl/go1.12.6.linux-amd64.tar.gz
else
yellow "[ * ] $go_pack detected,skip downloading "
fi
fi
else
bar_continue
red "[ x ] cannot download go 1.12.6,please download it mannually and place it into /opt/new_ngrok"
red "[ x ] Link: https://golang.google.cn/dl/ "
red "[ x ] Notes: the version of go should be 1.12.6 "
exit_program
fi
bar_continue
bar_start_from 50
bar_hold_at 90 "installing go 1.12.6" &
cd /opt/new_ngrok/
tar -C /opt/new_ngrok/ -xzf $go_pack >/dev/null
export PATH=$PATH:/opt/new_ngrok/go/bin
bar_continue
# bar_start_from 90
bar_hold_at 95 "checking installation" &
if [[ `go version | grep "1.12.6"` != "" ]]; then
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] Go installation completed! "
else
bar_continue
red "[ x ] Go installation failed! Please uninstall the current go environment before continue! "
exit_program
fi
}
# check go ok
function check_go() {
yellow "[ * ] Start go environment checking"
cd /opt/new_ngrok/ && go version 2> /opt/new_ngrok/log/ngrok_log.log >/dev/null
if cat $log_file | grep "go" > /dev/null; then
# if [ $? -eq 0 ]; then
red "[ × ] Cannot detected go "
:> $log_file
sleep 0.5s
install_go
elif [[ `go version | grep "1.12.6"` != "" ]]; then
green "[ √ ] Go checked, the version is 1.12.6 "
else
blue "[ - ] Go checked, but the version is not 1.12.6 "
blue "[ - ] Uninstallation command will start before installing go 1.12.6 "
yellow "[ - ] Uninstalling go"
bar_start_from 0
bar_hold_at 60 "uninstalling golang-go" &
apt-get remove golang-go >/dev/null
apt-get remove --auto-remove golang-go >/dev/null
bar_continue
bar_hold_at 90 "uninstalling gccgo-go" &
apt-get remove gccgo-go >/dev/null
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] 原有go环境卸载完成 "
install_go
fi
}
# check environment
function check_environment() {
yellow "[ - ] Do you want to check environment?(y/n)"
read option_environment
if [[ $option_environment == "y" ]]||[[ $option_environment == "Y" ]]; then
echo "[ * ] Start environment checking"
bar_start_from 0
bar_hold_at 20 "log checking" &
check_log
bar_continue
bar_start_from 20
bar_hold_at 30 "release checking" &
check_release
bar_continue
bar_start_from 30
bar_hold_at 40 "network checking" &
check_network
bar_continue
bar_start_from 40
bar_hold_at 50 "tools checking" &
check_tools
bar_continue
# bar_start_from 50
# bar_hold_at 60 "firewalld checking" &
# check_firewalld
# bar_continue
bar_start_from 50
bar_hold_at 70 "git checking" &
check_git
bar_continue
bar_start_from 70
bar_hold_at 100 "done!"
green "[ √ ] Environment check completed! "
elif [[ $option_environment == "n" ]]||[[ $option_environment == "N" ]]; then
green "[ * ] Environment check jumped "
else
red "[ x ] error! Exiting program"
exit_program
fi
}
check_domain() {
echo "[ * ] Start checking domain information"
green "[ - ] =========Please Input Domain Name========="
green "[ - ] 注: Please input the domain name which resolved to this server"
read ngrokd_domain
yellow "[ - ] Domain: $ngrokd_domain"
yellow "[ - ] Please confirm(y/n)"
read domain_confirm
while [ $domain_confirm == "n" ]||[ $domain_confirm == "N" ]
do
green "[ * ] Please input domain name again: "
read ngrokd_domain
yellow "[ - ] Domain: $ngrokd_domain"
yellow "[ - ] Please confirm(y/n)"
read domain_confirm
done
export NGROK_DOMAIN="$ngrokd_domain"
ip_domain=`ping $ngrokd_domain -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'`
ip_local=`curl ipv4.icanhazip.com`
blue "================================="
blue " domain_ip: $ip_domain"
blue " current_ip: $ip_local"
blue "================================="
sleep 1s
if [[ $ip_domain == $ip_local ]]; then
green "[ √ ] Domain checked"
else
red "[ x ] DNS error!"
red "[ x ] Please check domain name and ip address before running script!"
exit_program
fi
}
# git clone
git_clone() {
bar_start_from 0
bar_hold_at 70 "git cloning" &
cd /usr/local
git clone https://github.com/inconshreveable/ngrok.git >/dev/null
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] Program has been cloned to /usr/local"
}
# git clone check (whether to jump)
check_git_clone() {
echo "[ * ] Checking program files"
if [ ! -f "/usr/local/ngrok/Makefile" ]; then
echo "[ * ] Cannot find program files. Now start downloading, please keep this server online"
echo "[ * ] Default path: /usr/local"
git_clone
else
yellow "[ - ] Package detected. Please Select: "
yellow "[ - ] 1) (recommend) Download and overwrite current package"
yellow "[ - ] 2) Skip downloading"
read clone_options
case $clone_options in
1) # overwrite
git_clone
;;
2) # skip downloading
green "[ √ ] skip downloading, installation will start in a moment"
;;
*)
red "[ x ] Option error!"
;;
esac
fi
}
conf_port_menu2() {
green "[ - ] ========= Please Select ========="
yellow "[ - ] 1) Automatically"
yellow "[ - ] 2) Mannually"
read port_option
case $port_option in
1) # Automatically
port1=80
port2=443
port3=4443
;;
2) # Mannually
yellow "[ - ] Please Input Port of http: "
read port1
yellow "[ - ] Please Input Port of https: "
read port2
yellow "[ - ] Please Input Port of tunnels: "
read port3
;;
*)
red "Option Error!"
exit_program
;;
esac
}
# install new server
menu_server_1() {
green "Preparing Ngrok Server Installation"
check_environment
apt_update
check_go
check_domain
check_git_clone
git config --global http.sslverify false
echo "[ * ] Start install Ngrok Server"
bar_start_from 0
# generating CA certs
echo "[ * ] Start generating CA certs"
bar_hold_at 65 "generating CA certs" &
cd /usr/local/ngrok
openssl genrsa -out rootCA.key 2048 >/dev/null
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem >/dev/null
openssl genrsa -out device.key 2048 >/dev/null
openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr >/dev/null
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000 >/dev/null
bar_continue
# replace CA certs
bar_hold_at 95 "replacing certs" &
cp /usr/local/ngrok/rootCA.pem /usr/local/ngrok/assets/client/tls/ngrokroot.crt >/dev/null
cp /usr/local/ngrok/device.crt /usr/local/ngrok/assets/server/tls/snakeoil.crt >/dev/null
cp /usr/local/ngrok/device.key /usr/local/ngrok/assets/server/tls/snakeoil.key >/dev/null
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] Certs generated! "
# compile server
echo "[ * ] compiling Ngrok Server"
bar_start_from 0
bar_hold_at 95 "compiling Ngrok Server" &
cd /usr/local/ngrok
make clean >/dev/null
make release-server >/dev/null
bar_continue
bar_hold_at 100 "done!"
green "[ √ ] Ngrok Server Successfully Installed!"
# port configuration
cd /usr/local/ngrok/bin
echo "[ * ] Start Configure Port"
echo "[ * ] -----------------------"
echo "[ * ] Tips: Here we need to configure 3 ports on Server:"
echo "[ * ] 1) http"
echo "[ * ] 2) https"
echo "[ * ] 3) tunnel: including tcp | udp, could be used on ssh"
echo "[ * ] -----------------------"
echo "[ * ] If you select Automatically in this step, the configuration will be: "
echo "[ * ] http: 80 "
echo "[ * ] https: 443 "
echo "[ * ] tunnel: 4443 "
echo "[ * ] (this configuration is editiable)"
conf_port_menu2
# port confirm
yellow "[ - ] ====================================="
yellow "[ - ] Here is information of port(server): "
yellow "[ - ] http: $port1"
yellow "[ - ] https: $port2"
yellow "[ - ] tunnel: $port3"
yellow "[ - ] ======================================"
yellow "[ - ] Please confirm (y/n)"
read port_confirm
while [ $port_confirm == "n" ]||[ $port_confirm == "N" ]
do
conf_port_menu2
yellow "[ - ] ====================================="
yellow "[ - ] Here is information of port(server): "
yellow "[ - ] http: $port1"
yellow "[ - ] https: $port2"
yellow "[ - ] tunnel: $port3"
yellow "[ - ] ======================================"
yellow "[ - ] Please confirm (y/n)"
read port_confirm
done
green "[ √ ] Port confirmed! "
#writing into systemd
echo "Start installing server"
bar_start_from 0
bar_hold_at 20 "writing into systemd" &
mkdir -p /usr/lib/systemd/system >/dev/null
cat > /usr/lib/systemd/system/ngrokd.service <<-EOF
[Unit]
Description=ngrokd service
[Service]
Type=simple
ExecStart=/usr/local/ngrok/bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":$port1" -httpsAddr=":$port2" -tunnelAddr=":$port3"
[Install]
WantedBy=multi-user.target
EOF
bar_continue
green "[ √ ] Successfully written into systemd!"
# firewall release
bar_hold_at 60 "releasing firewall" &
firewall-cmd --add-port=$port1/tcp --permanent >/dev/null
firewall-cmd --add-port=$port1/udp --permanent >/dev/null
firewall-cmd --add-port=$port2/tcp --permanent >/dev/null
firewall-cmd --add-port=$port2/udp --permanent >/dev/null
firewall-cmd --add-port=$port3/tcp --permanent >/dev/null
firewall-cmd --add-port=$port3/udp --permanent >/dev/null
firewall-cmd --reload >/dev/null
bar_continue
green "[ √ ] Port released!"
# initiating server
bar_hold_at 95 "initiating server" &
systemctl start ngrokd >/dev/null
systemctl enable ngrokd >/dev/null
systemctl daemon-reload >/dev/null
bar_continue
bar_hold_at 100 "ok"
green "[ √ ] 服务端已在后台启动"
green "[ * ] Tips: 可重新运行本脚本,继续选择编译客户端"
exit_program
}
# make client