-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
invidious_update.sh
executable file
·2320 lines (2176 loc) · 72.5 KB
/
invidious_update.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=SC2181,SC2059,SC2086,SC2002,SC2162,SC2005,SC2015,SC2308,SC2006,SC2236,SC2231,SC1091
## Author: Tommy Miland (@tmiland) - Copyright (c) 2024
######################################################################
#### Invidious Update.sh ####
#### Automatic update script for Invidious ####
#### Script to update or install Invidious ####
#### Maintained by @tmiland ####
######################################################################
VERSION='2.2.3' # 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.
#
#------------------------------------------------------------------------------#
## Take 'debug' as argument for debugging purpose
if [[ $* =~ "debug" ]]
then
set -o errexit
set -o pipefail
set -o nounset
set -o xtrace
fi
#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}")
# Icons used for printing
ARROW='➜'
DONE='✔'
ERROR='✗'
WARNING='⚠'
# Colors used for printing
RED='\033[0;31m'
BLUE='\033[0;34m'
BBLUE='\033[1;34m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
# DARKORANGE="\033[38;5;208m"
# CYAN='\033[0;36m'
# DARKGREY="\033[48;5;236m"
NC='\033[0m' # No Color
# Text formatting used for printing
# BOLD="\033[1m"
# DIM="\033[2m"
# UNDERLINED="\033[4m"
# INVERT="\033[7m"
# HIDDEN="\033[8m"
# Script name
SCRIPT_NAME="Invidious Update.sh"
# Repo name
REPO_NAME="tmiland/invidious-updater"
# Set update check
UPDATE_SCRIPT=${UPDATE_SCRIPT:-'yes'}
# 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:-false}
# Default external port
EXTERNAL_PORT=${EXTERNAL_PORT:-}
# Default admins
ADMINS=${ADMINS:-}
# Default Captcha Key
CAPTCHA_KEY=${CAPTCHA_KEY:-}
# Default Swap option
SWAP_OPTIONS=${SWAP_OPTIONS:-}
# Logfile
LOGFILE=invidious_update.log
install_log() {
exec > >(tee ${LOGFILE}) 2>&1
}
read_sleep() {
read -rt "$1" <> <(:) || :
}
indexit() {
cd "${CURRDIR}" || exit
UPDATE_SCRIPT='no' \
./"${SCRIPT_FILENAME}"
}
repoexit() {
cd ${REPO_DIR} || exit 1
}
# Distro support
ARCH_CHK=$(uname -m)
if [ ! ${ARCH_CHK} == 'x86_64' ]; then
echo -e "${RED}${ERROR} Error: Sorry, your OS ($ARCH_CHK) is not supported.${NC}"
exit 1;
fi
shopt -s nocasematch
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
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}${ERROR} unknown distro: '$DISTRO'${NC}" ; exit 1 ;;
esac
if ! lsb_release -si >/dev/null 2>&1; then
echo ""
echo -e "${RED}${ERROR} Looks like ${LSB} is not installed!${NC}"
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}...${NC}"
su -s "$(which bash)" -c "${PKGCMD} ${LSB}" || echo -e "${RED}${ERROR} Error: could not install ${LSB}!${NC}"
echo -e "${GREEN}${DONE} Done${NC}"
read_sleep 3
indexit
;;
[Nn]* )
exit 1;
;;
* ) echo "Enter Y, N, please." ;;
esac
fi
SUDO=""
UPDATE=""
UPGRADE=""
INSTALL=""
UNINSTALL=""
PURGE=""
CLEAN=""
PKGCHK=""
PGSQL_SERVICE=""
DOCKER_PKGS=""
SYSTEM_CMD=""
SHOW_STATUS=""
SHOW_DOCKER_STATUS=""
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"
# Docker pkgs
DOCKER_PKGS="docker-ce docker-ce-cli containerd.io docker-compose-plugin"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(if [[ -d "/etc/postgresql/" ]]; then find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1; fi)
elif [[ $(lsb_release -si) == "CentOS" ]]; then
SUDO="sudo"
UPDATE="yum update -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"
#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"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# Docker pkgs
DOCKER_PKGS="docker-ce docker-ce-cli containerd.io docker-compose-plugin"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(if [[ -d "/etc/postgresql/" ]]; then find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1; fi)
elif [[ $(lsb_release -si) == "Fedora" ]]; then
SUDO="sudo"
UPDATE="dnf update -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"
#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"
# PostgreSQL Service
PGSQL_SERVICE="postgresql"
# Docker pkgs
DOCKER_PKGS="docker-ce docker-ce-cli containerd.io docker-compose-plugin"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder=$(if [[ -d "/etc/postgresql/" ]]; then find "/etc/postgresql/" -maxdepth 1 -type d -name "*" | sort -V | tail -1; fi)
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"
# Docker pkgs
DOCKER_PKGS="docker"
# System cmd
SYSTEM_CMD="systemctl"
# Postgresql config folder
pgsql_config_folder="/var/lib/postgres/data"
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
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}${ERROR} Error: Sorry, you need systemd to run this script.${NC}"
exit 1;
fi
fi
usage() {
# shellcheck disable=SC2046
printf "Usage: %s %s [options]\\n" "" $(basename "$0")
echo
echo " If called without arguments, installs Invidious."
echo
printf " ${ORANGE}--help |-h${NC} Display this help and exit\\n"
printf " ${ORANGE}--install-invidious |-i${NC} Install Invidious\\n"
printf " ${ORANGE}--cron-update |-c${NC} Update Invidious with cron\\n"
printf " ${ORANGE}--database-maintenance |-m${NC} Database Maintenance\\n"
printf " ${ORANGE}--install-log |-l${NC} Activate logging\\n"
printf " ${ORANGE}--install-inv-sig-helper |-iish${NC} Install Inv-sig-helper\\n"
printf " ${ORANGE}--install-ytsg |-iytsg${NC} Install YouTube trusted session generator\\n"
printf " ${ORANGE}--ytsg-docker |-uytsgd${NC} Update YouTube ts tokens for Docker\\n"
echo
}
# Make sure that the script runs with root permissions
chk_permissions() {
if [[ "$EUID" != 0 ]]; then
echo -e "${RED}${ERROR} This action needs root permissions."
echo -e "${NC} Please enter your root password...";
cd "$CURRDIR" || exit
su -s "$(which bash)" -c "./$SCRIPT_FILENAME"
cd - > /dev/null || exit
exit 0;
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}${ERROR} This script requires curl or wget.\nProcess aborted${NC}"
exit 0
fi
read_sleep 3
indexit
}
install_nginx(){
echo ""
echo " 1) Install Nginx"
echo " 2) Install Nginx Vhost for Invidious"
echo " 3) Install Let's Encrypt SSL certificates"
echo ""
while [[ $NGINX != "1" && $NGINX != "2" && $NGINX != "3" ]]; do
read -p "Select an option [1-3]: " NGINX
done
case $NGINX in
1)
nginx-autoinstall
;;
2)
install_nginx_vhost
;;
3)
install_certbot
;;
esac
}
install_certbot() {
shopt -s nocasematch
if [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "LinuxMint" ||
$(lsb_release -si) == "PureOS" ]]; then
NGINX_VHOST_DIR=/etc/nginx/sites-available
get_domain() {
# shellcheck disable=SC2046
echo $(sed -n 's/.*domain *: *\([^ ]*.*\)/\1/p' "$1")
}
NGINX_DOMAIN_NAME=$(get_domain "$IN_CONFIG")
NGINX_VHOST=$NGINX_DOMAIN_NAME.conf
if [[ -d "${NGINX_VHOST_DIR}" ]]; then
echo ""
read -p "Do you want to install Let's Encrypt SSL certificates for Invidious? [y/n/q]?" ANSWER
echo ""
echo "Your Invidious domain name: $NGINX_DOMAIN_NAME"
echo ""
case $ANSWER in
[Yy]* )
# Ask user for admin email
read -p "Please enter your admin email for the domain [E.G: [email protected]]:" ADMIN_EMAIL
# Set Acme home folder ()
ACME_HOME=/etc/acme
# Install dependencies
apt-get install openssl cron socat curl
# Clone from GitHub
git clone https://github.com/Neilpang/acme.sh.git
# Do the work
cd acme.sh || exit
./acme.sh --install \
--home $ACME_HOME \
--config-home $ACME_HOME/data \
--cert-home $ACME_HOME/certs \
--accountemail "${ADMIN_EMAIL}" \
--accountkey $ACME_HOME/account.key \
--accountconf $ACME_HOME/account.conf \
--useragent "Acme client"
# Issue cert
# Use for debugging: --force --test --debug
/etc/acme/acme.sh --issue -d ${NGINX_DOMAIN_NAME} -w /etc/nginx/html --server letsencrypt && echo "Successfully issued Let's Encrypt SSL certificates for Invidious" || echo "Error issuing Let's Encrypt SSL certificates!"
# Install cert
${SUDO} mkdir -p /etc/nginx/certs/${NGINX_DOMAIN_NAME}
/etc/acme/acme.sh --install-cert -d ${NGINX_DOMAIN_NAME} \
--cert-file /etc/nginx/certs/${NGINX_DOMAIN_NAME}/${NGINX_DOMAIN_NAME}.cert \
--key-file /etc/nginx/certs/${NGINX_DOMAIN_NAME}/${NGINX_DOMAIN_NAME}.key \
--fullchain-file /etc/nginx/certs/${NGINX_DOMAIN_NAME}/${NGINX_DOMAIN_NAME}.fullchain \
# --reloadcmd "$SYSTEM_CMD reload nginx"
nginx -t && ${SUDO} $SYSTEM_CMD restart nginx || echo "Error restarting nginx!"
if [ $? -eq 0 ]; then
${SUDO} sed -i "s/# listen/listen/g" $NGINX_VHOST_DIR/$NGINX_VHOST
${SUDO} sed -i "s/# ssl_certificate/ssl_certificate/g" $NGINX_VHOST_DIR/$NGINX_VHOST
# shellcheck disable=SC2154
${SUDO} sed -i "s/# if ($scheme/if ($scheme/g" $NGINX_VHOST_DIR/$NGINX_VHOST
${SUDO} sed -i "s/# return 301/ return 301/g" $NGINX_VHOST_DIR/$NGINX_VHOST
${SUDO} sed -i "s/# }/}/g" $NGINX_VHOST_DIR/$NGINX_VHOST
if [ -f "$IN_CONFIG" ]; then
https_only() {
# shellcheck disable=SC2046
echo $(sed -n 's/.*https_only *: *\([^ ]*.*\)/\1/p' "$1")
}
HTTPS_ONLY=$(https_only "$IN_CONFIG")
if [[ $HTTPS_ONLY == "false" ]]; then
while [[ $HTTPS_ONLY != "y" && $HTTPS_ONLY != "n" ]]; do
read -p "Do you want to turn on https in invidious? [y/n]: " HTTPS_ONLY
done
case $HTTPS_ONLY in
[Yy]* )
${SUDO} sed -i "s/https_only: false/https_only: true/g" $IN_CONFIG
${SUDO} sed -i "s/external_port: /external_port: 443/g" $IN_CONFIG
${SUDO} $SYSTEM_CMD restart invidious
;;
[Nn]* )
exit 1
;;
esac
else
echo "https_only is already set to 443 in Invidious config!"
fi
fi
echo "done!"
sleep 3
indexit
else
echo "something went wrong!"
fi
;;
[Nn]* )
sleep 3
indexit
;;
* ) echo "Enter Y, N or Q, please." ;;
esac
else
echo -e "${RED}${ERROR} Nginx vhost is not installed. Choose option 2 first.${NC}"
sleep 3
indexit
fi
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
indexit
fi
}
NGINX_AUTOINSTALL_URL=https://github.com/angristan/nginx-autoinstall/raw/master/nginx-autoinstall.sh
nginx-autoinstall() {
shopt -s nocasematch
if [[ $DISTRO_GROUP == "Debian" ]]; then
if [[ $(command -v 'curl') ]]; then
# shellcheck disable=SC1090
source <(curl -sSLf $NGINX_AUTOINSTALL_URL)
elif [[ $(command -v 'wget') ]]; then
# shellcheck disable=SC1090
. <(wget -qO - $NGINX_AUTOINSTALL_URL)
else
echo -e "${RED}${ERROR} This script requires curl or wget.\nProcess aborted${NC}"
exit 0
fi
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
exit 1;
fi
}
install_nginx_vhost() {
NGINX_VHOST_DIR=/etc/nginx/sites-available
get_domain() {
echo "$(sed -n 's/.*domain *: *\([^ ]*.*\)/\1/p' "$1")"
}
get_host() {
echo "$(sed -n 's/.*host *: *\([^ ]*.*\)/\1/p' "$1")"
}
# get_port() {
# echo $(sed -n 's/.*port *: *\([^ ]*.*\)/\2/p' "$1")
# }
NGINX_DOMAIN_NAME=$(get_domain "$IN_CONFIG")
NGINX_HOST=$(get_host "$IN_CONFIG")
#NGINX_PORT=$(get_port "$IN_CONFIG")
NGINX_VHOST=$NGINX_DOMAIN_NAME.conf
if [[ -d "${NGINX_VHOST_DIR}" ]]; then
echo ""
read -p "Do you want to install a nginx vhost file for Invidious? [y/n/q]?" ANSWER
echo ""
echo "Your Invidious domain name: $NGINX_DOMAIN_NAME"
echo ""
case $ANSWER in
[Yy]* )
tee $NGINX_VHOST_DIR/default.conf <<'EOF' >/dev/null
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _; # This is just an invalid value which will never trigger on a real hostname.
#access_log logs/default.access.log main;
server_name_in_redirect off;
root /etc/nginx/html;
}
EOF
tee $NGINX_VHOST_DIR/$NGINX_VHOST <<'EOF' >/dev/null
server {
listen 80;
listen [::]:80;
server_name invidious.domain.tld;
access_log off;
error_log /var/log/nginx/error.log crit;
location ^~ /.well-known/acme-challenge {
root /etc/nginx/html;
}
# Redirect HTTP to HTTPS
# if ($scheme = http) {
# return 301 https://$server_name$request_uri;
# }
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# ssl_certificate /etc/nginx/certs/invidious.domain.tld/invidious.domain.tld.cert;
# ssl_certificate_key /etc/nginx/certs/invidious.domain.tld/invidious.domain.tld.key;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host; # so Invidious knows domain
proxy_http_version 1.1; # to keep alive
proxy_set_header Connection ""; # to keep alive
}
}
EOF
${SUDO} sed -i "s/127.0.0.1/${NGINX_HOST}/g" $NGINX_VHOST_DIR/$NGINX_VHOST
${SUDO} sed -i "s/invidious.domain.tld/${NGINX_DOMAIN_NAME}/g" $NGINX_VHOST_DIR/$NGINX_VHOST
${SUDO} ln -s $NGINX_VHOST_DIR/$NGINX_VHOST /etc/nginx/sites-enabled/$NGINX_VHOST
${SUDO} chown -R root:www-data /etc/nginx/html
nginx -t && $SYSTEM_CMD reload nginx && echo "Successfully installed nginx vhost $NGINX_VHOST_DIR/$NGINX_VHOST" || echo "Error installing nginx vhost!"
sleep 3
indexit
;;
[Nn]* )
read_sleep 3
indexit
;;
* ) echo "Enter Y, N or Q, please." ;;
esac
else
echo -e "${RED}${ERROR} Nginx is not installed${NC}"
read_sleep 3
indexit
fi
}
## Update invidious_update.sh
## Source: ghacks-user.js updater for macOS and Linux
# Download method priority: curl -> wget
DOWNLOAD_METHOD=''
if [[ $(command -v 'curl') ]]; then
DOWNLOAD_METHOD='curl'
elif [[ $(command -v 'wget') ]]; then
# shellcheck disable=SC2034
DOWNLOAD_METHOD='wget'
else
echo -e "${RED}${ERROR} This script requires curl or wget.\nProcess aborted${NC}"
exit 0
fi
# Download files
download_file() {
declare -r URL=$1
# shellcheck disable=SC2155
declare -r TF=$(mktemp)
local DLCMD=''
#if [ $DOWNLOAD_METHOD = 'curl' ]; then
# DLCMD="curl -o $TF"
#else
DLCMD="wget -O $TF"
#fi
$DLCMD "${URL}" &>/dev/null && echo "$TF" || echo '' # return the temp-filename (or empty string on error)
}
# Open files
open_file() { #expects one argument: file_path
if [ "$(uname)" == 'Darwin' ]; then
open "$1"
elif [ "$(expr substr "$(uname -s)" 1 5)" == "Linux" ]; then
xdg-open "$1"
else
echo -e "${RED}${ERROR} Error: Sorry, opening files is not supported for your OS.${NC}"
fi
}
get_release_info() {
# Get latest release tag from GitHub
get_latest_release_tag() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"tag_name":' |
sed -n 's/[^0-9.]*\([0-9.]*\).*/\1/p'
}
RELEASE_TAG=$(get_latest_release_tag ${REPO_NAME})
# Get latest release download url
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep 'browser_download_url.*\.sh' |
sed -n 's#.*\(https*://[^"]*\).*#\1#;p'
}
LATEST_RELEASE=$(get_latest_release ${REPO_NAME})
# Get latest release notes
get_latest_release_note() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"body":' |
sed -n 's/.*"\([^"]*\)".*/\1/;p'
}
RELEASE_NOTE=$(get_latest_release_note ${REPO_NAME})
# Get latest release title
get_latest_release_title() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep -m 1 '"name":' |
sed -n 's/.*"\([^"]*\)".*/\1/;p'
}
RELEASE_TITLE=$(get_latest_release_title ${REPO_NAME})
}
# Returns the version number of invidious_update.sh file on line 14
get_updater_version() {
# shellcheck disable=SC2046
echo $(sed -n '14 s/[^0-9.]*\([0-9.]*\).*/\1/p' "$1")
}
# Show service status - @FalconStats
show_status() {
# if [[ $(lsb_release -si) == "CentOS" || $(lsb_release -si) == "Fedora" ]]; then
# declare -a services=(
# "invidious"
# "postgresql-11"
# )
# else
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}${NC}${serviceName[$i]}: ${GREEN}● ${serviceStatus[$i]}${NC} "
else
line+="${serviceName[$i]}: ${RED}▲ ${serviceStatus[$i]}${NC} "
fi
done
echo -e "$line"
}
if ( $SYSTEM_CMD -q is-active ${SERVICE_NAME}); then
SHOW_STATUS=$(show_status)
fi
# Show Docker Status
show_docker_status() {
declare -a container=(
"invidious-invidious-1"
"invidious-inv_sig_helper-1"
"invidious-invidious-db-1"
)
declare -a containerName=(
"Invidious"
"Inv-sig-helper"
"PostgreSQL"
)
declare -a status=()
echo ""
echo "Docker Status:"
running_containers="$( docker ps )"
for container_name in "${container[@]}"
do
#status+=($(docker ps "$container_name"))
status+=("$( echo -n "$running_containers" | grep -oP "(?<= )$container_name$" | wc -l )")
done
for i in "${!status[@]}"
do
# shellcheck disable=SC2128
if [[ "$status" = "1" ]] ; then
line+="${containerName[$i]}: ${GREEN}● running${NC} "
else
line+="${containerName[$i]}: ${RED}▲ stopped${NC} "
fi
done
echo -e "$line"
}
if ( ! $SYSTEM_CMD -q is-active ${SERVICE_NAME}); then
if docker ps >/dev/null 2>&1; then
SHOW_DOCKER_STATUS=$(show_docker_status)
fi
fi
# Run pgbackup
pgbackup() {
if [[ ! -d "${CURRDIR}/pgbackup" ]]; then
printf "\n-- Setting up pgbackup\n"
git clone https://github.com/tmiland/pgbackup.git
cd pgbackup || exit
shopt -s nocasematch
if [[ $DISTRO_GROUP == "RHEL" ]]; then
pgsqlConfigPath=/var/lib/pgsql/data
elif [[ $DISTRO_GROUP == "Debian" ]]; then
pgsqlConfigPath=$pgsql_config_folder/main
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
exit 1;
fi
cp -rp $pgsqlConfigPath/pg_hba.conf $pgsqlConfigPath/pg_hba.conf.bak
#sed -i "s/USERNAME=postgres/USERNAME=$USER_NAME/g" ./pg_backup.conf
echo "# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# local is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5" | ${SUDO} tee $pgsqlConfigPath/pg_hba.conf
#${SUDO} -i -u postgres sed -i "s/local all postgres peer/local all postgres trust/g" /etc/postgresql/9.6/main/pg_hba.conf
${SUDO} $SYSTEM_CMD restart ${PGSQL_SERVICE}
read_sleep 1
chmod +x pg_backup_rotated.sh && chmod +x pg_backup.sh
fi
printf "\n-- Running pgbackup\n"
cd ${CURRDIR}/pgbackup || exit
bash ./pg_backup.sh
cd - || exit
printf "\n"
echo -e "${GREEN}${DONE} Done ${REPO_DIR} ${NC}"
read_sleep 3
indexit
}
# BANNERS
# Documentation link
doc_link() {
echo -e "Documentation for this script is available here: ${ORANGE}\n ${ARROW} https://github.com/${REPO_NAME}${NC}\n"
}
# Header
header() {
echo -e "${GREEN}\n"
echo ' ╔═══════════════════════════════════════════════════════════════════╗'
echo ' ║ '"${SCRIPT_NAME}"' ║'
echo ' ║ Automatic update script for Invidious ║'
echo ' ║ Maintained by @tmiland ║'
echo ' ║ version: '${VERSION}' ║'
echo ' ╚═══════════════════════════════════════════════════════════════════╝'
echo -e "${NC}"
}
# Update banner
show_update_banner() {
clear
header
echo "Welcome to the ${SCRIPT_NAME} script."
echo ""
echo "There is a newer version of ${SCRIPT_NAME} available."
echo ""
echo ""
echo -e "${GREEN}${DONE} New version:${NC} ""${RELEASE_TAG}"" - ${RELEASE_TITLE}"
echo ""
echo -e "${ORANGE}${ARROW} Notes:${NC}\n"
echo -e "${BLUE}${RELEASE_NOTE}${NC}"
echo ""
}
# Preinstall banner
show_preinstall_banner() {
clear
header
echo "Thank you for using the ${SCRIPT_NAME} script."
echo ""
echo ""
echo ""
doc_link
}
# Install banner
show_install_banner() {
#clear
header
echo ""
echo ""
echo ""
echo "Thank you for using the ${SCRIPT_NAME} script."
echo ""
echo ""
echo ""
echo -e "${GREEN}${DONE} Invidious install done.${NC} Now visit http://${IP}:${PORT}"
echo ""
echo ""
echo ""
echo ""
doc_link
}
# Maintenance banner
show_maintenance_banner() {
#clear
header
echo ""
echo ""
echo ""
echo "Thank you for using the ${SCRIPT_NAME} script."
echo ""
echo ""
echo ""
echo -e "${GREEN}${DONE} Invidious maintenance done.${NC}"
echo ""
echo ""
echo ""
echo ""
doc_link
}
# Banner
show_banner() {
#clear
header
echo "Welcome to the ${SCRIPT_NAME} script."
echo "What do you want to do?"
echo "
1) Install Invidious 7) Uninstall Invidious
2) Update Invidious 8) Set up PostgreSQL Backup
3) Deploy with Docker 9) Install Nginx
4) Add Swap Space 10) Install Inv sig helper
5) Run Database Maintenance 11) Install YouTube tsg.
6) Start, Stop or Restart 12) Exit"
echo "${SHOW_STATUS} ${SHOW_DOCKER_STATUS}"
echo ""
doc_link
}
# Exit Script
exit_script() {
#header
echo -e "${GREEN}"
echo ' ____ _ ___ '
echo ' / _/___ _ __(_)___/ (_)___ __ _______ '
echo ' / // __ \ | / / / __ / / __ \/ / / / ___/ '
echo ' _/ // / / / |/ / / /_/ / / /_/ / /_/ (__ ) '
echo ' /___/_/ /_/|___/_/\__,_/_/\____/\__,_/____/ '
echo ' __ __ __ __ __ '
echo ' / / / /___ ____/ /___ _/ /____ _____/ /_ '
echo ' / / / / __ \/ __ / __ `/ __/ _ \ / ___/ __ \ '
echo ' / /_/ / /_/ / /_/ / /_/ / /_/ __/ (__ ) / / / '
echo ' \____/ .___/\__,_/\__,_/\__/\___(_)____/_/ /_/ '
echo -e ' /_/ ' "${NC}"
#echo -e "${NC}"
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}
"
doc_link
echo -e "${ORANGE}${ARROW} Goodbye.${NC} ☺"
echo ""
}
# Check Git repo
chk_git_repo() {
# Check if the folder is a git repo
if [[ -d "${REPO_DIR}/.git" ]]; then
echo ""
echo -e "${RED}${ERROR} Looks like Invidious is already installed!${NC}"
echo ""
echo -e "${ORANGE}${WARNING} If you want to reinstall, please choose option 7 to Uninstall Invidious first!${NC}"
echo ""
read_sleep 3
indexit
#exit 1
fi
}
update_invidious_docker() {
repoexit
docker compose pull
docker compose up -d
docker image prune -f
read_sleep 5
indexit
}
install_docker() {
DOCKER_VER=stable
echo ""
echo "This will install Docker CE."
echo ""
echo ""
read -n1 -r -p "Docker is ready to be installed, press any key to continue..."
echo ""
# Update the apt package index:
${SUDO} ${UPDATE}
shopt -s nocasematch
if [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "PureOS" ]]; then
CODENAME=$(lsb_release -cs)
DISTRO=$(lsb_release -si)
DISTRO_TO_LOWER="${DISTRO,}"
#Install packages to allow apt to use a repository over HTTPS:
${SUDO} ${INSTALL} \