]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | webapps=/etc/webapps | |
4 | webservers='apache httpd lighttpd' | |
5 | action="$1" | |
6 | httpd="$2" | |
7 | app="$3" | |
8 | ||
9 | webapp_link() { | |
10 | echo "$1" | tr '/' '-' | |
11 | } | |
12 | ||
13 | webapp_register() { | |
14 | local link=$(webapp_link $app) | |
15 | ln -sf $webapps/$app/$httpd.conf /etc/$httpd/webapps.d/$link.conf | |
16 | } | |
17 | ||
18 | webapp_unregister() { | |
19 | local link=$(webapp_link $app) | |
20 | rm -f /etc/$httpd/webapps.d/$link.conf | |
21 | } | |
22 | ||
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 | |
30 | app=$(readlink $conf | sed -e "s,$webapps/,,;s,/$server.conf$,,") | |
31 | echo "- $app" | |
32 | done | |
33 | done | |
34 | } | |
35 | ||
36 | webapp_list_apps() { | |
37 | echo "available webapps${1:+ for $1}": | |
38 | for server in ${1:-\\*}; do | |
39 | for app in `ls /etc/webapps`; do | |
40 | eval find /etc/webapps/$app -name $server.conf -printf '"- $app\n"' | |
41 | done | uniq | |
42 | done | |
43 | } | |
44 | ||
45 | usage() { | |
46 | cat >&2 <<EOF | |
47 | Usage: $0 register httpd webapp | |
48 | Usage: $0 register httpd webapp/module | |
49 | Usage: $0 unregister httpd webapp | |
50 | Usage: $0 unregister httpd webapp/module | |
51 | Usage: $0 list [$webservers] | |
52 | Usage: $0 list-apps [$webservers] | |
53 | ||
54 | Where httpd is one of the webservers | |
55 | apache 1.x: apache | |
56 | apache 2.x: httpd | |
57 | lighttpd: lighttpd | |
58 | ||
59 | webapp modules are supported, | |
60 | drupal tinymce module webapp name would be drupal/tinymce. | |
61 | EOF | |
62 | } | |
63 | ||
64 | die() { | |
65 | echo >&2 "$0: $*" | |
66 | exit 1 | |
67 | } | |
68 | ||
69 | checkconfig() { | |
70 | if [ -z "$httpd" ] || [ -z "$app" ]; then | |
71 | usage | |
72 | return | |
73 | fi | |
74 | ||
75 | # sanity check | |
76 | if [ ! -d "$webapps/$app" ]; then | |
77 | die "'$app' is not webapp? (Missing directory: $webapps/$app)" | |
78 | fi | |
79 | if [ ! -d "/etc/$httpd/webapps.d" ]; then | |
80 | die "'$httpd' is not a webserver? (Missing directory: /etc/$httpd/webapps.d)" | |
81 | fi | |
82 | } | |
83 | ||
84 | case "$action" in | |
85 | register) | |
86 | checkconfig | |
87 | webapp_register | |
88 | ;; | |
89 | unregister) | |
90 | checkconfig | |
91 | webapp_unregister | |
92 | ;; | |
93 | list) | |
94 | webapp_list $2 | |
95 | ;; | |
96 | list-apps) | |
97 | webapp_list_apps $2 | |
98 | ;; | |
99 | *) | |
100 | usage | |
101 | exit 1 | |
102 | esac |