-
Notifications
You must be signed in to change notification settings - Fork 0
/
newdomain.sh
56 lines (54 loc) · 1.98 KB
/
newdomain.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
#!/bin/bash
# settings
PORT=80
echo What is the website domain\? \(e.g\: example.com\)
read v_website
echo -e "Website name will be: $v_website \nWebsite will use port $PORT\nIs this correct? [y/n]"
read -n 1 -r -s
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "\nCreating new directory in /var/www ...\n"
mkdir /var/www/$v_website
echo -e "Changing ownership in new directory to ${SUDO_USER:-${USER}} ...\n"
chown -R ${SUDO_USER:-${USER}}:${SUDO_USER:-${USER}} /var/www/$v_website
set -o noclobber
echo -e "Writing config file to /etc/apache2/sites-available/$v_website.conf ...\n"
printf "<VirtualHost *:$PORT>
ServerName $v_website
ServerAlias www.$v_website
ServerAdmin webmaster@localhost
DocumentRoot /var/www/$v_website
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" $USER > /etc/apache2/sites-available/$v_website.conf
echo -e "Changing ownership of config file to ${SUDO_USER:-${USER}} ...\n"
chown -R ${SUDO_USER:-${USER}}:${SUDO_USER:-${USER}} /etc/apache2/sites-available/$v_website.conf
echo -e "Adding website to a2ensite ...\n"
a2ensite $v_website
echo -e "Reloading apache2 ... \n"
systemctl reload apache2
echo -e "Finished registering website!\n"
echo -e "\nDo you want to initiate a blank index.html file in the website directory? [y/n]"
read -n 1 -r -s
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "Creating new index.html file in /var/www/$v_website ...\n"
printf "<!DOCTYPE html>
<html>
<head>
<title>$v_website | Under construction...</title>
</head>
<body>
<h1>Welcome to $v_website</h1>
<p>This website is currently under construction...</p>
</body>
</html>" $USER > /var/www/$v_website/index.html
echo -e "Changing ownership of index.html to ${SUDO_USER:-${USER}} ..."
chown -R ${SUDO_USER:-${USER}}:${SUDO_USER:-${USER}} /var/www/$v_website/index.html
echo -e "All processes complete!\nExiting...\n"
else
echo -e "\nExiting...\n"
fi
else
echo -e "\nExiting...\n"
fi