-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathahost.sh
More file actions
executable file
·68 lines (62 loc) · 1.62 KB
/
ahost.sh
File metadata and controls
executable file
·68 lines (62 loc) · 1.62 KB
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
#!/bin/bash
#######################################################################
# ahost.sh B(ack)U(p)
# arielvb - http://www.arielvb.com
# Creates a new Apache virtualhost and a host entry
# version: 0.1
# Changelog:
# 0.1 first version
# 0.2 Clean virtualhost declaration and add allow override
#######################################################################
###########################
# CONFIG
###########################
# String messages
USAGE="Usage: ahost subdomain path"
PERMISION="Root is needed"
# CONFIG VARS
VHOSTFILE="/etc/apache2/extra/httpd-vhosts.conf"
HOSTSFILE="/etc/hosts"
# PARAMETERS
SERVERNAME=$1
DOCUMENTROOT=$2
###########################
# CHECK CALL
###########################
if [[ $BASH_ARGC < 2 ]]; then
echo $USAGE
exit;
fi
if [[ $UID != 0 ]]; then
echo $PERMISION
exit;
fi
#TODO will be better do something like realpath(3)
if [[ $DOCUMENTROOT == './' || $DOCUMENTROOT == '.' ]]; then
DOCUMENTROOT=`pwd`
DOCUMENTROOT=$DOCUMENTROOT"/"
fi
# Modifying hosts file
echo "Adding server $SERVERNAME to hosts"
echo "127.0.0.1 $SERVERNAME" >> $HOSTSFILE
# Modifying virtualhost file
echo "Generating virtualhost config: $SERVERNAME"
echo "###################################
# virtualhost generated with avhost
###################################
<VirtualHost *:80>
ServerName $SERVERNAME
DocumentRoot \"$DOCUMENTROOT\"
<Directory \"$DOCUMENTROOT\">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
###################################
# end virtualhost
###################################
" >> $VHOSTFILE
# Restarting apache
echo -n "Restarting apache..."
apachectl graceful
echo "done"