-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_site2.sh
105 lines (103 loc) · 2.57 KB
/
add_site2.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
#!/bin/bash
#!/bin/sh
# shev92k70 (Jeronimo)
if [ "$(id -u)" != "0" ]; then
echo "This script need to be running from superuser rights"
exit 0
fi
echo "Please enter project root directory:"
read site_dir
if [ ! -z $site_dir ];
then
echo "Please enter domain name:"
read domain
if [ ! -z $domain ];
then
echo "Please enter administrator email or press enter to move next"
read email
if [ -z $email ];
then
email="[email protected]"
fi
while true; do
echo "Create log-directory in project directory? (y/n)"
read yn
case $yn in
[Yy]* )
yn="Yes"
log=$site_dir
break;;
[Nn]* )
yn="No"
break;;
* ) echo "Please answer Yes or No.";;
esac
done
echo "Settings VirtualHost:\n==============================="
echo "Project directory: $site_dir"
echo "Domain name: $domain"
echo "Administrator email: $email"
echo "Create log directory: $yn"
echo "==============================="
while true; do
echo "Create VirtualHost with this settings? (Y/N)"
read tyn
case $tyn in
[Yy]* )
touch /etc/apache2/sites-available/$domain.conf
if [ ! -z $log ]
then
log="ErrorLog $site_dir/logs/error.log"
mkdir $site_dir/logs
touch $site_dir/logs/error.log
fi
echo "
<VirtualHost *:80>
ServerName $domain
ServerAlias $domain
ServerAdmin $email
$log
DocumentRoot $site_dir
<Directory "$site_dir">
Order allow,deny
Allow from all
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
" >> /etc/apache2/sites-available/$domain.conf
a2ensite $domain
#a2enconf /etc/apache2/sites-available/$domain
echo "127.0.0.1 $domain" >> /etc/hosts
find $site_dir -type f -exec chmod 644 {} \;
find $site_dir d -exec chmod 755 {} \;
chown -R www-data:www-data $site_dir
while true; do
echo "Reload apche2? (y/n)"
read yn
case $yn in
[Yy]* )
service apache2 reload
echo "VirtualHost successfully created!"
exit 3
break;;
[Nn]* )
echo "VirtualHost successfully created, settings will take effect after restarting the Apache server"
exit 4
break;;
* ) echo "Please answer Yes or No.";;
esac
done
break;;
[Nn]* ) echo "Abort operation ..."; exit;;
* ) echo "Please answer Yes or No";;
esac
done
else
echo "Domain name is not entered. Operation aborted."
exit 2
fi
else
echo "Project directory is not entered. Operation aborted."
exit 1
fi