-
Notifications
You must be signed in to change notification settings - Fork 0
/
apache_project
executable file
·76 lines (69 loc) · 1.54 KB
/
apache_project
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
#! /bin/bash
options="p:a:"
usage="
\n
generates a virtualhost configuration and an entry on host file\n
---------------------------------------------------------------\n
-p(required) project name\n
-a(required) admin email address\n
"
exceptionVHalreadyExits="\nthe virtualhost already exists"
while getopts $options opt; do
case $opt in
p)
projectName=$OPTARG
;;
a)
adminAddress=$OPTARG
;;
\?)
echo -e $usage
exit 1;;
esac
done
if [ -z $projectName ]; then
echo -e $usage;
exit 1;
fi
if [ -z $adminAddress ]; then
echo -e $usage
exit 1;
fi
configurationFile="/etc/apache2/sites-available/$projectName"
hostFile="/etc/hosts"
projectDir=$( readlink -f "$projectName" )
publicDir="$projectDir/public"
if [ -f $configurationFile ]; then
echo -e $exceptionVHalreadyExists
exit 1;
fi
if [ ! -d $projectDir ]; then
echo -e "$projectDir doesn't exist"
exit 1;
fi
if [ ! -d $publicDir ]; then
echo -e "$publicDir doesn't exist"
exit 1;
fi
#vhost template
vhostConfiguration="
<VirtualHost *:80>\n
ServerName $projectName\n
ServerAdmin $adminAddress\n
DocumentRoot $publicDir\n
<Directory $publicDir>\n
Options +Indexes Multiviews FollowSymLinks\n
AllowOverride All\n
Allow from All\n
</Directory>\n
</VirtualHost>\n"
#host entry
hostEntry="
\n
#$projectName
\n
127.0.0.1 $projectName
"
echo -e $vhostConfiguration > $configurationFile
echo -e $hostEntry >> $hostFile
a2ensite $projectName