/
phd
executable file
·49 lines (41 loc) · 1.27 KB
/
phd
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
#! /bin/bash
# Usage: phd [dir] [host name]
#
# eventually, it might be `phd run [app]` if phd gets more sophisticated
# default apache virtualhosts path
PHD_APACHE_VIRTUALHOSTS='/etc/apache2/phd-sites'
PHD_APACHE_CONFIG='/etc/apache2/apache2.conf'
PHD_APACHE_INCLUDE="Include $PHD_APACHE_VIRTUALHOSTS"
PHD_APACHE_VIRTUALHOST_TEXT='<VirtualHost *:80>
ServerName $host
DocumentRoot $dir/public
PassengerAppRoot $dir
</VirtualHost>'
# read .phdrc (for overrides)
if [[ -f ~/.phdrc ]]; then
source ~/.phdrc
fi
if [[ ! -f "$PHD_APACHE_VIRTUALHOSTS" ]]; then
echo "$PHD_APACHE_VIRTUALHOSTS hasn't been configured"
echo "It needs to be editable by the git user"
fi
dir=$(dirname $1)
host=$2
echo "Application directory: $dir"
echo "Hostname: $host"
if [[ -z "$dir" || -z "$host" ]]; then
echo "Usage: phd [application's .git directory] [hostname]"
exit
fi
if [[ -f "$dir/config.ru" ]]; then
echo "rack app!"
if [[ -f "PHD_APACHE_VIRTUALHOSTS/$host" ]]; then
echo 'Already configured'
else
echo 'Not yet configured'
PHD_APACHE_VIRTUALHOST_TEXT="echo \"$PHD_APACHE_VIRTUALHOST_TEXT\""
eval "$PHD_APACHE_VIRTUALHOST_TEXT" > $PHD_APACHE_VIRTUALHOSTS/$host
echo 'Application should now be configured'
echo 'You will need to reload apache for the application to work'
fi
fi