forked from tmiland/invidious-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invidious_update.sh
executable file
·1989 lines (1806 loc) · 60.6 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
## Author: Tommy Miland (@tmiland) - Copyright (c) 2020
######################################################################
#### Invidious Update.sh ####
#### Automatic update script for Invidious ####
#### Script to update or install Invidious ####
#### Maintained by @tmiland ####
######################################################################
version='1.5.3' # Must stay on line 14 for updater to fetch the numbers
#------------------------------------------------------------------------------#
#
# MIT License
#
# Copyright (c) 2020 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)"
CURRDIR=$(pwd)
SCRIPT_FILENAME=$(basename $0)
cd - > /dev/null
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='no'
# 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=invidious.tube
# Default ip
ip=localhost
# Default port
port=3000
# Default dbname
psqldb=invidious
# Default dbpass
psqlpass=kemal
# Default https only
https_only=false
# Default external port
external_port=
# Docker compose repo name
COMPOSE_REPO_NAME="docker/compose"
# 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
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
case "$DISTRO" in
Debian*)
PKGCMD="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
LSB=lsb-release
;;
Ubuntu*)
PKGCMD="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
LSB=lsb-release
;;
LinuxMint*)
PKGCMD="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
LSB=lsb-release
;;
PureOS*)
PKGCMD="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
LSB=lsb-release
;;
CentOS*)
PKGCMD="yum install -y"
LSB=redhat-lsb
;;
Fedora*)
PKGCMD="dnf install -y"
LSB=redhat-lsb
;;
Arch*)
PKGCMD="yes | LC_ALL=en_US.UTF-8 pacman -S"
LSB=lsb-release
;;
Manjaro*)
PKGCMD="yes | LC_ALL=en_US.UTF-8 pacman -S"
LSB=lsb-release
;;
*) echo -e "${RED}${ERROR} unknown distro: '$DISTRO'${NC}" ; exit 1 ;;
esac
echo ""
echo -e "${RED}${ERROR} Looks like ${LSB} is not installed!${NC}"
echo ""
read -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}"
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
;;
[Nn]* )
exit 1;
;;
* ) echo "Enter Y, N, please." ;;
esac
fi
SUDO=""
UPDATE=""
INSTALL=""
UNINSTALL=""
PURGE=""
CLEAN=""
PKGCHK=""
PGSQL_SERVICE=""
shopt -s nocasematch
if [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "LinuxMint" ||
$(lsb_release -si) == "PureOS"
]]; then
export DEBIAN_FRONTEND=noninteractive
SUDO="sudo"
UPDATE="apt-get -o Dpkg::Progress-Fancy="1" update -qq"
INSTALL="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
UNINSTALL="apt-get -o Dpkg::Progress-Fancy="1" remove -qq"
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 libssl-dev libxml2-dev libyaml-dev libgmp-dev libreadline-dev librsvg2-bin postgresql libsqlite3-dev"
#Uninstall packages
UNINSTALL_PKGS="crystal libssl-dev libxml2-dev libyaml-dev libgmp-dev libreadline-dev librsvg2-bin libsqlite3-dev"
# PostgreSQL Service
PGSQL_SERVICE="postgresql.service"
elif [[ $(lsb_release -si) == "CentOS" ]]; then
SUDO="sudo"
UPDATE="yum update -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"
# Install packages
INSTALL_PKGS="crystal openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel"
#Uninstall packages
UNINSTALL_PKGS="crystal openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel"
# PostgreSQL Service
PGSQL_SERVICE="postgresql-11.service"
elif [[ $(lsb_release -si) == "Fedora" ]]; then
SUDO="sudo"
UPDATE="dnf update -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 openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel"
#Uninstall packages
UNINSTALL_PKGS="crystal openssl-devel libxml2-devel libyaml-devel gmp-devel readline-devel librsvg2-tools sqlite-devel"
# PostgreSQL Service
PGSQL_SERVICE="postgresql-11.service"
elif [[ $(lsb_release -si) == "Arch" ||
$(lsb_release -si) == "ManjaroLinux"
]]; 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="base-devel shards crystal librsvg postgresql"
#Uninstall packages
UNINSTALL_PKGS="base-devel shards crystal librsvg"
# PostgreSQL Service
PGSQL_SERVICE="postgresql.service"
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
exit 1;
fi
# Make sure that the script runs with root permissions
chk_permissions() {
if [[ "$EUID" != 0 ]]; then
echo -e "${RED}${ERROR} This action needs root permissions.${NC} Please enter your root password...";
cd "$CURRDIR"
su -s "$(which bash)" -c "./$SCRIPT_FILENAME"
cd - > /dev/null
exit 0;
fi
}
add_swap_url=https://raw.githubusercontent.com/tmiland/swap-add/master/swap-add.sh
add_swap() {
if [[ $(command -v 'curl') ]]; then
source <(curl -sSLf $add_swap_url)
elif [[ $(command -v 'wget') ]]; then
. <(wget -qO - $add_swap_url)
else
echo -e "${RED}${ERROR} This script requires curl or wget.\nProcess aborted${NC}"
exit 0
fi
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
}
install_nginx(){
echo ""
echo " 1) Install Nginx"
echo " 2) Install Nginx Vhost for Invidious"
echo ""
while [[ $NGINX != "1" && $NGINX != "2" ]]; do
read -p "Select an option [1-2]: " NGINX
done
case $NGINX in
1)
nginx-autoinstall
;;
2)
install_nginx_vhost
;;
esac
}
nginx_autoinstall_url=https://github.com/angristan/nginx-autoinstall/raw/master/nginx-autoinstall.sh
nginx-autoinstall() {
shopt -s nocasematch
if [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "LinuxMint" ||
$(lsb_release -si) == "PureOS"
]]; then
if [[ $(command -v 'curl') ]]; then
source <(curl -sSLf $nginx_autoinstall_url)
elif [[ $(command -v 'wget') ]]; then
. <(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;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name invidious.domain.tld;
access_log off;
error_log /var/log/nginx/error.log crit;
ssl_certificate /etc/letsencrypt/live/invidious.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/invidious.domain.tld/privkey.pem;
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
}
if ($https = '') { return 301 https://"$host$request_uri"; } # if not connected to HTTPS, perma-redirect to HTTPS
}
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
nginx -t && systemctl reload nginx || echo "Successfully installed nginx vhost $NGINX_VHOST_DIR/$NGINX_VHOST"
;;
[Nn]* )
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
;;
* ) echo "Enter Y, N or Q, please." ;;
esac
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
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
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 latest Docker compose release tag from GitHub
get_compose_release_tag() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"tag_name":' |
sed -n 's/[^0-9.]*\([0-9.]*\).*/\1/p'
}
Docker_Compose_Ver=$(get_compose_release_tag ${COMPOSE_REPO_NAME})
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":' |
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() {
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+=($(systemctl is-active "$service.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 ( systemctl -q is-active ${SERVICE_NAME}); then
SHOW_STATUS=$(show_status)
fi
# Show Docker Status
show_docker_status() {
declare -a container=(
"invidious_invidious_1"
"invidious_postgres_1"
)
declare -a containerName=(
"Invidious"
"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
if [[ "$status" = "1" ]] ; then
line+="${containerName[$i]}: ${GREEN}● running${NC} "
else
line+="${containerName[$i]}: ${RED}▲ stopped${NC} "
fi
done
echo -e "$line"
}
if ( ! systemctl -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
shopt -s nocasematch
if [[ $(lsb_release -si) == "CentOS" ||
$(lsb_release -si) == "Fedora"
]]; then
pgsqlConfigPath=/var/lib/pgsql/11/data
elif [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "LinuxMint" ||
$(lsb_release -si) == "PureOS"
]]; then
pgsqlConfigPath=/etc/postgresql/9.6/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} systemctl restart ${PGSQL_SERVICE}
sleep 1
chmod +x pg_backup_rotated.sh && chmod +x pg_backup.sh
fi
printf "\n-- Running pgbackup\n"
cd ${CURRDIR}/pgbackup
bash ./pg_backup.sh
cd -
printf "\n"
echo -e "${GREEN}${DONE} Done ${REPO_DIR} ${NC}"
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
}
# BANNERS
# 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 ""
echo -e "Documentation for this script is available here: ${ORANGE}\n ${ARROW} https://github.com/tmiland/Invidious-Updater${NC}\n"
}
# 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 ""
echo -e "Documentation for this script is available here: ${ORANGE}\n ${ARROW} https://github.com/tmiland/Invidious-Updater${NC}\n"
}
# 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 ""
echo -e "Documentation for this script is available here: ${ORANGE}\n ${ARROW} https://github.com/tmiland/Invidious-Updater${NC}\n"
}
# Banner
show_banner() {
#clear
header
echo "Welcome to the ${SCRIPT_NAME} script."
echo ""
echo "What do you want to do?"
echo ""
echo " 1) Install Invidious 6) Start, Stop or Restart "
echo " 2) Update Invidious 7) Uninstall Invidious "
echo " 3) Deploy with Docker 8) Set up PostgreSQL Backup "
echo " 4) Add Swap Space 9) Install Nginx "
echo " 5) Run Database Maintenance 10) Exit "
echo "${SHOW_STATUS} ${SHOW_DOCKER_STATUS}"
echo ""
echo -e "Documentation for this script is available here: ${ORANGE}\n ${ARROW} https://github.com/tmiland/Invidious-Updater${NC}\n"
}
# 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}${DONE}${NC} ${BBLUE}Paypal${NC} ${ARROW} ${ORANGE}https://paypal.me/milanddata${NC}
${GREEN}${DONE}${NC} ${BBLUE}BTC${NC} ${ARROW} ${ORANGE}3MV69DmhzCqwUnbryeHrKDQxBaM724iJC2${NC}
${GREEN}${DONE}${NC} ${BBLUE}BCH${NC} ${ARROW} ${ORANGE}qznnyvpxym7a8he2ps9m6l44s373fecfnv86h2vwq2${NC}
"
echo -e "Documentation for this script is available here: ${ORANGE}\n${ARROW} https://github.com/tmiland/Invidious-Updater${NC}\n"
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 ""
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
#exit 1
fi
}
docker_repo_chk() {
# Check if the folder is a git repo
if [[ ! -d "${REPO_DIR}/.git" ]]; then
#if (systemctl -q is-active invidious.service) && -d "${REPO_DIR}/.git" then
echo ""
echo -e "${RED}${ERROR} Looks like Invidious is not installed!${NC}"
echo ""
read -p "Do you want to download Invidious? [y/n/q]?" answer
echo ""
case $answer in
[Yy]* )
echo -e "${GREEN}${ARROW} Setting up Dependencies${NC}"
if ! ${PKGCHK} $PRE_INSTALL_PKGS >/dev/null 2>&1; then
${UPDATE}
for i in $PRE_INSTALL_PKGS; do
${INSTALL} $i 2> /dev/null # || exit 1
done
fi
mkdir -p $USER_DIR
echo -e "${GREEN}${ARROW} Downloading Invidious from GitHub${NC}"
cd $USER_DIR || exit 1
git clone https://github.com/tbugatti/invidious
cd ${REPO_DIR} || exit 1
# Checkout
GetMaster
;;
[Nn]* )
sleep 3
cd ${CURRDIR}
./${SCRIPT_FILENAME}
;;
* ) echo "Enter Y, N or Q, please." ;;
esac
fi
}
# Set permissions
set_permissions() {
${SUDO} chown -R $USER_NAME:$USER_NAME $USER_DIR
${SUDO} chmod -R 755 $USER_DIR
}
# 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
echo -e "${GREEN}${ARROW} Updating config.yml with new info...${NC}"
# Add external_port: to config on line 13
sed -i "11i\external_port:" "$f" > $TFILE
sed -i "12i\check_tables: true" "$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"
else
echo -e "${RED}${ERROR} Error: Cannot read $f"
fi
done
if [[ -e $TFILE ]]; then
/bin/rm $TFILE
else
echo -e "${GREEN}${DONE} Done.${NC}"
fi
# Done updating config.yml with new info!
# Source: https://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/
}
# Systemd install
systemd_install() {
# Setup Systemd Service
cp ${REPO_DIR}/${SERVICE_NAME} /lib/systemd/system/${SERVICE_NAME}
${SUDO} sed -i "s/invidious -o invidious.log/invidious -b ${ip} -p ${port} -o invidious.log/g" /lib/systemd/system/${SERVICE_NAME}
# Enable invidious start at boot
${SUDO} systemctl enable ${SERVICE_NAME}
# Reload Systemd
${SUDO} systemctl daemon-reload
# Restart Invidious
${SUDO} systemctl start ${SERVICE_NAME}
if ( systemctl -q is-active ${SERVICE_NAME})
then
echo -e "${GREEN}${DONE} Invidious service has been successfully installed!${NC}"
${SUDO} systemctl status ${SERVICE_NAME} --no-pager
sleep 5
else
echo -e "${RED}${ERROR} Invidious service installation failed...${NC}"
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
chmod 0644 /etc/logrotate.d/invidious.logrotate
echo " (done)"
fi
}
# Get Crystal
get_crystal() {
shopt -s nocasematch
if [[ $(lsb_release -si) == "Debian" ||
$(lsb_release -si) == "Ubuntu" ||
$(lsb_release -si) == "LinuxMint" ||
$(lsb_release -si) == "PureOS"
]]; then
if [[ ! -e /etc/apt/sources.list.d/crystal.list ]]; then
#apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54
curl -sLk "https://keybase.io/crystal/pgp_keys.asc" | ${SUDO} apt-key add -
echo "deb https://dist.crystal-lang.org/apt crystal main" | ${SUDO} tee /etc/apt/sources.list.d/crystal.list
fi
elif [[ $(lsb_release -si) == "CentOS" ||
$(lsb_release -si) == "Fedora"
]]; then
if [[ ! -e /etc/yum.repos.d/crystal.repo ]]; then
curl -k https://dist.crystal-lang.org/rpm/setup.sh | ${SUDO} bash
fi
elif [[ $(lsb_release -si) == "Darwin" ]]; then
exit 1;
elif [[ $(lsb_release -si) == "Arch" ||
$(lsb_release -si) == "ManjaroLinux"
]]; then
echo "Arch/Manjaro Linux... Skipping manual crystal install"
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
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}
fi
}
# Rebuild Invidious
rebuild() {
printf "\n-- Rebuilding ${REPO_DIR}\n"
cd ${REPO_DIR} || exit 1
shards update && shards install
crystal build src/invidious.cr --release
#sudo chown -R 1000:$USER_NAME $USER_DIR
cd -
printf "\n"
echo -e "${GREEN}${DONE} Done Rebuilding ${REPO_DIR} ${NC}"
sleep 3
}
# Restart Invidious
restart() {
printf "\n-- restarting Invidious\n"
${SUDO} systemctl restart $SERVICE_NAME
sleep 2
${SUDO} systemctl status $SERVICE_NAME --no-pager
printf "\n"
echo -e "${GREEN}${DONE} Invidious has been restarted ${NC}"
sleep 3
}
# 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
}