-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
invidious_installer.sh
1285 lines (1177 loc) · 41.1 KB
/
invidious_installer.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
#!/usr/bin/env bash
# shellcheck disable=SC2059,SC1091,SC2166,SC2015,SC2129,SC2221,SC2222,SC2317,SC2086
## Author: Tommy Miland (@tmiland) - Copyright (c) 2024
######################################################################
#### Invidious Installer.sh ####
#### Automatic install script for Invidious ####
#### Script to install Invidious ####
#### Maintained by @tmiland ####
######################################################################
VERSION='2.2.2' # Must stay on line 14 for updater to fetch the numbers
#------------------------------------------------------------------------------#
#
# MIT License
#
# Copyright (c) 2024 Tommy Miland
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#------------------------------------------------------------------------------#
## Uncomment for debugging purpose
#set -o errexit
#set -o pipefail
#set -o nounset
#set -o xtrace
#timestamp
# time_stamp=$(date)
# Detect absolute and full path as well as filename of this script
cd "$(dirname "$0")" || exit
CURRDIR=$(pwd)
#SCRIPT_FILENAME=$(basename "$0")
cd - > /dev/null || exit
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
#SCRIPT_DIR=$(dirname "${sfp}")
if lsb_release -si >/dev/null 2>&1; then
DISTRO=$(lsb_release -si)
else
if [[ -f /etc/debian_version ]]; then
DISTRO=$(cat /etc/issue.net)
elif [[ -f /etc/redhat-release ]]; then
DISTRO=$(cat /etc/redhat-release)
elif [[ -f /etc/os-release ]]; then
DISTRO=$(cat < /etc/os-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' | sed 's/["]//g' | awk '{print $1}')
fi
fi
if [[ $DISTRO =~ Fedora* ]]
then
if [[ $(rpm --query openssl) == "package openssl is not installed" ]]
then
echo "package openssl is not installed... Installing"
dnf install -y -q openssl
fi
fi
# Icons used for printing
ARROW='➜'
#WARNING='⚠'
# Script name
SCRIPT_NAME="invidious installer.sh"
# Repo name
REPO_NAME="tmiland/invidious-installer"
# Invidious repo name
IN_REPO=${IN_REPO:-iv-org/invidious}
# Set username
USER_NAME=invidious
# Set userdir
USER_DIR="/home/invidious"
# Set repo Dir
REPO_DIR=$USER_DIR/invidious
# Set config file path
IN_CONFIG=${REPO_DIR}/config/config.yml
# Service name
SERVICE_NAME=invidious.service
# Default branch
IN_BRANCH=master
# Default domain
DOMAIN=${DOMAIN:-}
# Default ip
IP=${IP:-localhost}
# Default port
PORT=${PORT:-3000}
# Default dbname
PSQLDB=${PSQLDB:-invidious}
# Generate db password
PSSQLPASS_GEN=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# Default dbpass (generated)
PSQLPASS=${PSQLPASS:-$PSSQLPASS_GEN}
# Default https only
HTTPS_ONLY=${HTTPS_ONLY:-n}
# Default external port
EXTERNAL_PORT=${EXTERNAL_PORT:-}
# Default admins
ADMINS=${ADMINS:-}
# Default Captcha Key
CAPTCHA_KEY=${CAPTCHA_KEY:-}
# Default HMAC_KEY
HMAC_KEY_GEN=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
HMAC_KEY=${HMAC_KEY:-$HMAC_KEY_GEN}
# Default Swap option
SWAP_OPTIONS=${SWAP_OPTIONS:-n}
# Logfile
LOGFILE=$CURRDIR/invidious_installer.log
# Console output level; ignore debug level messages.
VERBOSE=0
#
BANNERS=1
usage() {
# shellcheck disable=SC2046
printf "Usage: %s %s [options]\\n" "${CYAN}" $(basename "$0")
echo
echo " If called without arguments, installs Invidious."
echo
printf " ${YELLOW}--help|-h${NORMAL} display this help and exit\\n"
printf " ${YELLOW}--verbose|-v${NORMAL} increase verbosity\\n"
printf " ${YELLOW}--banners|-b${NORMAL} disable banners\\n"
printf " ${YELLOW}--uninstall|-u${NORMAL} uninstall"
printf " ${YELLOW}--repo|-r${NORMAL} select custom repo. E.G: user/invidious\\n"
echo
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--help | -h)
usage
exit 0
;;
--verbose | -v)
shift
VERBOSE=1
;;
--banners | -b)
shift
BANNERS=0
;;
--repo | -r) # Bash Space-Separated (e.g., --option argument)
IN_REPO="$2" # Source: https://stackoverflow.com/a/14203146
shift # past argument
shift # past value
;;
--uninstall | -u)
shift
mode="uninstall"
;;
-*|--*)
printf "Unrecognized option: $1\\n\\n"
usage
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# Include functions
if [[ -f ./src/slib.sh ]]; then
. ./src/slib.sh
else
SLIB_URL=https://raw.githubusercontent.com/tmiland/invidious-installer/main/src/slib.sh
if [[ $(command -v 'curl') ]]; then
# shellcheck source=$SLIB_URL
source <(curl -sSLf $SLIB_URL)
elif [[ $(command -v 'wget') ]]; then
# shellcheck source=$SLIB_URL
. <(wget -qO - $SLIB_URL)
else
echo -e "${RED}${BALLOT_X} This script requires curl or wget.\nProcess aborted${NORMAL}"
exit 0
fi
fi
# Setup slog
# shellcheck disable=SC2034
LOG_PATH="$LOGFILE"
# Setup run_ok
# shellcheck disable=SC2034
RUN_LOG="$LOGFILE"
# Exit on any failure during shell stage
# shellcheck disable=SC2034
RUN_ERRORS_FATAL=1
# Console output level; ignore debug level messages.
if [ "$VERBOSE" = "1" ]; then
# shellcheck disable=SC2034
LOG_LEVEL_STDOUT="DEBUG"
else
# shellcheck disable=SC2034
LOG_LEVEL_STDOUT="INFO"
fi
# Log file output level; catch literally everything.
# shellcheck disable=SC2034
LOG_LEVEL_LOG="DEBUG"
# log_fatal calls log_error
log_fatal() {
log_error "$1"
}
fatal() {
echo
log_fatal "Fatal Error Occurred: $1"
printf "${RED}Cannot continue installation.${NORMAL}\\n"
log_fatal "If you are unsure of what went wrong, you may wish to review the log"
log_fatal "in $LOGFILE"
exit 1
}
success() {
log_success "$1 Succeeded."
}
read_sleep() {
read -rt "$1" <> <(:) || :
}
# Start with a clean log
if [[ -f $LOGFILE ]]; then
rm $LOGFILE
fi
# Distro support
ARCH_CHK=$(uname -m)
if [ ! "${ARCH_CHK}" == 'x86_64' ]; then
echo -e "${RED}${BALLOT_X} Error: Sorry, your OS ($ARCH_CHK) is not supported.${NORMAL}"
exit 1;
fi
shopt -s nocasematch
case "$DISTRO" in
Debian*|Ubuntu*|LinuxMint*|PureOS*|Pop*|Devuan*)
# shellcheck disable=SC2140
PKGCMD="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
LSB=lsb-release
DISTRO_GROUP=Debian
;;
CentOS*)
PKGCMD="yum install -y"
LSB=redhat-lsb
DISTRO_GROUP=RHEL
;;
Fedora*)
PKGCMD="dnf install -y"
LSB=redhat-lsb
DISTRO_GROUP=RHEL
;;
Arch*|Manjaro*)
PKGCMD="yes | LC_ALL=en_US.UTF-8 pacman -S"
LSB=lsb-release
DISTRO_GROUP=Arch
;;
*) echo -e "${RED}${BALLOT_X} unknown distro: '$DISTRO'${NORMAL}" ; exit 1 ;;
esac
if ! lsb_release -si 1>/dev/null 2>&1; then
echo ""
echo -e "${RED}${BALLOT_X} Looks like ${LSB} is not installed!${NORMAL}"
echo ""
read -r -p "Do you want to download ${LSB}? [y/n]? " ANSWER
echo ""
case $ANSWER in
[Yy]* )
echo -e "${GREEN}${ARROW} Installing ${LSB} on ${DISTRO}...${NORMAL}"
su -s "$(which bash)" -c "${PKGCMD} ${LSB}" || echo -e "${RED}${BALLOT_X} Error: could not install ${LSB}!${NORMAL}"
echo -e "${GREEN}${CHECK} Done${NORMAL}"
read_sleep 3
#indexit
;;
[Nn]* )
exit 1;
;;
* ) echo "Enter Y, N, please." ;;
esac
fi
SUDO=""
UPDATE=""
#UPGRADE=""
INSTALL=""
UNINSTALL=""
PURGE=""
CLEAN=""
PKGCHK=""
PGSQL_SERVICE=""
SYSTEM_CMD=""
shopt -s nocasematch
if [[ $DISTRO_GROUP == "Debian" ]]; then
export DEBIAN_FRONTEND=noninteractive
SUDO="sudo"
# shellcheck disable=SC2140
UPDATE="apt-get -o Dpkg::Progress-Fancy="1" update -qq"
# shellcheck disable=SC2140
# UPGRADE="apt-get -o Dpkg::Progress-Fancy="1" upgrade -qq"
# shellcheck disable=SC2140
INSTALL="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
# shellcheck disable=SC2140
UNINSTALL="apt-get -o Dpkg::Progress-Fancy="1" remove -qq"
# shellcheck disable=SC2140
PURGE="apt-get purge -o Dpkg::Progress-Fancy="1" -qq"
CLEAN="apt-get clean && apt-get autoremove -qq"
PKGCHK="dpkg -s"
# Pre-install packages
PRE_INSTALL_PKGS="apt-transport-https git curl sudo gnupg"
# Install packages
INSTALL_PKGS="crystal make libssl-dev libxml2-dev libyaml-dev libgmp-dev libreadline-dev librsvg2-bin postgresql libsqlite3-dev zlib1g-dev libpcre3-dev libevent-dev"
#Uninstall packages
UNINSTALL_PKGS="crystal make libssl-dev libxml2-dev libyaml-dev libgmp-dev libreadline-dev librsvg2-bin libsqlite3-dev zlib1g-dev libpcre3-dev libevent-dev"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1)
elif [[ $(lsb_release -si) == "CentOS" ]]; then
SUDO="sudo"
UPDATE="yum update -y -q"
# UPGRADE="yum upgrade -q"
INSTALL="yum install -y -q"
UNINSTALL="yum remove -y -q"
PURGE="yum purge -y -q"
CLEAN="yum clean all -y -q"
PKGCHK="rpm --quiet --query"
# Pre-install packages
PRE_INSTALL_PKGS="epel-release git curl sudo dnf-plugins-core"
# Install packages
INSTALL_PKGS="crystal make openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel postgresql postgresql-server zlib-devel gcc libevent-devel patch"
#Uninstall packages
UNINSTALL_PKGS="crystal make openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel zlib-devel gcc libevent-devel patch"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1)
elif [[ $(lsb_release -si) == "Fedora" ]]; then
SUDO="sudo"
UPDATE="dnf update -y -q"
# UPGRADE="dnf upgrade -q"
INSTALL="dnf install -y -q"
UNINSTALL="dnf remove -y -q"
PURGE="dnf purge -y -q"
CLEAN="dnf clean all -y -q"
PKGCHK="rpm --quiet --query"
# Pre-install packages
PRE_INSTALL_PKGS="git curl sudo"
# Install packages
INSTALL_PKGS="crystal make openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel postgresql postgresql-server zlib-devel gcc libevent-devel patch"
#Uninstall packages
UNINSTALL_PKGS="crystal make openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel zlib-devel gcc libevent-devel patch"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1)
elif [[ $DISTRO_GROUP == "Arch" ]]; then
SUDO="sudo"
UPDATE="pacman -Syu"
INSTALL="pacman -S --noconfirm --needed"
UNINSTALL="pacman -R"
PURGE="pacman -Rs"
CLEAN="pacman -Sc"
PKGCHK="pacman -Qs"
# Pre-install packages
PRE_INSTALL_PKGS="git curl sudo"
# Install packages
INSTALL_PKGS="make base-devel librsvg postgresql ttf-opensans"
#Uninstall packages
UNINSTALL_PKGS="make base-devel librsvg postgresql ttf-opensans"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder="/var/lib/postgres/data"
else
echo -e "${RED}${BALLOT_X} Error: Sorry, your OS is not supported.${NORMAL}"
exit 1;
fi
# Check if systemd is installed on Devuan
if [[ $(lsb_release -si) == "Devuan" ]]; then
if ( ! $SYSTEM_CMD 2>/dev/null); then
echo -e "${RED}${BALLOT_X} Error: Sorry, you need systemd to run this script.${NORMAL}"
exit 1;
fi
fi
# Make sure that the script runs with root permissions
chk_permissions() {
if [[ $EUID -ne 0 ]]; then
echo -e "Sorry, you need to run this as root"
exit 1
fi
}
ADD_SWAP_URL=https://raw.githubusercontent.com/tmiland/swap-add/master/swap-add.sh
add_swap() {
if [[ $(command -v 'curl') ]]; then
# shellcheck disable=SC1090
source <(curl -sSLf $ADD_SWAP_URL)
elif [[ $(command -v 'wget') ]]; then
# shellcheck disable=SC1090
. <(wget -qO - $ADD_SWAP_URL)
else
echo -e "${RED}${BALLOT_X} This script requires curl or wget.\nProcess aborted${NORMAL}"
exit 0
fi
read_sleep 3
}
install_inv_sig_helper() {
if [[ -d $USER_DIR ]]
then
echo -e "Downloading Invidious sig helper service from GitHub"
cd $USER_DIR || exit 1
git clone https://github.com/iv-org/inv_sig_helper.git
chown -R $USER_NAME:$USER_NAME inv_sig_helper
cd inv_sig_helper || exit 1
# Install cargo / rust
curl -fsSL sh.rustup.rs | sh -s -- -y
# Source cargo
. "$HOME/.cargo/env"
# Build release
cargo build --release
# Copy service file to systemd folder
cp -rp $USER_DIR/inv_sig_helper/inv_sig_helper.service /etc/systemd/system/
# Add socket to config
${SUDO} echo "signature_server: /home/invidious/tmp/inv_sig_helper.sock" >> $USER_DIR/invidious/config/config.yml
if [[ ! -d /home/invidious/tmp ]]
then
${SUDO} mkdir -p /home/invidious/tmp
chown -R $USER_NAME:$USER_NAME /home/invidious/tmp
fi
SERVICE_NAME=inv_sig_helper.service
# Enable invidious sig helper at boot
${SUDO} $SYSTEM_CMD enable ${SERVICE_NAME}
# Reload Systemd
${SUDO} $SYSTEM_CMD daemon-reload
# Start Invidious sig helper
${SUDO} $SYSTEM_CMD start ${SERVICE_NAME}
if ( $SYSTEM_CMD -q is-active ${SERVICE_NAME})
then
echo -e "Invidious sig helper service has been successfully installed!"
${SUDO} $SYSTEM_CMD status ${SERVICE_NAME} --no-pager
echo -e "Restarting Invidious for changes to take effect..."
${SUDO} $SYSTEM_CMD restart invidious
read_sleep 5
else
echo -e "Invidious sig helper service installation failed..."
${SUDO} journalctl -u ${SERVICE_NAME}
read_sleep 5
fi
else
echo -e "Invidious is not installed..."
fi
}
## get total free memory size in megabytes(MB)
free=$(free -mt | grep Total | awk '{print $4}')
if [[ "$free" -le 2048 ]]; then
echo -e "${YELLOW}Advice: Free memory: $free MB is less than recommended to build Invidious${NORMAL}"
while true; do
case $SWAP_OPTIONS in
[Yy]* )
add_swap
break
;;
[Nn]* )
break
;;
esac
done
fi
# Show service status - @FalconStats
installer_status() {
declare -a services=(
"invidious"
"postgresql"
)
#fi
declare -a serviceName=(
"Invidious"
"PostgreSQL"
)
declare -a serviceStatus=()
for service in "${services[@]}"
do
serviceStatus+=("$($SYSTEM_CMD is-active "$service")")
done
echo ""
echo "Services running:"
for i in "${!serviceStatus[@]}"
do
if [[ "${serviceStatus[$i]}" == "active" ]]; then
line+="${GREEN}${NORMAL}${serviceName[$i]}: ${GREEN}● ${serviceStatus[$i]}${NORMAL} "
else
line+="${serviceName[$i]}: ${RED}▲ ${serviceStatus[$i]}${NORMAL} "
fi
done
echo -e "$line"
}
if ( $SYSTEM_CMD -q is-active ${SERVICE_NAME}); then
SHOW_STATUS=$(installer_status)
fi
# BANNERS
# Header
installer_header() {
echo -e "${GREEN}\n"
echo ' ╔═══════════════════════════════════════════════════════════════════╗'
echo ' ║ invidious installer.sh ║'
echo ' ║ Automatic install script for Invidious ║'
echo ' ║ Maintained by @tmiland ║'
echo ' ║ version: '${VERSION}' ║'
echo ' ╚═══════════════════════════════════════════════════════════════════╝'
echo -e "${NORMAL}"
}
# Preinstall banner
installer_preinstall_banner() {
clear
installer_header
echo "Thank you for using the invidious installer.sh script."
echo ""
echo ""
echo ""
echo -e "Documentation for this script is available here: ${YELLOW}\n ${ARROW} https://github.com/${REPO_NAME}${NORMAL}\n"
}
# Install banner
installer_install_banner() {
#clear
installer_header
echo ""
echo ""
echo ""
echo "Thank you for using the invidious installer.sh script."
echo ""
echo ""
echo ""
echo -e "${GREEN}${CHECK} Invidious install done.${NORMAL} Now visit http://${IP}:${PORT}"
echo ""
echo ""
echo ""
echo ""
echo -e "Documentation for this script is available here: ${YELLOW}\n ${ARROW} https://github.com/${REPO_NAME}${NORMAL}\n"
}
# Banner
installer_banner() {
#clear
installer_header
echo "Welcome to the invidious installer.sh script."
echo ""
echo ""
echo "${SHOW_STATUS} "
echo ""
echo ""
echo ""
echo -e "Documentation for this script is available here: ${YELLOW}\n ${ARROW} https://github.com/${REPO_NAME}${NORMAL}\n"
}
# Exit Script
exit_script() {
#installer_header
echo -e "${GREEN}"
echo ' ____ _ ___ '
echo ' / _/___ _ __(_)___/ (_)___ __ _______ '
echo ' / // __ \ | / / / __ / / __ \/ / / / ___/ '
echo ' _/ // / / / |/ / / /_/ / / /_/ / /_/ (__ ) '
echo ' /___/_/_/_/|___/_/\__,_/_/\____/\__,_/____/ __ '
echo ' / _/___ _____/ /_____ _/ / /__ __________/ /_ '
echo ' / // __ \/ ___/ __/ __ `/ / / _ \/ ___/ ___/ __ \ '
echo ' _/ // / / (__ ) /_/ /_/ / / / __/ / (__ ) / / / '
echo ' /___/_/ /_/____/\__/\__,_/_/_/\___/_(_)/____/_/ /_/ '
echo -e ' ' "${NORMAL}"
echo -e "
This script runs on coffee ☕
${GREEN}${CHECK}${NORMAL} ${BBLUE}GitHub${NORMAL} ${ARROW} ${YELLOW}https://github.com/sponsors/tmiland${NORMAL}
${GREEN}${CHECK}${NORMAL} ${BBLUE}Coindrop${NORMAL} ${ARROW} ${YELLOW}https://coindrop.to/tmiland${NORMAL}
"
echo -e "Documentation for this script is available here: ${YELLOW}\n${ARROW} https://github.com/${REPO_NAME}${NORMAL}\n"
echo -e "${YELLOW}${ARROW} Goodbye.${NORMAL} ☺"
echo ""
}
# Check Git repo
chk_git_repo() {
# Check if the folder is a git repo
if [[ -d "${REPO_DIR}/.git" ]]; then
echo ""
log_fatal "Looks like Invidious is already installed!"
echo ""
log_warning "If you want to reinstall, please remove Invidious first!"
echo ""
read_sleep 3
#indexit
exit 0
fi
}
# Set permissions
set_permissions() {
${SUDO} chown -R $USER_NAME:$USER_NAME $USER_DIR 1>/dev/null 2>&1
${SUDO} chmod -R 755 $USER_DIR 1>/dev/null 2>&1
}
# Update config
update_config() {
# Update config.yml with new info from user input
BAKPATH="/home/backup/$USER_NAME/config"
# Lets change the default password
OLDPASS="password: kemal"
NEWPASS="password: $PSQLPASS"
# Lets change the default database name
OLDDBNAME="dbname: invidious"
NEWDBNAME="dbname: $PSQLDB"
# Lets change the default domain
OLDDOMAIN="domain:"
NEWDOMAIN="domain: $DOMAIN"
# Lets change https_only value
OLDHTTPS="https_only: false"
NEWHTTPS="https_only: $HTTPS_ONLY"
# Lets change external_port
OLDEXTERNAL="external_port:"
NEWEXTERNAL="external_port: $EXTERNAL_PORT"
DPATH="${IN_CONFIG}"
BPATH="$BAKPATH"
TFILE="/tmp/config.yml"
[ ! -d $BPATH ] && mkdir -p $BPATH || :
for f in $DPATH
do
if [ -f $f -a -r $f ]; then
/bin/cp -f $f $BPATH
# Add external_port: to config on line 13
sed -i "11i\external_port:" "$f" > $TFILE
sed -i "12i\check_tables: true" "$f" > $TFILE
sed -i "13i\port: $PORT" "$f" > $TFILE
sed -i "14i\host_binding: $IP" "$f" > $TFILE
sed -i "15i\admins: \n- $ADMINS" "$f" > $TFILE
sed -i "17i\captcha_key: $CAPTCHA_KEY" "$f" > $TFILE
sed -i "18i\hmac_key: $HMAC_KEY" "$f" > $TFILE
sed -i "19i\captcha_api_url: https://api.anti-captcha.com" "$f" > $TFILE
sed "s/$OLDPASS/$NEWPASS/g; s/$OLDDBNAME/$NEWDBNAME/g; s/$OLDDOMAIN/$NEWDOMAIN/g; s/$OLDHTTPS/$NEWHTTPS/g; s/$OLDEXTERNAL/$NEWEXTERNAL/g;" "$f" > $TFILE &&
mv $TFILE "$f" >>"${RUN_LOG}" 2>&1
else
log_fatal "Error: Cannot read $f"
fi
done
if [[ -e $TFILE ]]; then
/bin/rm $TFILE >>"${RUN_LOG}" 2>&1
fi
# Done updating config.yml with new info!
# Source: https://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/
}
system_cmd() {
${SUDO} $SYSTEM_CMD "$1" "$2"
}
# Systemd install
systemd_install() {
# Setup Systemd Service
shopt -s nocasematch
if [[ $DISTRO_GROUP == "RHEL" ]]; then
cp ${REPO_DIR}/${SERVICE_NAME} /etc/systemd/system/${SERVICE_NAME} >>"${RUN_LOG}" 2>&1
else
cp ${REPO_DIR}/${SERVICE_NAME} /lib/systemd/system/${SERVICE_NAME} >>"${RUN_LOG}" 2>&1
fi
# Enable invidious start at boot
system_cmd enable ${SERVICE_NAME} >>"${RUN_LOG}" 2>&1
# Reload Systemd
system_cmd daemon-reload >>"${RUN_LOG}" 2>&1
# Restart Invidious
system_cmd start ${SERVICE_NAME} >>"${RUN_LOG}" 2>&1
if ( $SYSTEM_CMD -q is-active ${SERVICE_NAME})
then
system_cmd status ${SERVICE_NAME} --no-pager >>"${RUN_LOG}" 2>&1
read_sleep 5
else
${SUDO} journalctl -u ${SERVICE_NAME} >>"${RUN_LOG}" 2>&1
read_sleep 5
fi
}
logrotate_install() {
if [ -d /etc/logrotate.d ]; then
echo "Adding logrotate configuration..."
echo "/home/invidious/invidious/invidious.log {
rotate 4
weekly
notifempty
missingok
compress
minsize 1048576
}" | ${SUDO} tee /etc/logrotate.d/invidious.logrotate >>"${RUN_LOG}" 2>&1
chmod 0644 /etc/logrotate.d/invidious.logrotate >>"${RUN_LOG}" 2>&1
fi
}
# Get Crystal
get_crystal() {
shopt -s nocasematch
if [[ $DISTRO_GROUP == "Debian" ]]; then
if [[ ! -e /etc/apt/sources.list.d/crystal.list ]]; then
curl -fsSL https://crystal-lang.org/install.sh | ${SUDO} bash >>"${RUN_LOG}" 2>&1
fi
elif [[ $DISTRO_GROUP == "RHEL" ]]; then
if [[ ! -e /etc/yum.repos.d/crystal.repo ]]; then
curl -fsSL https://crystal-lang.org/install.sh | ${SUDO} bash >>"${RUN_LOG}" 2>&1
fi
elif [[ $(lsb_release -si) == "Darwin" ]]; then
exit 1;
elif [[ $DISTRO_GROUP == "Arch" ]]; then
echo "Arch/Manjaro Linux... Skipping manual crystal install" >>"${RUN_LOG}" 2>&1
else
log_fatal "Error: Sorry, your OS is not supported."
exit 1;
fi
}
# Create new config.yml
create_config() {
if [ ! -f "$IN_CONFIG" ]; then
echo "channel_threads: 1
feed_threads: 1
db:
user: kemal
password: kemal
host: localhost
port: 5432
dbname: invidious
full_refresh: false
https_only: false
domain:" | ${SUDO} tee ${IN_CONFIG} >>"${RUN_LOG}" 2>&1
fi
}
# Backup config file
backupConfig() {
# Set config backup path
ConfigBakPath="/home/backup/$USER_NAME/config"
# If directory is not created
[ ! -d $ConfigBakPath ] && mkdir -p $ConfigBakPath || :
configBackup=${IN_CONFIG}
backupConfigFile=$(date +%F).config.yml
/bin/cp -f $configBackup $ConfigBakPath/"$backupConfigFile" >>"${RUN_LOG}" 2>&1
}
# Checkout Master branch to branch master (to avoid detached HEAD state)
GetMaster() {
create_config
backupConfig
git checkout origin/${IN_BRANCH} -B ${IN_BRANCH} >>"${RUN_LOG}" 2>&1
}
# Get dbname from config file (used in db maintenance and uninstallation)
get_dbname() {
echo "$(sed -n 's/.*dbname *: *\([^ ]*.*\)/\1/p' "$1")"
}
uninstall_invidious() {
# Set default uninstallation parameters
RM_PostgreSQLDB=${RM_PostgreSQLDB:-y}
RM_RE_PGSQLDB=${RM_RE_PGSQLDB:-n}
RM_PACKAGES=${RM_PACKAGES:-n}
RM_PURGE=${RM_PURGE:-n}
RM_FILES=${RM_FILES:-y}
RM_USER=${RM_USER:-n}
# Set db backup path
PGSQLDB_BAK_PATH="/home/backup/$USER_NAME"
# Get dbname from config.yml
RM_PSQLDB=$(get_dbname "${IN_CONFIG}")
read -p "Express uninstall ? [y/n]: " EXPRESS_UNINSTALL
if [[ ! $EXPRESS_UNINSTALL = "y" ]]; then
echo ""
read -e -i "$RM_PostgreSQLDB" -p " Remove database for Invidious ? [y/n]: " RM_PostgreSQLDB
if [[ $RM_PostgreSQLDB = "y" ]]; then
echo -e " ${YELLOW}${WARNING} (( A backup will be placed in ${ARROW} $PGSQLDB_BAK_PATH ))${NORMAL}"
echo -e " Your Invidious database name: $RM_PSQLDB"
fi
if [[ $RM_PostgreSQLDB = "y" ]]; then
echo -e " ${YELLOW}${WARNING} (( If yes, only data will be dropped ))${NORMAL}"
read -e -i "$RM_RE_PGSQLDB" -p " Do you intend to reinstall?: " RM_RE_PGSQLDB
fi
read -e -i "$RM_PACKAGES" -p " Remove Packages ? [y/n]: " RM_PACKAGES
if [[ $RM_PACKAGES = "y" ]]; then
read -e -i "$RM_PURGE" -p " Purge Package configuration files ? [y/n]: " RM_PURGE
fi
echo -e " ${YELLOW}${WARNING} (( This option will remove ${ARROW} ${REPO_DIR} ))${NORMAL}"
read -e -i "$RM_FILES" -p " Remove files ? [y/n]: " RM_FILES
if [[ "$RM_FILES" = "y" ]]; then
echo -e " ${RED}${WARNING} (( This option will remove ${ARROW} $USER_DIR ))${NORMAL}"
echo -e " ${YELLOW}${WARNING} (( Not needed for reinstall ))${NORMAL}"
read -e -i "$RM_USER" -p " Remove user ? [y/n]: " RM_USER
fi
echo ""
echo -e "${GREEN}${ARROW} Invidious is ready to be uninstalled${NORMAL}"
echo ""
read -n1 -r -p "press any key to continue or Ctrl+C to cancel..."
echo ""
fi
# Remove PostgreSQL database if user ANSWER is yes
if [[ "$RM_PostgreSQLDB" = 'y' ]]; then
# Stop and disable invidious
system_cmd stop ${SERVICE_NAME}
read_sleep 1
system_cmd restart ${PGSQL_SERVICE}
read_sleep 1
# If directory is not created
if [[ ! -d $PGSQLDB_BAK_PATH ]]; then
echo -e "${YELLOW}${ARROW} Backup Folder Not Found, adding folder${NORMAL}"
${SUDO} mkdir -p $PGSQLDB_BAK_PATH
fi
echo ""
echo -e "${GREEN}${ARROW} Running database backup${NORMAL}"
echo ""
${SUDO} -i -u postgres pg_dump ${RM_PSQLDB} > ${PGSQLDB_BAK_PATH}/${RM_PSQLDB}.sql
read_sleep 2
${SUDO} chown -R 1000:1000 "/home/backup"
if [[ "$RM_RE_PGSQLDB" != 'n' ]]; then
echo ""
echo -e "${RED}${ARROW} Dropping Invidious PostgreSQL data${NORMAL}"
echo ""
${SUDO} -i -u postgres psql -c "DROP OWNED BY kemal CASCADE;"
echo ""
echo -e "${YELLOW}${CHECK} Data dropped and backed up to ${ARROW} ${PGSQLDB_BAK_PATH}/${RM_PSQLDB}.sql ${NORMAL}"
echo ""
fi
if [[ "$RM_RE_PGSQLDB" != 'y' ]]; then
echo ""
echo -e "${RED}${ARROW} Dropping Invidious PostgreSQL database${NORMAL}"
echo ""
${SUDO} -i -u postgres psql -c "DROP DATABASE $RM_PSQLDB"
echo ""
echo -e "${YELLOW}${CHECK} Database dropped and backed up to ${ARROW} ${PGSQLDB_BAK_PATH}/${RM_PSQLDB}.sql ${NORMAL}"
echo ""
echo -e "${RED}${ARROW} Removing user kemal${NORMAL}"
${SUDO} -i -u postgres psql -c "DROP ROLE IF EXISTS kemal;"
fi
fi
# Reload Systemd
system_cmd daemon-reload
# Remove packages installed during installation
if [[ "$RM_PACKAGES" = 'y' ]]; then
echo ""
echo -e "${YELLOW}${ARROW} Removing packages installed during installation."
echo ""
echo -e "Note: PostgreSQL will not be removed due to unwanted complications${NORMAL}"
echo ""
if ${PKGCHK} $UNINSTALL_PKGS >/dev/null 2>&1; then
for i in $UNINSTALL_PKGS; do
echo ""
echo -e "${YELLOW}${ARROW} removing packages.${NORMAL}"
echo ""
${UNINSTALL} $i 2> /dev/null
done
fi
echo ""
echo -e "${GREEN}${CHECK} done.${NORMAL}"
echo ""
fi
# Remove conf files
if [[ "$RM_PURGE" = 'y' ]]; then
# Removing invidious files and modules files
echo ""
echo -e "${YELLOW}${ARROW} Removing invidious files and modules files.${NORMAL}"
echo ""
if [[ $DISTRO_GROUP == "Debian" ]]; then
rm -r \
/lib/systemd/system/${SERVICE_NAME} \
/etc/apt/sources.list.d/crystal.list
elif [[ $DISTRO_GROUP == "RHEL" ]]; then
rm -r \
/usr/lib/systemd/system/${SERVICE_NAME} \
/etc/yum.repos.d/crystal.repo
fi
if ${PKGCHK} $UNINSTALL_PKGS >/dev/null 2>&1; then
for i in $UNINSTALL_PKGS; do
echo ""
echo -e "${YELLOW}${ARROW} purging packages.${NORMAL}"
echo ""
${PURGE} $i 2> /dev/null
done
fi
echo ""
echo -e "${YELLOW}${ARROW} cleaning up.${NORMAL}"
echo ""
${CLEAN}
echo ""
echo -e "${GREEN}${CHECK} done.${NORMAL}"
echo ""
fi
if [[ "$RM_FILES" = 'y' ]]; then
# If directory is present, remove
if [[ -d ${REPO_DIR} ]]; then
echo -e "${YELLOW}${ARROW} Folder Found, removing folder${NORMAL}"
rm -r ${REPO_DIR}
fi
fi
# Remove user and settings
if [[ "$RM_USER" = 'y' ]]; then
# Stop and disable invidious
system_cmd stop ${SERVICE_NAME}
read_sleep 1
system_cmd restart ${PGSQL_SERVICE}
read_sleep 1
system_cmd daemon-reload
read_sleep 1
grep $USER_NAME /etc/passwd >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo ""
echo -e "${YELLOW}${ARROW} User $USER_NAME Found, removing user and files${NORMAL}"
echo ""
shopt -s nocasematch
if [[ $DISTRO_GROUP == "Debian" ]]; then
${SUDO} deluser --remove-home $USER_NAME
fi
if [[ $DISTRO_GROUP == "RHEL" ]]; then
/usr/sbin/userdel -r $USER_NAME
fi
fi
fi
if [ -d /etc/logrotate.d ]; then
rm /etc/logrotate.d/invidious.logrotate
fi
# We're done !
echo ""
echo -e "${GREEN}${CHECK} Un-installation done.${NORMAL}"
echo ""
read_sleep 3
tput cnorm
exit 0
}
if [ "$mode" = "uninstall" ]; then
uninstall_invidious
fi
install_invidious() {
chk_git_repo
if [ "$BANNERS" = "1" ]; then
installer_preinstall_banner
fi