-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvroxy_install_deb.sh
129 lines (114 loc) · 4.05 KB
/
vroxy_install_deb.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
#!/bin/bash
echo This script will automatically setup all dependencies and an NGINX server with a LetsEncrypt SSL cert.
if [[ `whoami` != root ]]; then
echo Permission escalation required. Please run this script as root or using sudo.
exit
fi
echo '
>>> Some information is needed from you <<<
'
read -p "Please select the folder for Vroxy to install into or update in (leave empty for /var/vroxy): " dir
if [ ! $dir ]; then dir='/var/vroxy'; fi
if [[ -f "$dir/settings.ini" ]]; then
defaultdomain=$(grep -E "domain=" $dir/settings.ini | cut -d'=' -f2)
defaultport=$(grep -E "port=" $dir/settings.ini | cut -d'=' -f2)
fi
if [ ! $defaultport ]; then defaultport=8420; fi
domainmsg='required'
if [ $defaultdomain ]; then domainmsg="leave empty for $defaultdomain"; fi
read -p "Please enter the domain name you wish to setup with the NGINX configuration ($domainmsg): " domain
read -p "Please specify what port to run the Vroxy service on (leave empty for $defaultport): " port
if [ ! $port ]; then port=$defaultport; fi
if [ ! $domain ]; then
if [ ! $defaultdomain ]; then
echo "No domain name provided. This is required information for initial setup. Rerun script and specify the domain name."
exit 1
else
domain=$defaultdomain
fi
fi
echo "Domain: $domain | Reverse Proxy Port: $port | Vroxy Location: $dir"
cd ~
echo ---
echo Installing common dependencies
echo ---
apt install -y git software-properties-common tmux gpg gpg-agent dirmngr nginx certbot
echo ---
echo Installing python dependencies
echo ---
add-apt-repository -y ppa:deadsnakes/ppa
apt install -y python3.9 python3-pip python3-certbot-nginx
echo ---
echo Configuring NGINX with LetsEncrypt SSL Certs
echo ---
cat << EOF > /etc/nginx/conf.d/$domain.conf
server {
server_name $domain;
location / {
proxy_pass http://0.0.0.0:$port;
}
error_log /var/log/nginx/$domain.error.log;
access_log /var/log/nginx/$domain.access.log;
}
EOF
echo NGINX Configuration stored in /etc/nginx/conf.d/$domain.conf
nginx -t && nginx -s reload
echo ---
echo Setting up LetsEncrypt
echo ---
certbot -n --nginx --redirect --no-eff-email --agree-tos --register-unsafely-without-email -d $domain
croninfo=$(crontab -l)
if echo $croninfo | grep -xq "vroxy_reload.sh"; then
# replace any old directory service cron with the new directory service cron
croninfo=$(echo $croninfo | sed -r "s|bash .+/vroxy_reload\.sh|bash $dir/vroxy_reload.sh|g")
echo $croninfo | crontab -
echo Vroxy service auto-reload cron updated.
else
echo "$croninfo
# Vroxy service auto-reload
0 3 * * * bash $dir/vroxy_reload.sh
" | crontab -
echo Vroxy service auto-reload cron added.
fi
echo ---
echo "Setting up Vroxy in $dir"
echo ---
mkdir $dir
if [ ! $(git config --global --get-all safe.directory | grep "$dir")]; then
# ensure that git knows that this new directory is safe
git config --global --add safe.directory $dir
fi
if [ $SUDO_USER ]; then
# enforce calling user has ownership of the directory and files
chown -R $SUDO_USER $dir
fi
cd $dir
if [[ ! -d "$dir/.git" ]]; then
git clone https://github.com/techanon/vroxy.git $dir
git config pull.ff only
else
# if it already exists, just grab the latest instead
git pull
fi
cat << EOF > settings.ini
[server]
domain=$domain
host=localhost
port=$port
EOF
python3 -m pip install -U yt-dlp aiohttp tldextract
if [ $SUDO_USER ]; then
# re-enforce calling user has ownership of the directory and files
chown -R $SUDO_USER $dir
su $SUDO_USER -c "bash $dir/vroxy_reload.sh"
else
# is actually just root user, no sudo being used, all good
bash $dir/vroxy_reload.sh
fi
echo ---
echo "Vroxy service is now running on https://$domain/ from $dir"
echo "Try it out with this sample URL: https://$domain/?url=https://www.youtube.com/watch?v=wpV-gGA4PSk"
echo "If you need to restart or update the service, run this command: bash $dir/vroxy_reload.sh"
echo "You can view the Vroxy logs via 'tmux a -t vroxy'."
echo "In the tmux session you can cleanly exit via CTRL+B and the clicking the D key."
echo ---