-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
FOLIO-INSTALL.bash
executable file
·2419 lines (1589 loc) · 76.3 KB
/
FOLIO-INSTALL.bash
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
# Copyright 2014-2024 GPLv3, Open Crypto Tracker by Mike Kilday: Mike@DragonFrugal.com (leave this copyright / attribution intact in ALL forks / copies!)
ISSUES_URL="https://github.com/taoteh1221/Open_Crypto_Tracker/issues"
echo " "
echo "PLEASE REPORT ANY ISSUES HERE: $ISSUES_URL"
echo " "
echo "Initializing, please wait..."
echo " "
######################################
# EXPLICITLY set any dietpi paths
# Export too, in case we are calling another bash instance in this script
if [ -f /boot/dietpi/.version ]; then
PATH=/boot/dietpi:$PATH
export PATH=$PATH
fi
# EXPLICITLY set any ~/.local/bin paths
# Export too, in case we are calling another bash instance in this script
if [ -d ~/.local/bin ]; then
PATH=~/.local/bin:$PATH
export PATH=$PATH
fi
# EXPLICITLY set any /usr/sbin path
# Export too, in case we are calling another bash instance in this script
if [ -d /usr/sbin ]; then
PATH=/usr/sbin:$PATH
export PATH=$PATH
fi
# In case we are recursing back into this script (for filtering params etc),
# flag export of a few more basic sys vars if present
# Authentication of X sessions
export XAUTHORITY=~/.Xauthority
# Working directory
export PWD=$PWD
######################################
# Get date / time
DATE=$(date '+%Y-%m-%d')
TIME=$(date '+%H:%M:%S')
# Current timestamp
CURRENT_TIMESTAMP=$(date +%s)
# Are we running on Ubuntu OS?
IS_UBUNTU=$(cat /etc/os-release | grep -i "ubuntu")
# If a symlink, get link target for script location
# WE ALWAYS WANT THE FULL PATH!
if [[ -L "$0" ]]; then
SCRIPT_LOCATION=$(readlink "$0")
else
SCRIPT_LOCATION="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/"$(basename "$0")""
fi
# Now set path / file vars, after setting SCRIPT_LOCATION
SCRIPT_PATH="$( cd -- "$(dirname "$SCRIPT_LOCATION")" >/dev/null 2>&1 ; pwd -P )"
SCRIPT_NAME=$(basename "$SCRIPT_LOCATION")
# Parent directory of the script location
PARENT_DIR="$(dirname "$SCRIPT_LOCATION")"
# Get the operating system and version
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
...
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
# For setting user agent header in curl, since some API servers !REQUIRE! a set user agent OR THEY BLOCK YOU
CUSTOM_CURL_USER_AGENT_HEADER="User-Agent: Curl (${OS}/$VER; compatible;)"
######################################
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
if hash tput > /dev/null 2>&1; then
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
reset=`tput sgr0`
else
red=``
green=``
yellow=``
blue=``
magenta=``
cyan=``
reset=``
fi
######################################
# Get logged-in username (if sudo, this works best with logname)
TERMINAL_USERNAME=$(logname)
# If logname doesn't work, use the $SUDO_USER or $USER global var
if [ -z "$TERMINAL_USERNAME" ]; then
if [ -z "$SUDO_USER" ]; then
TERMINAL_USERNAME=$USER
else
TERMINAL_USERNAME=$SUDO_USER
fi
fi
if [ "$EUID" -ne 0 ] || [ "$TERMINAL_USERNAME" == "root" ]; then
echo " "
echo "${red}Please run as a NORMAL USER WITH 'sudo' PERMISSIONS (NOT LOGGED IN AS 'root').${reset}"
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to exit..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Exiting...${reset}"
echo " "
exit
fi
fi
######################################
if [ -f "/etc/debian_version" ]; then
echo "${cyan}Your system has been detected as Debian-based, which is compatible with this automated script."
# USE 'apt-get' IN SCRIPTING!
# https://askubuntu.com/questions/990823/apt-gives-unstable-cli-interface-warning
PACKAGE_INSTALL="sudo apt-get install"
PACKAGE_REMOVE="sudo apt-get --purge remove"
echo " "
echo "Continuing...${reset}"
echo " "
elif [ -f "/etc/redhat-release" ]; then
echo "${cyan}Your system has been detected as RedHat-based, which is ${red}CURRENTLY STILL IN DEVELOPMENT TO EVENTUALLY BE (BUT IS *NOT* YET) ${cyan}compatible with this automated script."
PACKAGE_INSTALL="sudo yum install"
PACKAGE_REMOVE="sudo yum remove"
echo " "
echo "Continuing...${reset}"
echo " "
else
echo "${red}Your system has been detected as NOT BEING Debian-based OR RedHat-based. Your system is NOT compatible with this automated script."
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to exit..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Exiting...${reset}"
echo " "
exit
fi
fi
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to continue..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Continuing...${reset}"
echo " "
fi
echo " "
######################################
# Path to app (CROSS-DISTRO-COMPATIBLE)
get_app_path() {
app_path_result=$(whereis -b $1)
app_path_result="${app_path_result#*$1: }"
app_path_result=${app_path_result%%[[:space:]]*}
app_path_result="${app_path_result#*$1:}"
# If we have found the library already installed on this system
if [ ! -z "$app_path_result" ]; then
PATH_CHECK_REENTRY="" # Reset reentry flag
echo "$app_path_result"
# If we are re-entering from the else statement below, quit trying, with warning sent to terminal (NOT function output)
elif [ ! -z "$PATH_CHECK_REENTRY" ]; then
PATH_CHECK_REENTRY="" # Reset reentry flag
echo "${red} " > /dev/tty
echo "System path for '$1' NOT FOUND, even AFTER package installation attempts, giving up." > /dev/tty
echo " " > /dev/tty
echo "*PLEASE* REPORT THIS ISSUE HERE, *IF THIS SCRIPT FAILS TO RUN PROPERLY FROM THIS POINT ONWARD*:" > /dev/tty
echo " " > /dev/tty
echo "$ISSUES_URL" > /dev/tty
echo "${reset} " > /dev/tty
echo "${yellow} " > /dev/tty
read -n1 -s -r -p $"PRESS ANY KEY to continue..." key
echo "${reset} " > /dev/tty
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " " > /dev/tty
echo "${green}Continuing...${reset}" > /dev/tty
echo " " > /dev/tty
fi
echo " " > /dev/tty
# If library not found, attempt package installation
else
# Handle package name exceptions...
# bsdtar on Ubuntu 18.x and higher
if [ "$1" == "bsdtar" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="libarchive-tools"
# xdg-user-dir (debian package name differs slightly)
elif [ "$1" == "xdg-user-dir" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="xdg-user-dirs"
# rsyslogd (debian package name differs slightly)
elif [ "$1" == "rsyslogd" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="rsyslog"
# xorg (debian package name differs)
elif [ "$1" == "xorg" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="xserver-xorg"
# chromium-browser (debian package name differs)
elif [ "$1" == "chromium-browser" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="chromium"
# epiphany-browser (debian package name differs)
elif [ "$1" == "epiphany-browser" ] && [ -f "/etc/debian_version" ]; then
SYS_PACK="epiphany"
else
SYS_PACK="$1"
fi
# Terminal alert for good UX...
if [ "$1" != "$SYS_PACK" ]; then
echo " " > /dev/tty
echo "${yellow}'$1' is found WITHIN '$SYS_PACK', changing package request accordingly...${reset}" > /dev/tty
echo " " > /dev/tty
fi
echo " " > /dev/tty
echo "${cyan}Installing required component '$SYS_PACK', please wait...${reset}" > /dev/tty
echo " " > /dev/tty
sleep 3
$PACKAGE_INSTALL $SYS_PACK -y > /dev/tty
# If UBUNTU (*NOT* any other OS) snap was detected on the system, try a snap install too
# (as they moved some libs over to snap / snap-only? now)
if [ ! -z "$UBUNTU_SNAP_PATH" ]; then
UBUNTU_SNAP_INSTALL="sudo $UBUNTU_SNAP_PATH install"
echo " " > /dev/tty
echo "${yellow}CHECKING FOR UBUNTU SNAP PACKAGE '$SYS_PACK', please wait...${reset}" > /dev/tty
echo " " > /dev/tty
sleep 3
$UBUNTU_SNAP_INSTALL $SYS_PACK > /dev/tty
fi
sleep 2
PATH_CHECK_REENTRY=1 # Set reentry flag, right before reentry
echo $(get_app_path "$1")
fi
}
# Ubuntu uses snaps for very basic libraries these days, so we need to configure for possible snap installs
if [ "$IS_UBUNTU" != "" ]; then
UBUNTU_SNAP_PATH=$(get_app_path "snap")
fi
######################################
# Make sure automatic suspend / sleep is disabled
if [ ! -f "${HOME}/.sleep_disabled.dat" ]; then
echo "${red}We need to make sure your system will NOT AUTO SUSPEND / SLEEP, or your app server could stop running.${reset}"
echo "${yellow} "
read -n1 -s -r -p $"PRESS F to fix this (disables auto suspend / sleep), OR any other key to skip fixing..." key
echo "${reset} "
if [ "$key" = 'f' ] || [ "$key" = 'F' ]; then
echo " "
echo "${cyan}Disabling auto suspend / sleep...${reset}"
echo " "
echo -e "ran" > ${HOME}/.sleep_disabled.dat
if [ -f "/etc/debian_version" ]; then
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target > /dev/null 2>&1
elif [ -f "/etc/redhat-release" ]; then
sudo -u gdm dbus-run-session gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0 > /dev/null 2>&1
fi
else
echo " "
echo "${green}Skipping...${reset}"
echo " "
fi
fi
######################################
# ON DEBIAN-BASED SYSTEMS ONLY:
# Do we have less than 900MB PHYSICAL RAM (IN KILOBYTES),
# AND no swap / less swap virtual memory than 900MB (IN BYTES)?
if [ -f "/etc/debian_version" ] && [ "$(awk '/MemTotal/ {print $2}' /proc/meminfo)" -lt 900000 ] && (
[ "$(free | awk '/^Swap:/ { print $2 }')" = "0" ] || [ "$(free --bytes | awk '/^Swap:/ { print $2 }')" -lt 900000000 ]
); then
echo "${red}YOU HAVE LESS THAN 900MB *PHYSICAL* MEMORY, AND ALSO HAVE LESS THAN 900MB SWAP *VIRTUAL* MEMORY. This MAY cause your system to FREEZE, *IF* you have a desktop display attached!${reset}"
echo "${yellow} "
read -n1 -s -r -p $"PRESS F to fix this (sets swap virtual memory to 1GB), OR any other key to skip fixing..." key
echo "${reset} "
if [ "$key" = 'f' ] || [ "$key" = 'F' ]; then
echo " "
echo "${cyan}Changing Swap Virtual Memory size to 1GB, please wait (THIS MAY TAKE AWHILE ON SMALLER SYSTEMS)...${reset}"
echo " "
# Required components check...
# dphys-swapfile
DPHYS_PATH=$(get_app_path "dphys-swapfile")
# sed
SED_PATH=$(get_app_path "sed")
sudo $DPHYS_PATH swapoff
sleep 5
if [ -f /etc/dphys-swapfile ]; then
DETECT_SWAP_CONF=$(sudo sed -n '/CONF_SWAPSIZE=/p' /etc/dphys-swapfile)
if [ "$DETECT_SWAP_CONF" != "" ]; then
sudo sed -i "s/CONF_SWAPSIZE=.*/CONF_SWAPSIZE=1024/g" /etc/dphys-swapfile
elif [ "$DETECT_SWAP_CONF" == "" ]; then
sudo bash -c "echo 'CONF_SWAPSIZE=1024' >> /etc/dphys-swapfile"
fi
sudo $DPHYS_PATH setup
sleep 5
sudo $DPHYS_PATH swapon
sleep 5
echo " "
echo "${green}Swap Memory size has been updated to 1GB.${reset}"
echo " "
else
echo " "
echo "${red}Swap Memory config file could NOT be located, skipping update of Swap Memory size!${reset}"
echo " "
fi
else
echo " "
echo "${green}Skipping...${reset}"
echo " "
fi
fi
######################################
# clean_system_update function START
clean_system_update () {
if [ -z "$ALLOW_FULL_UPGRADE" ]; then
echo " "
echo "${yellow}Does the Operating System on this device update using the \"Rolling Release\" model (Kali, Manjaro, Ubuntu Rolling Rhino, Debian Unstable, etc), or the \"Long-Term Release\" model (Debian, Ubuntu, Raspberry Pi OS, Armbian Stable, Diet Pi, etc)?"
echo " "
echo "${red}(You can SEVERLY MESS UP a \"Rolling Release\" Operating System IF YOU DO NOT CHOOSE CORRECTLY HERE! In that case, you can SAFELY choose \"I don't know\".)${reset}"
echo " "
echo "Enter the NUMBER next to your chosen option.${reset}"
echo " "
OPTIONS="rolling long_term i_dont_know"
select opt in $OPTIONS; do
if [ "$opt" = "long_term" ]; then
ALLOW_FULL_UPGRADE="yes"
echo " "
echo "${green}Allowing system-wide updates before installs.${reset}"
break
else
ALLOW_FULL_UPGRADE="no"
echo " "
echo "${green}Disabling system-wide updates before installs.${reset}"
break
fi
done
echo " "
fi
if [ -z "$PACKAGE_CACHE_REFRESHED" ]; then
if [ -f "/etc/debian_version" ]; then
echo "${cyan}Making sure your APT sources list is updated before installations, please wait...${reset}"
echo " "
# In case package list was ever corrupted (since we are about to rebuild it anyway...avoids possible errors)
sudo rm -rf /var/lib/apt/lists/* -vf > /dev/null 2>&1
sleep 2
sudo apt-get update
echo " "
echo "${cyan}APT sources list update complete.${reset}"
echo " "
fi
if [ "$ALLOW_FULL_UPGRADE" == "yes" ]; then
echo "${cyan}Making sure your system is updated before installations, please wait...${reset}"
echo " "
if [ -f "/etc/debian_version" ]; then
#DO NOT RUN dist-upgrade, bad things can happen, lol
sudo apt-get upgrade -y
elif [ -f "/etc/redhat-release" ]; then
sudo yum upgrade -y
fi
sleep 2
echo " "
echo "${cyan}System updated.${reset}"
echo " "
fi
PACKAGE_CACHE_REFRESHED=1
fi
}
# clean_system_update function END
# Clears / updates cache, then upgrades (if NOT a rolling release)
clean_system_update
######################################
# Get PRIMARY dependency lib's paths (for bash scripting commands...auto-install is attempted, if not found on system)
# (our usual standard library prerequisites [ordered alphabetically], for 99% of advanced bash scripting needs)
# avahi-daemon
AVAHID_PATH=$(get_app_path "avahi-daemon")
# bc
BC_PATH=$(get_app_path "bc")
# bsdtar
BSDTAR_PATH=$(get_app_path "bsdtar")
# curl
CURL_PATH=$(get_app_path "curl")
# expect
EXPECT_PATH=$(get_app_path "expect")
# git
GIT_PATH=$(get_app_path "git")
# jq
JQ_PATH=$(get_app_path "jq")
# less
LESS_PATH=$(get_app_path "less")
# sed
SED_PATH=$(get_app_path "sed")
# wget
WGET_PATH=$(get_app_path "wget")
# PRIMARY dependency lib's paths END
######################################
# Get the *INTERNAL* NETWORK ip address
IP=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')
######################################
# Distro-specific logic, for PHP-FPM
if [ -f "/etc/debian_version" ]; then
# Get a list of PHP-FPM packages THAT ARE AVAILABLE TO INSTALL
PHP_FPM_LIST=$(apt-cache search php-fpm)
FPM_PACKAGE=`expr match "$PHP_FPM_LIST" '.*\(php[0-9][.][0-9]-fpm\)'`
FPM_PACKAGE_VER=`expr match "$FPM_PACKAGE" '.*\([0-9][.][0-9]\)'`
elif [ -f "/etc/redhat-release" ]; then
# Get a list of PHP-FPM packages THAT ARE AVAILABLE TO INSTALL
PHP_FPM_LIST=$(yum list php-fpm)
FPM_PACKAGE=`expr match "$PHP_FPM_LIST" '.*\(php-fpm [0-9][.][0-9]\)'`
FPM_PACKAGE_VER=`expr match "$FPM_PACKAGE" '.*\([0-9][.][0-9]\)'`
fi
######################################
# Start in user home directory
# WE DON'T USE ~/ FOR PATHS IN THIS SCRIPT BECAUSE:
# 1) WE'RE #RUNNING AS SUDO# ANYWAYS (WE CAN INSTALL ANYWHERE WE WANT)
# 2) WE SET THE USER WE WANT TO INSTALL UNDER DYNAMICALLY
# 3) IN CASE THE USER INITIATES INSTALL AS ANOTHER ADMIN USER
cd /home/$TERMINAL_USERNAME
######################################
# WE NEED TO SET THIS OUTSIDE OF / BEFORE ANY OTHER SETUP LOGIC, AS WE'RE SETTING THE SYSTEM USER VAR
echo " "
echo "${yellow}We need to know the SYSTEM username you'll be logging in as on this machine to edit web files..."
echo " "
echo "Enter the SYSTEM username to allow web server editing access for:"
echo "(leave blank / hit enter for default username '${TERMINAL_USERNAME}')${reset}"
echo " "
read APP_USER
echo " "
if [ -z "$APP_USER" ]; then
APP_USER=${1:-$TERMINAL_USERNAME}
echo "${green}Using default username: $APP_USER${reset}"
else
echo "${green}Using username: $APP_USER${reset}"
fi
echo " "
######################################
echo "${yellow}Enter the FULL SYSTEM PATH to the document root of the web server:"
echo "(this does NOT automate setting apache's document root, you would need to do that manually)"
echo "(DO !NOT! INCLUDE A #TRAILING# FORWARD SLASH)"
echo " "
echo "(leave blank / hit enter to use the default value: /var/www/html)${reset}"
echo " "
read DOC_ROOT
echo " "
if [ -z "$DOC_ROOT" ]; then
DOC_ROOT=${1:-/var/www/html}
echo "${green}Using default website document root:"
echo "$DOC_ROOT${reset}"
else
echo "${green}Using custom website document root:"
echo "$DOC_ROOT${reset}"
fi
echo " "
if [ ! -d "$DOC_ROOT" ] && [ "$DOC_ROOT" != "/var/www/html" ]; then
echo "The defined document root directory '$DOC_ROOT' does not exist yet. Please create this directory structure before running this script."
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to exit..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Exiting...${reset}"
echo " "
exit
fi
fi
######################################
echo " "
echo "${yellow}TECHNICAL NOTE:"
echo " "
echo "This script was designed to install on popular Debian-based ${green}(STABLE / POLISHED)${yellow} / RedHat-based ${red}(UNSTABLE / WORK-IN-PROGRESS)${yellow} operating systems (Debian, Ubuntu, Raspberry Pi OS [Raspbian], Armbian, DietPi, Fedora, REHL, CentOS, etc), for running as an app server WHICH IS LEFT TURNED ON 24/7 (ALL THE TIME).${reset}"
echo " "
echo "${yellow}This script MAY NOT work on ALL Debian-based / RedHat-based system setups.${reset}"
echo " "
echo "${cyan}Your operating system has been detected as:"
echo " "
echo "$OS v$VER${reset}"
echo " "
echo "${red}Recommended MINIMUM system specs:${reset}"
echo " "
echo "${yellow}1 Gigahertz CPU / 512 Megabytes RAM / HIGH QUALITY 16 Gigabyte MicroSD card (running Nginx or Apache headless with PHP v7.2+)${reset}"
echo " "
echo "${red}If you already have unrelated web site files located at $DOC_ROOT on your system, they may be affected. Please back up any important pre-existing files in that directory before proceeding.${reset}"
echo " "
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to continue..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Continuing...${reset}"
echo " "
fi
echo " "
if [ -f $DOC_ROOT/config.php ]; then
echo "${yellow}Configuration files from a previous install of Open Crypto Tracker (Server Edition) have been detected on your system."
echo " "
echo "${green}During this upgrade / re-install, they will be backed up to:"
echo " "
echo "$DOC_ROOT/[filename].php.BACKUP.$DATE.[random string]${reset}"
echo " "
echo "This will save any custom settings within them, so you can migrate settings to the new config files MANUALLY."
echo " "
echo "(ALL plugin configuration files will be backed up in the same manner)"
echo " "
echo "You will need to manually move any CUSTOMIZED DEFAULT settings from backup files to the NEW configuration files with a text editor, otherwise you can just ignore or delete the backup files."
echo " "
echo "${red}IF ANYTHING STOPS WORKING AFTER UPGRADING, CLEAR YOUR BROWSER CACHE (temporary files), AND RELOAD OR RESTART THE APP. This will load the latest Javascript / Style Sheet upgrades properly.${reset}"
echo " "
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to continue..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Continuing...${reset}"
echo " "
fi
echo " "
echo "${red}IMPORTANT *UPGRADE* NOTICES:"
echo " "
echo " "
echo "v6.00.38 and higher restructures CURRENCY settings in the config. USE THE LATEST/UPGRADED CONFIG.PHP, AND MIGRATE YOUR EXISTING CUSTOM SETTINGS TO THE NEW FORMAT."
echo " "
echo " "
echo "${reset} "
echo "${yellow} "
read -n1 -s -r -p $"PRESS ANY KEY to continue..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" != 'y' ]; then
echo " "
echo "${green}Continuing...${reset}"
echo " "
fi
echo " "
fi
echo "${red}VERY IMPORTANT *SECURITY* NOTES:"
echo " "
echo "YOU WILL BE PROMPTED TO CREATE AN ADMIN LOGIN (FOR SECURITY OF THE ADMIN AREA), #WHEN YOU FIRST RUN THIS APP AFTER INSTALLATION#. IT'S #HIGHLY RECOMMENDED TO DO THIS IMMEDIATELY#, ESPECIALLY ON PUBLIC FACING / KNOWN SERVERS, #OR SOMEBODY ELSE MAY BEAT YOU TO IT#."
echo " "
echo "!!VERY IMPORTANT *HOSTING* NOTICE!!:"
echo " "
echo "This auto-install script is ONLY FOR SELF-HOSTED ENVIRONMENTS, THAT #DO NOT# ALREADY HAVE A APP SERVER OR CONTROL PANEL INSTALLED ON THE SYSTEM. If this is a managed hosting environment that a service provider has already provisioned, please quit this auto-install session, and refer to the \"Manual Install\" section of the README.txt file documentation.${reset}"
echo " "
echo "${yellow}PLEASE REPORT ANY ISSUES HERE: $ISSUES_URL${reset}"
echo " "
echo "${yellow} "
read -n1 -s -r -p $"Press Y to continue (or press N to exit)..." key
echo "${reset} "
if [ "$key" = 'y' ] || [ "$key" = 'Y' ]; then
echo " "
echo "${green}Continuing...${reset}"
# If all clear for takeoff, make sure a group exists with same name as user,
# AND user is a member of it (believe it or not, I've seen this not always hold true!)
groupadd -f $APP_USER > /dev/null 2>&1
sleep 3
usermod -a -G $APP_USER $APP_USER > /dev/null 2>&1
echo " "
else
echo " "
echo "${green}Exiting...${reset}"
echo " "
exit
fi
echo " "
######################################
echo " "
echo "${yellow}OPTIONAL SECURITY-HARDENING:"
echo " "
echo "Before we install a PHP web server and Open Crypto Tracker (server edition), let's review a few OPTIONAL security-hardening configurations below. If you enable all of these security options, it will significantly improve the security of this app server (HIGHLY RECOMMENDED)...${reset}"
echo " "
######################################
echo "${yellow} "
read -n1 -s -r -p $'Disable bluetooth, for higher app server security? (press Y to run, or press N to skip)...\n' keystroke
echo "${reset} "
if [ "$keystroke" = 'y' ] || [ "$keystroke" = 'Y' ]; then
echo " "
echo "${cyan}Disabling bluetooth, please wait...${reset}"
systemctl disable hciuart.service
systemctl disable bluealsa.service
systemctl disable bluetooth.service
# Raspberry pi devices
if [ -f "/usr/bin/raspi-config" ]; then
# Enhanced security for raspi config
RASPI_CONF="/boot/config.txt"
CHECK_RASPI_CONF=$(sed -n '/disable-bt/p' $RASPI_CONF)
# Raspi security
if [ "$CHECK_RASPI_CONF" == "" ]; then
echo " "
echo "${cyan}Disabling bluetooth in $RASPI_CONF, please wait...${reset}"
echo " "
# Don't nest / indent, or it could malform the setting addition
read -r -d '' RASPI_SECURITY <<- EOF
\r
# Disable on-board bluetooth
dtoverlay=disable-bt
\r
EOF
# Backup config before editing, to be safe
\cp $RASPI_CONF $RASPI_CONF.BACKUP.$DATE
sleep 1
# APPEND the config
echo -e "$RASPI_SECURITY" >> $RASPI_CONF
sleep 1
echo "${green}Disabling bluetooth in $RASPI_CONF has been completed.${reset}"
echo " "
else
echo " "
echo "${green}Bluetooth was already disabled in $RASPI_CONF.${reset}"
echo " "
fi
sleep 2
echo " "
echo " "
fi
echo " "
echo "${green}Disabling bluetooth has been completed.${reset}"
echo " "
echo "${red}YOU MUST RESTART the computer for this to take affect (ONLY AFTER THIS SCRIPT IS FINISHED RUNNING).${reset}"
echo " "
else
echo "${green}Disabling bluetooth has been skipped.${reset}"
echo " "
fi
######################################
echo "${yellow} "
read -n1 -s -r -p $'Install / configure a firewall, for higher app server security? (press Y to run, or press N to skip)...\n' keystroke
echo "${reset} "
if [ "$keystroke" = 'y' ] || [ "$keystroke" = 'Y' ]; then
echo " "
echo "${cyan}Installing / configuring a firewall, please wait...${reset}"
echo "${yellow}(THE SSH PORT *WILL* BE ALLOWED, SO IT'S SAFE TO PRESS 'Y' WHEN ASKED)${reset}"
echo " "
$PACKAGE_INSTALL ufw -y
ufw allow ssh
ufw limit ssh/tcp
ufw allow 80
ufw allow 443
ufw enable
echo " "