]>
Commit | Line | Data |
---|---|---|
e9689537 | 1 | #!/bin/sh |
7b49779e | 2 | |
e9689537 | 3 | webapps=/etc/webapps |
2ec41251 | 4 | webservers='apache httpd lighttpd' |
e9689537 | 5 | action="$1" |
f21ce9bd | 6 | httpd="$2" |
e9689537 ER |
7 | app="$3" |
8 | ||
64efe5c9 ER |
9 | webapp_link() { |
10 | echo "$1" | tr '/' '-' | |
11 | } | |
12 | ||
e9689537 | 13 | webapp_register() { |
64efe5c9 | 14 | local link=$(webapp_link $app) |
4f184781 | 15 | ln -sf ../../..$webapps/$app/$httpd.conf /etc/$httpd/webapps.d/$link.conf |
e9689537 ER |
16 | } |
17 | ||
18 | webapp_unregister() { | |
64efe5c9 ER |
19 | local link=$(webapp_link $app) |
20 | rm -f /etc/$httpd/webapps.d/$link.conf | |
e9689537 ER |
21 | } |
22 | ||
2ec41251 ER |
23 | webapp_list() { |
24 | echo "registered webapps${1:+ for $1}": | |
25 | for server in ${1:-$webservers}; do | |
26 | [ -d /etc/$server/webapps.d ] || continue | |
27 | echo "$server:" | |
28 | for conf in /etc/$server/webapps.d/*; do | |
29 | [ -L $conf ] || continue | |
e00050c4 | 30 | app=$(readlink $conf | sed -e "s,.*$webapps/,,;s,/$server.conf$,,") |
2ec41251 ER |
31 | echo "- $app" |
32 | done | |
33 | done | |
34 | } | |
35 | ||
aa165ce2 | 36 | # return registered application list for webserver |
7f6ce6e7 | 37 | # useful for bash_completion parsing |
aa165ce2 | 38 | webapp_apps_registered() { |
7f6ce6e7 ER |
39 | local action="$1" |
40 | local server=$2 | |
41 | ||
aa165ce2 ER |
42 | for conf in /etc/$server/webapps.d/*.conf; do |
43 | [ -L $conf ] || continue | |
44 | appname=$(readlink $conf) | |
45 | appname=${appname#*$webapps/} | |
46 | appname=${appname%/$server.conf} | |
47 | [ -f /etc/webapps/$appname/$server.conf ] || continue | |
48 | echo $appname | |
7f6ce6e7 ER |
49 | done |
50 | } | |
51 | ||
996e9544 ER |
52 | # return application list for webserver |
53 | # useful for bash_completion parsing | |
54 | webapp_applist() { | |
55 | local action="$1" | |
56 | local server=$2 | |
57 | ||
58 | for app in /etc/webapps/*; do | |
59 | [ -d $app ] || continue | |
60 | [ -f $app/$server.conf ] || continue | |
61 | local appname=${app##*/} | |
62 | local link=$(webapp_link $appname) | |
63 | ||
64 | case "$action" in | |
65 | *-registered) | |
66 | [ -f /etc/$server/webapps.d/$link.conf ] && echo $appname | |
67 | ;; | |
68 | *-unregistered) | |
69 | [ -f /etc/$server/webapps.d/$link.conf ] || echo $appname | |
70 | ;; | |
71 | *) | |
72 | echo $appname | |
73 | ;; | |
74 | esac | |
75 | done | |
76 | } | |
77 | ||
7b49779e | 78 | webapp_list_apps() { |
7f6ce6e7 | 79 | echo "available webapps" |
c907433c ER |
80 | for app in /etc/webapps/*; do |
81 | [ -d $app ] || continue | |
82 | ||
83 | servers="" | |
7f6ce6e7 | 84 | for server in $webservers; do |
c907433c ER |
85 | [ -f $app/$server.conf ] || continue |
86 | servers="$servers${servers:+ }$server" | |
87 | done | |
88 | ||
89 | [ "$servers" ] || continue | |
b40433db | 90 | echo "- ${app##*/} ($servers)" |
7b49779e TP |
91 | done |
92 | } | |
93 | ||
e9689537 ER |
94 | usage() { |
95 | cat >&2 <<EOF | |
f21ce9bd | 96 | Usage: $0 register httpd webapp |
64efe5c9 | 97 | Usage: $0 register httpd webapp/module |
f21ce9bd | 98 | Usage: $0 unregister httpd webapp |
64efe5c9 | 99 | Usage: $0 unregister httpd webapp/module |
7b49779e TP |
100 | Usage: $0 list [$webservers] |
101 | Usage: $0 list-apps [$webservers] | |
f21ce9bd | 102 | |
a715016d | 103 | Where httpd is one of the webservers |
f21ce9bd ER |
104 | apache 1.x: apache |
105 | apache 2.x: httpd | |
106 | lighttpd: lighttpd | |
64efe5c9 ER |
107 | |
108 | webapp modules are supported, | |
c907433c | 109 | "drupal tinymce" module webapp name would be "drupal/tinymce". |
e9689537 ER |
110 | EOF |
111 | } | |
112 | ||
a715016d ER |
113 | die() { |
114 | echo >&2 "$0: $*" | |
115 | exit 1 | |
116 | } | |
117 | ||
118 | checkconfig() { | |
cd3edc5c | 119 | if [ -z "$httpd" ] || [ -z "$app" ]; then |
7b49779e | 120 | usage |
5ea8d8d5 | 121 | return 1 |
cd3edc5c ER |
122 | fi |
123 | ||
a715016d ER |
124 | # sanity check |
125 | if [ ! -d "$webapps/$app" ]; then | |
cd3edc5c | 126 | die "'$app' is not webapp? (Missing directory: $webapps/$app)" |
a715016d | 127 | fi |
5ec58d25 | 128 | if [ ! -d "/etc/$httpd/webapps.d" ]; then |
cd3edc5c | 129 | die "'$httpd' is not a webserver? (Missing directory: /etc/$httpd/webapps.d)" |
a715016d ER |
130 | fi |
131 | } | |
132 | ||
e9689537 ER |
133 | case "$action" in |
134 | register) | |
5ea8d8d5 | 135 | checkconfig && webapp_register |
e9689537 ER |
136 | ;; |
137 | unregister) | |
5ea8d8d5 | 138 | checkconfig && webapp_unregister |
e9689537 | 139 | ;; |
2ec41251 ER |
140 | list) |
141 | webapp_list $2 | |
142 | ;; | |
aa165ce2 ER |
143 | list-apps) |
144 | webapp_list_apps | |
145 | ;; | |
146 | list-apps-registered) | |
147 | if [ "$2" ]; then | |
148 | webapp_apps_registered $action $2 | |
149 | else | |
150 | webapp_list_apps | |
151 | fi | |
152 | ;; | |
153 | list-apps-unregistered) | |
7f6ce6e7 ER |
154 | if [ "$2" ]; then |
155 | webapp_applist $action $2 | |
156 | else | |
157 | webapp_list_apps | |
158 | fi | |
7b49779e | 159 | ;; |
e9689537 ER |
160 | *) |
161 | usage | |
162 | exit 1 | |
163 | esac |