]>
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 | ||
7f6ce6e7 ER |
36 | # return application list for webserver |
37 | # useful for bash_completion parsing | |
38 | webapp_applist() { | |
39 | local action="$1" | |
40 | local server=$2 | |
41 | ||
42 | for app in /etc/webapps/*; do | |
43 | [ -d $app ] || continue | |
44 | [ -f $app/$server.conf ] || continue | |
b40433db | 45 | local appname=${app##*/} |
7f6ce6e7 ER |
46 | local link=$(webapp_link $appname) |
47 | ||
48 | case "$action" in | |
49 | *-registered) | |
50 | [ -f /etc/$server/webapps.d/$link.conf ] && echo $appname | |
51 | ;; | |
52 | *-unregistered) | |
53 | [ -f /etc/$server/webapps.d/$link.conf ] || echo $appname | |
54 | ;; | |
55 | *) | |
56 | echo $appname | |
57 | ;; | |
58 | esac | |
59 | done | |
60 | } | |
61 | ||
7b49779e | 62 | webapp_list_apps() { |
7f6ce6e7 | 63 | echo "available webapps" |
c907433c ER |
64 | for app in /etc/webapps/*; do |
65 | [ -d $app ] || continue | |
66 | ||
67 | servers="" | |
7f6ce6e7 | 68 | for server in $webservers; do |
c907433c ER |
69 | [ -f $app/$server.conf ] || continue |
70 | servers="$servers${servers:+ }$server" | |
71 | done | |
72 | ||
73 | [ "$servers" ] || continue | |
b40433db | 74 | echo "- ${app##*/} ($servers)" |
7b49779e TP |
75 | done |
76 | } | |
77 | ||
e9689537 ER |
78 | usage() { |
79 | cat >&2 <<EOF | |
f21ce9bd | 80 | Usage: $0 register httpd webapp |
64efe5c9 | 81 | Usage: $0 register httpd webapp/module |
f21ce9bd | 82 | Usage: $0 unregister httpd webapp |
64efe5c9 | 83 | Usage: $0 unregister httpd webapp/module |
7b49779e TP |
84 | Usage: $0 list [$webservers] |
85 | Usage: $0 list-apps [$webservers] | |
f21ce9bd | 86 | |
a715016d | 87 | Where httpd is one of the webservers |
f21ce9bd ER |
88 | apache 1.x: apache |
89 | apache 2.x: httpd | |
90 | lighttpd: lighttpd | |
64efe5c9 ER |
91 | |
92 | webapp modules are supported, | |
c907433c | 93 | "drupal tinymce" module webapp name would be "drupal/tinymce". |
e9689537 ER |
94 | EOF |
95 | } | |
96 | ||
a715016d ER |
97 | die() { |
98 | echo >&2 "$0: $*" | |
99 | exit 1 | |
100 | } | |
101 | ||
102 | checkconfig() { | |
cd3edc5c | 103 | if [ -z "$httpd" ] || [ -z "$app" ]; then |
7b49779e | 104 | usage |
5ea8d8d5 | 105 | return 1 |
cd3edc5c ER |
106 | fi |
107 | ||
a715016d ER |
108 | # sanity check |
109 | if [ ! -d "$webapps/$app" ]; then | |
cd3edc5c | 110 | die "'$app' is not webapp? (Missing directory: $webapps/$app)" |
a715016d | 111 | fi |
5ec58d25 | 112 | if [ ! -d "/etc/$httpd/webapps.d" ]; then |
cd3edc5c | 113 | die "'$httpd' is not a webserver? (Missing directory: /etc/$httpd/webapps.d)" |
a715016d ER |
114 | fi |
115 | } | |
116 | ||
e9689537 ER |
117 | case "$action" in |
118 | register) | |
5ea8d8d5 | 119 | checkconfig && webapp_register |
e9689537 ER |
120 | ;; |
121 | unregister) | |
5ea8d8d5 | 122 | checkconfig && webapp_unregister |
e9689537 | 123 | ;; |
2ec41251 ER |
124 | list) |
125 | webapp_list $2 | |
126 | ;; | |
7f6ce6e7 ER |
127 | list-apps|list-apps-registered|list-apps-unregistered) |
128 | if [ "$2" ]; then | |
129 | webapp_applist $action $2 | |
130 | else | |
131 | webapp_list_apps | |
132 | fi | |
7b49779e | 133 | ;; |
e9689537 ER |
134 | *) |
135 | usage | |
136 | exit 1 | |
137 | esac |