-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinstall.sh
1672 lines (1469 loc) · 59.5 KB
/
install.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
# --------------------------------------------------------------------------------------------
# Armour install script
# --------------------------------------------------------------------------------------------
#
# Usage:
# ./install.sh [option]
#
# -i Install Armour (and optionally, eggdrop)
# -a Add a new bot to existing Armour install
# -l Load Armour on an existing eggdrop with Armour already configured
# -h, --help Display script options
#
# --------------------------------------------------------------------------------------------
#
# Tested on:
# - Debian 12
# - CentOS 9
# - Ubuntu 23.10
# - FreeBSD 13.1
# - macOS 14.3
#
# --------------------------------------------------------------------------------------------
# https://armour.bot/setup
# --------------------------------------------------------------------------------------------
ARMOUR_VER="v4.0"
ARMOUR_GIT="https://github.com/empus/armour"
EGGDROP_VER="1.9.5"
EGGDROP_URL="https://ftp.eggheads.org/pub/eggdrop/source/1.9/eggdrop-1.9.5.tar.gz"
set -u
shopt -s nocasematch # -- case insensitive matching
stty erase '^?' # -- fix backspace with 'read'
abort() {
printf "%s\n" "$@" >&2
exit 1
}
# -- bash required
if [ -z "${BASH_VERSION:-}" ]; then
abort "Bash is required to interpret this script."
fi
# -- string formatters
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_underline="$(tty_escape "4;39")"
tty_red="$(tty_mkbold 31)"
tty_green="$(tty_mkbold 32)"
tty_yellow="$(tty_mkbold 33)"
tty_blue="$(tty_mkbold 34)"
tty_bold="$(tty_mkbold 39)"
tty_reset="$(tty_escape 0)"
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"
do
printf " "
printf "%s" "${arg// /\ }"
done
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
}
warn() {
printf "${tty_yellow}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2
}
# -- error checker
check_error() {
if [ $? -ne 0 ]; then
ring_bell
return 1
else
return 0
fi
}
# -- check the OS
OS="$(uname)"
if [[ "${OS}" == "Linux" ]]; then
ARMOUR_ON_LINUX=1
elif [[ "${OS}" == "FreeBSD" ]]; then
SYSTEM="FreeBSD"
ARMOUR_ON_BSD=1
elif [[ "${OS}" == "OpenBSD" ]]; then
ARMOUR_ON_BSD=1
SYSTEM="OpenBSD"
elif [[ "${OS}" == "NetBSD" ]]; then
ARMOUR_ON_BSD=1
SYSTEM="NetBSD"
elif [[ "${OS}" == "Darwin" ]]; then
ARMOUR_ON_MACOS=1
else
echo "${tty_red}Error:${tty_reset} Armour install script is only ${tty_yellow}currently{$tty_reset} supported on Linux, FreeBSD, NetBSD, OpenBSD, and macOS"
abort
fi
# -- set OS specific package manager and packages
MD5="md5sum"
PKG_OATHTOOL="oathtool"
PKG_IMAGEMAGICK="imagemagick"
GNUSED=1
if [[ -n "${ARMOUR_ON_LINUX-}" ]]; then
# -- Linux default to apt-get
SYSTEM="Linux"
PKGMGR="apt-get"
PKGMGR_ARGS="install -y"
PACKAGES="gcc curl git tcl tcl-dev tcllib tcl-tls sqlite3 libsqlite3-tcl"
if [ -f /etc/centos-release ]; then
# -- CentOS
SYSTEM="CentOS"
PKGMGR="yum"
PKGMGR_ARGS="install -y"
PACKAGES="gcc epel-release curl git tcl tcl-devel tcltls sqlite-devel"
PKG_IMAGEMAGICK="ImageMagick"
else
if [ -f "/etc/os-release" ]; then
if grep -q "^ID=ubuntu" "/etc/os-release"; then
# -- Ubuntu
SYSTEM="Ubuntu"
PKGMGR="apt-get"
PKGMGR_ARGS="install -y"
PACKAGES="gcc make curl git tcl tcl-dev tcllib tcl-tls sqlite3 libsqlite3-tcl"
fi
fi
fi
elif [[ -n "${ARMOUR_ON_BSD-}" ]]; then
PKGMGR="pkg"
PKGMGR_ARGS="install -y"
PACKAGES="curl git tcl tcllib tcltls sqlite3 tcl-sqlite3"
PKG_IMAGEMAGICK="ImageMagick7"
MD5="md5"
GNUSED=0
elif [[ -n "${ARMOUR_ON_MACOS-}" ]]; then
SYSTEM="macOS"
PKGMGR="brew"
PKGMGR_ARGS="install"
#PACKAGES="curl git tcl tcllib tcltls sqlite3 tcl-sqlite3 oath-toolkit imagemagick"
PACKAGES="curl git tcl sqlite3 oath-toolkit imagemagick"
PKG_OATHTOOL="oath-toolkit"
MD5="md5"
GNUSED=0
fi
execute() {
if ! "$@"
then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi
}
# -- read user input
getc() {
local save_state
save_state="$(/bin/stty -g)"
/bin/stty raw -echo
IFS='' read -r -n 1 -d '' "$@"
/bin/stty "${save_state}"
}
# -- ring audible shell bell
ring_bell() {
if [[ -t 1 ]]; then
printf "\a"
fi
}
wait_for_user() {
local c
echo
echo "Press ${tty_bold}RETURN${tty_reset}/${tty_bold}ENTER${tty_reset} to begin, or any other key to abort:"
getc c
# -- test for \r and \n because some stuff does \r instead
if ! [[ "${c}" == $'\r' || "${c}" == $'\n' ]]; then
exit 1
fi
}
# -- check if prerequisites will be installed
ASKED=0
ask_for_prereq() {
local input
echo
ohai "Do you wish to install prerequisite packages and tools? (${tty_green}Y${tty_reset})es or (${tty_green}N${tty_reset})o"
echo
echo " sudo ${PKGMGR} ${PKGMGR_ARGS} ${PACKAGES}"
echo
getc input
if [[ "${input}" == 'y' ]]
then
install_prereq
elif [[ "${input}" == 'n' ]]
then
warn "Not installing prerequisite TCL packages and tools. Armour will not run if these are not already installed."
if [[ "${ASKED}" -eq 1 ]]
then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} You must install the prerequisites before installing Armour. See:"
echo " ${tty_underline}https://armour.bot/setup/install/#requirements${tty_reset}"
abort
fi
echo
else
ring_bell
warn "Invalid input, please select (Y)es or (N)o"
echo
ask_for_prereq
fi
}
# -- check for sudo
check_sudo() {
if ! command -v sudo >/dev/null
then
ring_bell
echo "${tty_red}Error:${tty_reset} You must install ${tty_bold}sudo${tty_reset} to install prerequisites from this script."
abort
fi
}
# -- install the prerequisites
install_prereq() {
check_sudo
ohai "Installing prerequisites..."
if [[ "${SYSTEM}" != "macOS" ]]; then
ohai "sudo ${PKGMGR} ${PKGMGR_ARGS} ${PACKAGES}"
sudo ${PKGMGR} ${PKGMGR_ARGS} ${PACKAGES}
return_code=$?
else
# -- macOS: don't run brew as root
ohai "${PKGMGR} ${PKGMGR_ARGS} ${PACKAGES}"
${PKGMGR} ${PKGMGR_ARGS} ${PACKAGES}
return_code=$?
fi
if [ ! $return_code -eq 0 ]; then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} failed package install. Please correct and try again."
echo
abort
fi
echo
ohai "Done!"
echo
}
# -- check if prerequisites exist
check_prereqs() {
# -- check for cURL
CURL=`command -v curl`
ohai "CURL: ${CURL}"
if [ "${CURL}" == "" ]; then
ring_bell
echo
echo "${tty_red}Error:${tty_reset} You must install ${tty_bold}cURL${tty_reset} before installing Armour. See:"
echo " ${tty_underline}https://armour.bot/setup/install/#requirements${tty_reset}"
ask_for_prereq
fi
# -- check for Git
GIT=`command -v git`
ohai "GIT: ${GIT}"
if [ "${GIT}" == "" ]; then
ring_bell
echo
echo "${tty_red}Error:${tty_reset} You must install ${tty_bold}Git${tty_reset} before installing Armour. See:"
echo " ${tty_underline}https://armour.bot/setup/install/#requirements${tty_reset}"
ASKED=1
ask_for_prereq
fi
# -- check for oathtool
OATHTOOL=`command -v oathtool`
ohai "OATHTOOL: ${OATHTOOL}"
#if [ "${OATHTOOL}" == "" ]; then
# ring_bell
# echo
# echo "${tty_red}Error:${tty_reset} You must install ${tty_bold}oathtool${tty_reset} before installing Armour. See:"
# echo " ${tty_underline}https://armour.bot/setup/install/#requirements${tty_reset}"
# ASKED=1
# ask_for_prereq
#fi
# -- check for ImageMagick
CONVERT=`command -v convert`
ohai "CONVERT: ${CONVERT}"
#if [ ${CONVERT} == "" ]; then
# ring_bell
# ehco
# echo "${tty_red}Error:${tty_reset} You must install ${tty_bold}ImageMagick7${tty_reset} before installing Armour. See:"
# echo " ${tty_underline}https://armour.bot/setup/install/#requirements${tty_reset}"
# ASKED=1
# ask_for_prereq
#fi
}
# -- check if eggdrop needs installing
NEW_EGGDROP=false
ask_for_eggdrop() {
local input
echo
ohai "Is this for a (${tty_green}N${tty_reset})ew or (${tty_green}E${tty_reset})xisting ${tty_bold}eggdrop${tty_reset} installation?"
echo
echo " Selecting ${tty_green}N${tty_reset} will download, install, and configure ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset} before then downloading, installing, and configuring Armour ${ARMOUR_VER}"
echo " Selecting ${tty_green}E${tty_reset} will install Armour ${ARMOUR_VER} to an ${tty_bold}existing${tty_reset} eggdrop installation."
echo
getc input
if [[ "${input}" == 'n' ]]; then
NEW_EGGDROP=true
download_eggdrop
elif [[ "${input}" == 'e' ]]; then
existing_eggdrop
else
ring_bell
warn "Invalid input, please select (${tty_green}N${tty_reset})ew or (${tty_green}E${tty_reset})xisting"
echo
ask_for_eggdrop
fi
}
# -- check which eggdrop install directory to use
ARMOUR_LOADING=false
ask_for_eggdrop_dir() {
local input
ohai "What eggdrop installation directory should be used? [${tty_green}${HOME}/bots${tty_reset}]"
echo
read input
EGGDROP_INSTALL_DIR=${input}
if [ "${EGGDROP_INSTALL_DIR}" == "" ]; then
EGGDROP_INSTALL_DIR="${HOME}/bots"
fi
echo
ohai "Using eggdrop install directory: ${tty_green}${EGGDROP_INSTALL_DIR}${tty_reset}"
if [ -d ${EGGDROP_INSTALL_DIR} ]; then
# -- chosen eggdrop install directory exists
if [ ${NEW_EGGDROP} == true ]; then
# -- new eggdrop install but directory already exists
ring_bell
echo
echo "${tty_red}Error:${tty_reset} new eggdrop install directory ${EGGDROP_INSTALL_DIR} already exists. Please either:"
echo " - Delete, move or rename this directory; ${tty_bold}or${tty_reset}"
echo " - Run this script for an ${tty_green}existing${tty_reset} eggdrop installation; ${tty_bold}or${tty_reset}"
echo " - Choose another eggdrop installation directory."
echo
ask_for_eggdrop_dir
elif [ ! -f "${EGGDROP_INSTALL_DIR}/eggdrop" ]; then
# -- install directory exists but eggdrop binary does not
ring_bell
echo
echo "${tty_red}Error:${tty_reset} chosen eggdrop install directory ${EGGDROP_INSTALL_DIR} does not contain ${tty_bold}eggdrop${tty_reset} binary. Please either:"
echo " - Choose another eggdrop installation directory; ${tty_bold}or${tty_reset}"
echo " - Run this script again after eggdrop is propery installed; ${tty_bold}or${tty_reset}"
echo " - Run this script again and select to create a ${tty_green}new${tty_reset} eggdrop install"
echo
ask_for_eggdrop_dir
fi
else
if [ ${NEW_EGGDROP} == false ]; then
# -- existing eggdrop, but directory doesn't exist
ring_bell
echo
echo "${tty_red}Error:${tty_reset} existing eggdrop install directory ${EGGDROP_INSTALL_DIR} doesn't exist. Please either:"
echo " - Choose another eggdrop installation directory; ${tty_bold}or${tty_reset}"
echo " - Run this script again and select a new eggdrop installation"
echo
ask_for_eggdrop_dir
fi
fi
echo
}
# -- user has selected to use an existing eggdrop installation
existing_eggdrop() {
ask_for_eggdrop_dir
ask_for_botname
configure_eggdrop
install_armour
configure_armour
start_eggdrop
show_success
}
# -- new eggdrop installation
download_eggdrop() {
ohai "Installing ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset}..."
echo
EGGDROP_FILE=$(basename ${EGGDROP_URL})
if [ ! -f ${EGGDROP_FILE} ]; then
ohai "Downloading ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset} from ${EGGDROP_URL}"
echo
curl --progress-bar ${EGGDROP_URL} --output ${EGGDROP_FILE}
echo
ohai "Done!"
echo
else
ohai "${tty_bold}${EGGDROP_FILE}${tty_reset} already exists in this directory..."
echo
fi
EGGDROP_DIR="${EGGDROP_FILE%.tar.gz}"
if [ -d ${EGGDROP_DIR} ]; then
ring_bell
echo "${tty_red}Error:${tty_reset} directory ${EGGDROP_DIR} already exists in this location. Please either:"
echo " - Delete, move or rename this directory; ${tty_bold}or${tty_reset}"
echo " - Run this script for an existing eggdrop installation; ${tty_bold}or${tty_reset}"
echo " - Run this script from another location."
abort
fi
ohai "Extracting ${EGGDROP_FILE}..."
tar -xf ${EGGDROP_FILE}
echo
ohai "Done!"
echo
build_eggdrop
}
# -- configure, compile, and install eggdrop
build_eggdrop() {
ask_for_eggdrop_dir
ohai "Building ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset} ..."
cd ${EGGDROP_DIR}
./configure --prefix=${EGGDROP_INSTALL_DIR}
return_code=$?
if [ ! $return_code -eq 0 ]; then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} eggdrop configure script failed. Please check logs and try again. Delete the ${EGGDROP_DIR} directory to allow retry."
echo
abort
fi
echo
ohai "Compiling ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset} ..."
echo
make config && make
return_code=$?
if [ ! $return_code -eq 0 ]; then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} eggdrop compilation failed. Please check logs and try again. Delete the ${tty_bold}${EGGDROP_DIR}${tty_reset} directory to allow retry."
echo
abort
fi
echo
ohai "Installing ${tty_bold}eggdrop ${EGGDROP_VER}${tty_reset} to ${tty_bold}${EGGDROP_INSTALL_DIR}${tty_reset} ..."
echo
make install
return_code=$?
if [ ! $return_code -eq 0 ]; then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} eggdrop installation failed. Please check logs and try again. Delete the ${tty_bold}${EGGDROP_DIR}${tty_reset} directory to allow retry."
echo
abort
fi
echo
}
# -- get the name of the bot
ask_for_botname() {
local input
ohai "What is the name of your bot?"
echo
read input
BOTNAME=${input}
if [ "${BOTNAME}" == "" ]; then
ask_for_botname
fi
ARMOUR_INSTALL_DIR="${EGGDROP_INSTALL_DIR}/armour"
if [[ -f "${ARMOUR_INSTALL_DIR}/${BOTNAME}.conf" && ${ARMOUR_LOADING} == false ]]; then
echo
ring_bell
echo "${tty_red}Error:${tty_reset} Armour configuration file ${tty_green}${ARMOUR_INSTALL_DIR}/${BOTNAME}.conf${tty_reset} already exists. Please choose another bot name."
echo
ask_for_botname
fi
}
# -- ask for network to automate some settings
ask_for_network() {
local input
ohai "Which IRC network is this bot connecting to?"
echo " ${tty_green}1${tty_reset}: Undernet"
echo " ${tty_green}2${tty_reset}: DALnet"
echo " ${tty_green}3${tty_reset}: Other"
echo
getc input
if [ "${input}" == '1' ]; then
NETWORK="Undernet"
IRCU=1
elif [ "${input}" == '2' ]; then
NETWORK="DALnet"
elif [ "${input}" == '3' ]; then
NETWORK="Other"
else
ring_bell
warn "IRC network must be set. Please try again."
echo
ask_for_network
fi
ohai "Set network to: ${tty_green}${NETWORK}${tty_reset}"
echo
}
# -- setup eggdrop config file
configure_eggdrop() {
cd ${EGGDROP_INSTALL_DIR}
ohai "Configuring ${tty_bold}eggdrop${tty_reset} ..."
echo
ohai "Copying ${tty_green}armour/eggdrop.conf.sample${tty_reset} to ${tty_green}./${BOTNAME}.conf${tty_reset} ..."
cp armour/eggdrop.conf.sample ./${BOTNAME}.conf
echo
if [ ! -d "${EGGDROP_INSTALL_DIR}/db" ]; then
mkdir "${EGGDROP_INSTALL_DIR}/db"
ohai "Created ${tty_green}${EGGDROP_INSTALL_DIR}/db${tty_reset} directory"
echo
fi
check_eggdrop_settings
}
# -- clone Armour from GitHub
install_armour() {
cd ${EGGDROP_INSTALL_DIR}
if [ -d "armour" ]; then
# -- armour directory already exists
ring_bell
echo
echo "${tty_red}Error:${tty_reset} the directory ${tty_green}armour${tty_reset} already exists."
local input
echo
ohai "Do you wish to ${tty_green}D${tty_reset})elete the directory, (${tty_green}B${tty_reset})ackup the directory, or (${tty_green}E${tty_reset})xit?"
echo
getc input
if [ "${input}" == 'e' ]; then
echo "${tty_red}Error:${tty_reset} Armour installation halted."
echo
abort
elif [ "${input}" == 'd' ]; then
rm -rf armour
elif [ "${input}" == 'b' ]; then
mv armour armour-old
warn "Created backup of original ${tty_green}armour${tty_reset} directory to ${tty_green}armour-old${tty_reset}"
echo
else
install_armour
fi
fi
echo
ohai "Cloning ${tty_green}Armour ${ARMOUR_VER}${tty_reset} from GitHub..."
echo
${GIT} clone ${ARMOUR_GIT}
echo
cd armour
ohai "Copying ${tty_green}armour/armour.conf.sample${tty_reset} to ${tty_green}armour/${BOTNAME}.conf${tty_reset} ..."
echo
cp armour.conf.sample ${BOTNAME}.conf
}
# -- configure Armour *.conf settings
configure_armour() {
ohai "Configuring settings in ${tty_green}armour/${BOTNAME}.conf${tty_reset} ..."
echo
check_armour_settings
}
# -- describe Armour config settings
armour_setting() {
# -- value validation
BINARY=0
NOEMPTY=0
NUMERIC=0
echo
if [ $1 == "botname" ]; then
NOEMPTY=1
new_value="${BOTNAME}"
else
ohai "[${tty_blue}Setting${tty_reset}] ${tty_green}$setting_name${tty_reset}:"
fi
if [ $1 == "md5" ]; then
echo " The md5 utility on the machine for password hashing."
echo " Use md5 for ${tty_green}Linux${tty_reset} or ${tty_green}md5sum${tty_reset} for BSD machines"
NOEMPTY=1
elif [ $1 == "register" ]; then
echo " Allow users to register their own bot usernames using the ${tty_green}register${tty_reset} command? Enter ${tty_green}1${tty_reset} to enable or ${tty_green}0${tty_reset} to disable:"
echo " If the next ${tty_green}cfg(register:inchan)${tty_reset} setting includes channels, this command will only work for users inside the beloe channels."
NOEMPTY=1
BINARY=1
elif [ $1 == "register:inchan" ]; then
echo " If the above ${tty_green}cfg(register)${tty_reset} setting is set to ${tty_green}1${tty_reset}, only users in this space delimited list of channels can use the ${tty_green}register${tty_reset} command."
elif [ $1 == "ircd" ]; then
echo " The type of ircd used by servers on the IRC network this bot will connect to."
echo " ${tty_green}1${tty_reset}: ircu (e.g., Undernet, Quakenet, Unreal)"
echo " ${tty_green}2${tty_reset}: DALnet/IRCnet/EFnet"
echo " ${tty_green}3${tty_reset}: InspIRCd/Solanum/ircd-seven"
NOEMPTY=1
elif [ $1 == "znc" ]; then
echo " Does this bot connect to IRC using a znc bouncer? Enter ${tty_green}1${tty_reset} for yes, or ${tty_green}0${tty_reset} for no."
echo " This setting controls how the bot will change servers using the ${tty_green}jump${tty_reset} command."
BINARY=1
NOEMPTY=1
elif [ $1 == "realname" ]; then
echo " The IRC realname that the bot will display in /WHOIS"
elif [ $1 == "servicehost" ]; then
echo " The service host of network services such as X!cservice@undernet.org on Undernet"
NOEMPTY=1
elif [ $1 == "prefix" ]; then
echo " The character used to command the bot in channels."
echo " If, for example, the ${tty_green}prefix${tty_reset} was ${tty_green}c${tty_reset}, commands could be issued as: ${tty_green}c op MrBob${tty_reset}"
echo " ${tty_yellow}Tip${tty_reset}: do not use vowels for this command prefix as the bot could be too easily triggered inadvertently."
NOEMPTY=1
elif [ $1 == "chan:nocmd" ]; then
echo " Space delimited list of channels where the use of public commands is disallowed."
elif [ $1 == "chan:def" ]; then
echo " The default channel applied with applicabkle commands that do not specify a channel and the command was typed in privmsg, or from an unregistered channel"
echo " Consider this as your primary registered bot channel."
NOEMPTY=1
elif [ $1 == "chan:report" ]; then
echo " Reporting & diagnostic channel for the bot to send command usage, errors, and other information."
echo " This channel is intended to be private and mostly useful to only the bot owner. Leave unset if uninterested in this output."
elif [ $1 == "auth:user" ]; then
echo " The network username (or nickname where NickServ exists) that the bot uses to authenticate with networks services."
echo " Leave this value empty if the bot does not authenticate to network services."
elif [ $1 == "auth:pass" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set, what password is used for the bot to authenticate with network services."
NOEMPTY=1
elif [ $1 == "auth:totp" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set, this setting holds the 2FA secret key for network accounts using TOTP."
elif [ $1 == "auth:mech" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set, this setting specifies the mechanism to authenticate with network services,"
echo " ${tty_green}gnuworld${tty_reset}: GNUWorld services (such as X on Undernet)"
echo " ${tty_green}nickserv${tty_reset}: Networks that use nick registration with NickServ"
NOEMPTY=1
elif [ $1 == "auth:serv:nick" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set, this setting specifies the nickname of the service to authenticate to"
echo " e.g., ${tty_green}X${tty_reset} for Undernet or ${tty_green}NickServ${tty_reset} for a network such as DALnet"
NOEMPTY=1
elif [ $1 == "auth:serv:host" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set, this setting specifies the host of the {tty_green}cfg(auth:serv:nick)${tty_reset} service."
echo " e.g., ${tty_green}channels.undernet.org${tty_reset} for Undernet or ${tty_green}services.dal.net${tty_reset} DALnet"
NOEMPTY=1
elif [ $1 == "xhost:ext" ]; then
echo " The network username's hostname extension given to users with hidden hosts via the +x user mode."
echo " Only relevant when ${tty_green}cfg(auth:mech)${tty_reset} is set to ${tty_green}gnuworld${tty_reset}"
echo " e.g., Use ${tty_green}users.undernet.org${tty_reset} for Undernet"
NOEMPTY=1
elif [ $1 == "auth:hide" ]; then
echo " If ${tty_green}cfg(auth:mech)${tty_reset} is set to ${tty_green}gnuworld${tty_reset}, this setting defines whether or not to set usermode ${tty_green}+x${tty_reset} for host hiding."
echo " ${tty_green}1${tty_reset}: Enable host hiding"
echo " ${tty_green}0${tty_reset}: Disable host hiding"
NOEMPTY=1
BINARY=1
elif [ $1 == "auth:rand" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set and this setting is enabled, the bot will use a random nickname until authenticated with network services."
echo " ${tty_green}1${tty_reset}: Enable"
echo " ${tty_green}0${tty_reset}: Disable"
NOEMPTY=1
BINARY=1
elif [ $1 == "auth:wait" ]; then
echo " If ${tty_green}cfg(auth:user)${tty_reset} is set and this setting is enabled, the bot will wait to join channels until authenticated with network services."
echo " ${tty_green}1${tty_reset}: Enable"
echo " ${tty_green}0${tty_reset}: Disable"
NOEMPTY=1
BINARY=1
elif [ $1 == "ban" ]; then
echo " The ban mechanism to use when setting bans (except when stacking modes during floodnet detection)"
echo " ${tty_green}chan${tty_reset}: Set bans through the server"
echo " ${tty_green}X${tty_reset}: Set bans through the service bot defined in ${tty_green}cfg(auth:serv:nick)${tty_reset}"
NOEMPTY=1
NOEMPTY=1
elif [ $1 == "portscan" ]; then
echo " Defines whether or not to enable the port scanner for configured matching clients and the ${tty_green}scanport${tty_reset} command."
echo " ${tty_green}1${tty_reset}: Enable"
echo " ${tty_green}0${tty_reset}: Disable"
NOEMPTY=1
BINARY=1
fi
echo
}
ask_yes() {
local input
echo $@
getc input
if [ "$input" == "y" ]; then
return true
else
return false
fi
}
ask_for_setting_value() {
local setting_name
local current_value
setting_name=$1
current_value=$2
read -p " Enter new value for ${tty_green}$setting_name${tty_reset} (default value: ${tty_blue}$current_value${tty_reset}): " new_value </dev/tty
echo
if [[ "${NOEMPTY}" == "1" && "${new_value}" == "" ]]; then
# -- empty value
warn "Setting ${tty_green}$setting_name${tty_reset} must have a value."
echo
# -- ask if the user wants the defaults
if [[ "$new_value" == "" && "$current_value" != "" ]]; then
local input
read -p " Enter (${tty_green}Y${tty_reset})es or (${tty_green}N${tty_reset})o to use the default value: ${tty_blue}$current_value${tty_reset} " input </dev/tty
echo
if [ "${input}" == "y" ]; then
ohai "Using ${tty_green}$setting_name${tty_reset} default value of: ${tty_blue}$current_value${tty_reset}"
echo
new_value="${current_value}"
else
echo
ask_for_setting_value "$setting_name" "$current_value"
fi
else
ask_for_setting_value "$setting_name" "$current_value"
fi
elif [[ "${BINARY}" == "1" && "${new_value}" != "0" && "${new_value}" != "1" ]]; then
# -- not a binary value
warn "Setting ${tty_green}$setting_name${tty_reset} must have a ${tty_green}binary${tty_reset} value (${tty_green}0${tty_reset} or ${tty_green}1${tty_reset})."
echo
ask_for_setting_value "$setting_name" "$current_value"
elif [[ "${NUMERIC}" == "1" && ! "${new_value}" =~ ^[0-9]+$ ]]; then
# -- not a number
warn "Setting ${tty_green}$setting_name${tty_reset} must have a ${tty_green}numeric${tty_reset} value."
echo
ask_for_setting_value "$setting_name" "$current_value"
fi
}
eggdrop_setting() {
# -- value validation
BINARY=0
NOEMPTY=0
NUMERIC=0
echo
if [[ "$1" == "uservar" || "$1" == "nick" || "$1" == "botnet-nick" ]]; then
NOEMPTY=1
new_value="${BOTNAME}"
return
else
ohai "[${tty_blue}Setting${tty_reset}] ${tty_green}$setting_name${tty_reset}:"
fi
if [ $1 == "altnick" ]; then
echo " The alternate nickname on IRC when ${tty_green}${BOTNAME}${tty_reset} is taken."
NOEMPTY=1
elif [ $1 == "username" ]; then
echo " The ${tty_green}ident${tty_reset} used for the bot on IRC"
NOEMPTY=1
elif [ $1 == "owner" ]; then
echo " Your ${tty_green}owner${tty_reset} handle (user) in eggdrop"
NOEMPTY=1
elif [ $1 == "admin" ]; then
echo " The ${tty_green}admin${tty_reset} description used by the bot"
NOEMPTY=1
elif [ $1 == "network" ]; then
echo " The name of the IRC ${tty_green}network${tty_reset} the bot connects to.:"
NOEMPTY=1
elif [ $1 == "realname" ]; then
echo " The ${tty_green}realname${tty_reset} (gecos) field for the bot, shown in ${tty_green}/WHOIS${tty_reset})"
NOEMPTY=1
elif [ $1 == "offset" ]; then
echo " The ${tty_green}UTC${tty_reset} timezone offset for the bot. e.g., ${tty_green}+5${tty_reset}"
NOEMPTY=1
elif [ $1 == "listen-addr" ]; then
echo " The ${tty_green}listen address${tty_reset} used to accept bot and telnet connections on."
NOEMPTY=1
elif [ $1 == "vhost4" ]; then
echo " The ${tty_green}IPv4${tty_reset} bind address for outgoing IRC server connections."
NOEMPTY=1
elif [ $1 == "vhost6" ]; then
echo " The ${tty_green}IPv6${tty_reset} bind address for outgoing IRC server connections. Leave empty if not using IPv6."
elif [ $1 == "net-type" ]; then
echo " The ${tty_green}network type${tty_reset} of the IRC network. Options are:"
echo " ${tty_green}Undernet${tty_reset}"
echo " ${tty_green}DALnet${tty_reset}"
echo " ${tty_green}IRCnet${tty_reset}"
echo " ${tty_green}EFnet${tty_reset}"
echo " ${tty_green}Libera${tty_reset}"
echo " ${tty_green}Quakenet${tty_reset}"
echo " ${tty_green}Rizon${tty_reset}"
echo " ${tty_blue}Other${tty_reset}"
NOEMPTY=1
elif [ $1 == "servers" ]; then
echo " The space delimited ${tty_green}server(s)${tty_reset} to connect to on IRC"
NOEMPTY=1
elif [ $1 == "_port" ]; then
echo " The ${tty_green}port number${tty_reset} >1024 to use for incoming botnet and telnet connections."
NOEMPTY=1
NUMERIC=1
elif [ $1 == "_oidentd" ]; then
echo " Does this box use ${tty_green}oidentd${tty_reset} for IRC identd requests?"
echo " ${tty_green}0${tty_reset}: No"
echo " ${tty_green}1${tty_reset}: Yes"
NOEMPTY=1
BINARY=1
fi
echo
}
REALNAME=""
check_eggdrop_settings() {
ohai "Eggdrop settings ..."
echo
SETTING_LIST="uservar nick altnick botnet-nick username owner admin network realname offset listen-addr vhost4 net-type servers"
cd ${EGGDROP_INSTALL_DIR}
EGGDROP_FILE="${BOTNAME}.conf"
# -- read the config file
while IFS= read -r line; do
# -- check for line match on pattern: set cfg(name) "value"
setting_name=""
current_value=""
extracted_info=$(echo "$line" | sed -E -n 's/^set[[:space:]]+([[:alnum:]_-]+)[[:space:]]+"?([^"]*)"?$/\1 \2/p')
if [ -n "$extracted_info" ]; then
setting_name=$(echo "$extracted_info" | cut -d' ' -f1)
current_value=$(echo "$extracted_info" | cut -d' ' -f2-)
# -- ignore settings which are not required for basic deployments
if [[ " $SETTING_LIST " != *" $setting_name "* ]]; then
continue;
fi
if [[ "$setting_name" == "uservar" || "$setting_name" == "nick" || "$setting_name" == "botnet-nick" ]]; then
new_value="${BOTNAME}"
ohai "Applying automatic value for ${tty_green}$setting_name${tty_reset}: ${tty_blue}$new_value${tty_reset}"
echo
else
# -- describe setting
eggdrop_setting "$setting_name"
# -- request new config value
ask_for_setting_value "$setting_name" "$current_value"
fi
# -- avoid asking for this later when configuring Armour
if [[ "$setting_name" == "realname" ]]; then
REALNAME="${new_value}"
fi
# -- new setting line
updated_line="set $setting_name \"$new_value\""
ohai "[${tty_blue}Updated${tty_reset}] config line: ${tty_green}$updated_line${tty_reset}"
echo
# -- replace the line
if [ ! $GNUSED ]; then
sed -i '' "s|^set $setting_name .*$|$updated_line|" "$EGGDROP_FILE"
else
sed -i "s|^set $setting_name .*$|$updated_line|" "$EGGDROP_FILE"
fi
fi
done < "$EGGDROP_FILE"
# -- do the 'listen' line
eggdrop_setting "_port"
ask_for_setting_value "port number" "1231"
if [ ! $GNUSED ]; then
sed -i '' "s|^listen .*$|listen $new_value all|" "$EGGDROP_FILE"
else
sed -i "s|^listen .*$|listen $new_value all|" "$EGGDROP_FILE"
fi
ohai "[${tty_blue}Updated${tty_reset}] config line: ${tty_green}listen $new_value all${tty_reset}"
echo
# -- ask about oidentd usage
eggdrop_setting "_oidentd"
ask_for_setting_value "oidentd" "0"
if [ "$new_value" == "1" ]; then
# -- load ident module and uncomment ident-method
if [ ! $GNUSED ]; then
sed -i '' "s|^\#loadmodule ident$|loadmodule ident|" "$EGGDROP_FILE"
else
sed -i "s|^\#loadmodule ident$|loadmodule ident|" "$EGGDROP_FILE"
fi
ohai "[${tty_blue}Updated${tty_reset}] config line: ${tty_green}loadmodule ident${tty_reset}"
echo
if [ ! $GNUSED ]; then
sed -i '' "s|^\#set ident-method 0|set ident-method 0|" "$EGGDROP_FILE"
else
sed -i "s|^\#set ident-method 0|set ident-method 0|" "$EGGDROP_FILE"
fi
ohai "[${tty_blue}Updated${tty_reset}] config line: ${tty_green}set ident-method 0${tty_reset}"
echo
fi
}
check_armour_settings() {
ohai "Armour settings ..."
echo
SETTING_LIST="botname md5 register register:inchan ircd znc realname servicehost prefix chan:nocmd chan:def chan:report auth:user auth:pass auth:totp auth:mech auth:serv:nick auth:serv:host xhost:ext auth:hide auth:rand auth:wait ban portscan"
NOAUTH=0
REGISTER=0
cd ${ARMOUR_INSTALL_DIR}
ARMOUR_FILE="${BOTNAME}.conf"
# -- read the config file
while IFS= read -r line; do
# -- check for line match on pattern: set cfg(name) "value"
if [[ "$line" =~ ^set\ cfg\(([^\)]+)\)\ \"?([^\"]*)\"?$ ]]; then
setting_name=$(echo "$line" | sed 's/.*cfg(\([^)]*\)).*/\1/')
current_value=$(echo "$line" | sed 's/.*cfg([^)]*)[[:space:]]*"\([^"]*\)".*/\1/;s/.*cfg([^)]*)[[:space:]]*\([^"]*\).*/\1/')
# -- ignore settings which are not required for basic deployments
if [[ " $SETTING_LIST " != *" $setting_name "* ]]; then
continue;
fi
# -- ignore cfg(register:inchan) if cfg(register) was not enabled
if [[ "${setting_name}" == "register:inchan" && "${REGISTER}" == "0" ]]; then
continue;
fi
# -- fallback to default value
new_value="${current_value}"
# -- set default values for Undernet
UNDERNET_DEFAULTS="ircd servicehost auth:mech auth:serv:nick auth:serv:host xhost:ext"
AUTH_SETTINGS="auth:pass auth:totp auth:mech auth:serv:nick auth:serv:host auth:hide auth:rand auth:wait"
DALNET_SETTINGS="ircd servicehost auth:mech auth:serv:nick auth:serv:host xhost:ext auth:hide auth:rand auth:wait auth:totp"
if [[ "${NETWORK}" == "Undernet" && " $UNDERNET_DEFAULTS " == *" $setting_name "* ]]; then
# -- Undernet: use defaults
ohai "Using default ${tty_green}Undernet${tty_reset} value for ${tty_green}$setting_name${tty_reset}: ${tty_blue}$current_value${tty_reset}"
echo
elif [[ "${NETWORK}" == "DALnet" && " $DALNET_SETTINGS " == *" $setting_name "* ]]; then
# -- DALnet: setup specific auth settings