-
Notifications
You must be signed in to change notification settings - Fork 1
/
INSTALL.bash
executable file
·116 lines (100 loc) · 2.8 KB
/
INSTALL.bash
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
#!/bin/bash
#
# Variables
#
BASEDOMAIN=$BASEDOMAIN
BASEIP=$BASEIP
PASSWORD=$PASSWORD
SCRIPTPATH=$(dirname "$(realpath $0)")
# Colors
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
#
# Functions (tasks)
#
function install_dependencies() {
echo -e "${GREEN}Install dependencies${NOCOLOR}"
apt -y update
apt -y upgrade
apt install -y coreutils nginx dnsmasq php7.4-fpm
}
function disable_systemd_resolved() {
echo -e "${GREEN}Disable systemd resolved${NOCOLOR}"
systemctl disable systemd-resolved
systemctl stop systemd-resolved
unlink /etc/resolv.conf
echo "nameserver 208.67.222.222" > /etc/resolv.conf
}
function configure_nginx() {
echo -e "${GREEN}Configure Nginx${NOCOLOR}"
if [ -d /etc/nginx/sites-available ]
then
cp "$SCRIPTPATH/config/myddns.nginx" /etc/nginx/sites-available/myddns
sed -i "s/server_name _;/server_name $BASEDOMAIN;/g" /etc/nginx/sites-available/myddns
cd /etc/nginx/sites-enabled
[[ -f myddns ]] && unlink myddns
ln -s ../sites-available/myddns
else
cp "$SCRIPTPATH/config/myddns.nginx" /etc/nginx/conf.d/myddns.conf
sed -i "s/server_name _;/server_name $BASEDOMAIN;/g" /etc/nginx/conf.d/myddns.conf
fi
nginx -t && service nginx restart
}
function configure_dnsmasq() {
echo -e "${GREEN}Configure dnsmasq${NOCOLOR}"
cp "$SCRIPTPATH/config/dnsmasq.conf" /etc/dnsmasq.d/myddns
echo "address=/$BASEDOMAIN/$BASEIP" >> /etc/dnsmasq.d/myddns
sed -i '/local-service/d' /etc/init.d/dnsmasq
service dnsmasq restart
}
function copy_www() {
echo -e "${GREEN}Copy www${NOCOLOR}"
mkdir -p /var/www/myddns/data
touch /var/www/myddns/data/hosts
cp -R "$SCRIPTPATH/public_html" /var/www/myddns/
chown -R www-data:www-data /var/www/myddns
}
function configure_app() {
echo -e "${GREEN}Configure application${NOCOLOR}"
mkdir -p /var/www/myddns/config
CONFIG=$(cat <<EOF
<?php
\$basedomain="$BASEDOMAIN";
\$password="$PASSWORD";
EOF
)
echo -e "$CONFIG" > /var/www/myddns/config/config.php
}
function install_cron() {
echo -e "${GREEN}Install cron${NOCOLOR}"
cp "$SCRIPTPATH/config/myddns-reload" /usr/local/sbin/myddns-reload
chmod u+x /usr/local/sbin/myddns-reload
cp "$SCRIPTPATH/config/myddns.cron" /etc/cron.d/myddns
}
function read_args() {
while [ -z "$BASEDOMAIN" ]
do
read -p "(required) BASEDOMAIN = " BASEDOMAIN
done
while [ -z "$BASEIP" ]
do
read -p "(required) BASEIP = " BASEIP
done
[ -z "$PASSWORD" ] && read -p "(optional) PASSWORD = " PASSWORD
}
#
# MAIN
#
[ "$(id -u)" != "0" ] && echo -e "${RED}This script must be run as root${NOCOLOR}" && exit 1
cd "$SCRIPTPATH"
read_args
[ ! -z "$(echo $(service systemd-resolved status) | grep loaded)" ] && \
disable_systemd_resolved
install_dependencies
copy_www
configure_app
configure_nginx
configure_dnsmasq
install_cron
echo -e "${GREEN}Success${NOCOLOR}"