-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddsite.sh
executable file
·48 lines (39 loc) · 1.06 KB
/
addsite.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
#!/bin/bash
# functions
get_host() {
echo -e "\n\n"
read -e -p "Enter a host (e.g. web.host.com) " -r host
if [[ "${#host}" -lt 1 ]]; then
echo " >> Please enter a valid host!"
get_host
fi
echo -e "\n\n"
}
# get host name and init
get_host
wwwroot="/var/www/$host"
[[ -d "$wwwroot" ]] || sudo rm -rf $wwwroot
htmlDir="$wwwroot/html"
sudo mkdir -p $htmlDir
sudo cp $HOME/nginx-script/index.html $htmlDir
# update owner
sudo chown -R www-data:www-data $wwwroot
sudo chmod -R 755 $wwwroot
# setup server block
availableDIR="/etc/nginx/sites-available"
enabledDIR="/etc/nginx/sites-enabled"
availableBlock="$availableDIR/$host"
enabledBlock="$enabledDIR/$host"
[ -d "$availableDIR" ] || sudo mkdir -p "$availableDIR"
[ -d "$enabledDIR" ] || sudo mkdir -p "$enabledDIR"
[ -f "$availableBlock" ] || sudo touch $availableBlock
[ -L "$enabledBlock" ] || sudo ln -s $availableBlock $enabledBlock
cat <<EOT > $availableBlock
server {
listen 80;
listen [::]:80;
server_name $host;
root $wwwroot/html;
index index.html index.htm index.nginx-debian.html;
}
EOT