-
Notifications
You must be signed in to change notification settings - Fork 39
/
redi.sh
73 lines (61 loc) · 2.13 KB
/
redi.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
#!/bin/bash
now=$(date +"%s")
echo [+] updating
apt-get update
if [ "$2" = "dns" ]
then
echo [+] installing dnsmasq
apt-get --assume-yes install dnsmasq
echo [+] starting configuration
service dnsmasq stop
mv /etc/default/dnsmasq /etc/default/dnsmasq_bak_${now}
mv /etc/dnsmasq.conf /etc/dnsmasq.conf_bak_${now}
echo [+] generating config file for teamserver $1
CONFIGFILE="redirector-dns.conf"
sed 's/www.your_team_server_domain_here.com/'$1'/g' $CONFIGFILE > /etc/dnsmasq.conf
cp redirector-dns-defaults.conf /etc/default/dnsmasq
echo [+] starting dnsmasq
service dnsmasq start
else
#for http/https redirectors
if [ "$3" = "https" ] || [ "$3" = "http" ]
then
echo [+] installing nginx
apt-get --assume-yes install nginx
echo [+] starting configuration
service nginx stop
mv /etc/nginx/sites-enabled/ /etc/nginx/sites-enabled_bak_${now}/
mkdir /etc/nginx/sites-enabled
CONFIGFILE="redirector.conf"
DOMAINS=( $(echo $1 | tr ',' ' ') )
#for https redirectors
if [ "$3" = "https" ]
then
echo [+] https is selected
CONFIGFILE="redirector-ssl.conf"
echo [+] downloading certbot to generate certificates
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
echo [+] generating certifcates
mv /etc/letsencrypt/ /etc/letsencrypt_bak_${now}/
DOMAINS=( $(echo $1 | tr ',' ' ') )
for DOMAIN in "${DOMAINS[@]}"
do
./certbot-auto certonly --standalone -d $DOMAIN --agree-tos --register-unsafely-without-email --non-interactive --expand
done
fi
for DOMAIN in "${DOMAINS[@]}"
do
if [ "$3" = "https" ] && [ ! -f /etc/letsencrypt/live/$DOMAIN/cert.pem ]; then
echo -e "\e[91m[-] Certificate generation failed for domain $DOMAIN \033[0m"
echo -e "\e[91m[-] Will not generate nginx config for this domain \033[0m"
else
echo [+] generating config file for $DOMAIN
sed 's/www.you_redirector_domain_here.com/'$DOMAIN'/g; s/www.your_team_server_domain_here.com/'$2'/g' $CONFIGFILE > /etc/nginx/sites-enabled/redirector-${DOMAIN}.conf
fi
done
echo [+] starting nginx
service nginx start
service nginx reload
fi
fi