|
@@ -1,13 +1,44 @@
|
1
|
1
|
#! /usr/bin/env sh
|
2
|
2
|
|
3
|
|
-dir="/etc/apache2/sites-available/"
|
|
3
|
+apache_dir=/etc/apache2/sites-available/
|
|
4
|
+conf_dir=/etc/sitegen/
|
|
5
|
+site_dir=/var/
|
4
|
6
|
|
5
|
|
-if [ $# -eq 0 ] || [ $# -gt 2 ]
|
|
7
|
+conf_file=/etc/sitegen/sitegen.conf
|
|
8
|
+conf_file_local=~/.sitegen.conf
|
|
9
|
+
|
|
10
|
+loadConf()
|
|
11
|
+{
|
|
12
|
+ if [ -e "$1" ]
|
|
13
|
+ then
|
|
14
|
+ echo "Found a config file: $1"
|
|
15
|
+ . "$1"
|
|
16
|
+ fi
|
|
17
|
+}
|
|
18
|
+
|
|
19
|
+makeDir()
|
|
20
|
+{
|
|
21
|
+ mkdir -p "$1"
|
|
22
|
+ if [ $? -ne 0 ]
|
|
23
|
+ then
|
|
24
|
+ exit 4
|
|
25
|
+ fi
|
|
26
|
+}
|
|
27
|
+
|
|
28
|
+getPath()
|
|
29
|
+{
|
|
30
|
+ readlink -m "$1"
|
|
31
|
+}
|
|
32
|
+
|
|
33
|
+if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ]
|
6
|
34
|
then
|
7
|
35
|
echo "Usage:" $(basename $0) "hostname [config=default]" >&2
|
8
|
36
|
exit 1
|
9
|
37
|
fi
|
10
|
38
|
|
|
39
|
+loadConf "${conf_file}"
|
|
40
|
+loadConf "${conf_file_local}"
|
|
41
|
+
|
11
|
42
|
host="$1"
|
12
|
43
|
if [ $# -eq 2 ]
|
13
|
44
|
then
|
|
@@ -16,25 +47,31 @@ else
|
16
|
47
|
conf="default"
|
17
|
48
|
fi
|
18
|
49
|
|
19
|
|
-def="/etc/sitegen/${conf}"
|
20
|
|
-def_conf="/etc/sitegen/${conf}.conf"
|
|
50
|
+conf_conf=$(getPath "${conf_dir}/${conf}.conf")
|
|
51
|
+conf_include=$(getPath "${conf_dir}/${conf}.include")
|
|
52
|
+
|
|
53
|
+site_conf=$(getPath "${apache_dir}/${host}.conf")
|
|
54
|
+site_include=$(getPath "${apache_dir}/${host}.include")
|
21
|
55
|
|
22
|
|
-adef="${dir}/${host}"
|
23
|
|
-adef_conf="${dir}/${host}.conf"
|
|
56
|
+root_dir=$(getPath "${site_dir}/${host}")
|
24
|
57
|
|
25
|
|
-if [ ! -f "${def}" ] || [ ! -f "${def_conf}" ]
|
|
58
|
+sed_host="s:%%HOST%%:${host}:g"
|
|
59
|
+sed_root="s:%%ROOT%%:${root_dir}:g"
|
|
60
|
+
|
|
61
|
+if [ ! -f "${conf_conf}" ] || [ ! -f "${conf_include}" ]
|
26
|
62
|
then
|
27
|
|
- echo "Configuration file ${def} and/or ${def_conf} error: No such file" >&2
|
|
63
|
+ echo "Configuration file ${conf_conf} and/or ${conf_include} error: No such file" >&2
|
28
|
64
|
exit 2
|
29
|
65
|
fi
|
30
|
66
|
|
31
|
|
-if [ -f "${adef}" ] || [ -f "${adef_conf}" ]
|
|
67
|
+if [ -f "${site_conf}" ] || [ -f "${site_include}" ]
|
32
|
68
|
then
|
33
|
|
- echo "Host already exists: ${adef} and/or ${adef_conf}" >&2
|
|
69
|
+ echo "Host already exists: ${site_conf} and/or ${site_include}" >&2
|
34
|
70
|
exit 3
|
35
|
71
|
fi
|
36
|
72
|
|
37
|
|
-sed="s/%%HOST%%/${host}/g"
|
38
|
|
-sed "${sed}" "${def}" > "${adef}"
|
39
|
|
-sed "${sed}" "${def_conf}" > "${adef_conf}"
|
40
|
|
-mkdir -p "/var/${host}"
|
|
73
|
+makeDir "${root_dir}"
|
|
74
|
+makeDir "${apache_dir}"
|
|
75
|
+
|
|
76
|
+sed -e "${sed_host}" -e "${sed_root}" "${conf_conf}" > "${site_conf}"
|
|
77
|
+sed -e "${sed_host}" -e "${sed_root}" "${conf_include}" > "${site_include}"
|