-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.sh
107 lines (79 loc) · 2.42 KB
/
script.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
#!/bin/bash
sudo apt update -y
sudo apt install nginx python3 pip -y
sudo pip install -r dependencies/requirements.txt
clear
# Check if the SSL certificate is in place
read -p "Have you placed your SSL certificate and private key at /root/cert.crt and /root/private.key? (y/n): " ssl_cert_ready
read -p "Enter the domain name: " domain_name
if [ "$ssl_cert_ready" != "y" ]; then
apt install curl socat -y
curl https://get.acme.sh/ | sh
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --register-account -m te324stus32er@gmail.com
~/.acme.sh/acme.sh --issue -d $domain_name --standalone
~/.acme.sh/acme.sh --installcert -d $domain_name --key-file /root/private.key --fullchain-file /root/cert.crt
clear
echo "Your ssl certificate is ready. the script will now continue"
sleep 2
fi
# Get the server's IP address
server_ip=$(curl -s ifconfig.me)
# Replace variables in /etc/nginx/sites-available/default
cat <<EOF > /etc/nginx/sites-available/default
server {
listen 443 ssl;
ssl_certificate /root/cert.crt;
ssl_certificate_key /root/private.key;
server_name $domain_name;
location / {
proxy_pass http://$server_ip:5000;
proxy_set_header X-Real-IP \$remote_addr;
}
}
server {
listen 80;
server_name $domain_name;
return 302 https://\$server_name\$request_uri;
}
EOF
# Start and enable nginx systemd service
systemctl start nginx
systemctl enable nginx
# Write the submixer service in /etc/systemd/system/submixer.service
cat <<EOF > /etc/systemd/system/submixer.service
[Unit]
Description= Submixer service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/python3 /root/submixer/dependencies/main.py
[Install]
WantedBy=multi-user.target
EOF
# Write the flask service in /etc/systemd/system/flask.service
cat <<EOF > /etc/systemd/system/flask.service
[Unit]
Description= Submixer Flask service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/python3 /root/submixer/Flask/app.py
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
# Start and enable submixer and flask systemd services
systemctl start submixer
systemctl enable submixer
systemctl start flask
systemctl enable flask
systemctl reload nginx
# Return the domain name in the https://domain.name format
echo "Your subscription is now accessible at https://$domain_name"