]>
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 | |
4f184781 | 30 | app=$(basename $conf .conf) |
2ec41251 ER |
31 | echo "- $app" |
32 | done | |
33 | done | |
34 | } | |
35 | ||
7b49779e TP |
36 | webapp_list_apps() { |
37 | echo "available webapps${1:+ for $1}": | |
c907433c ER |
38 | for app in /etc/webapps/*; do |
39 | [ -d $app ] || continue | |
40 | ||
41 | servers="" | |
42 | for server in ${1:-$webservers}; do | |
43 | [ -f $app/$server.conf ] || continue | |
44 | servers="$servers${servers:+ }$server" | |
45 | done | |
46 | ||
47 | [ "$servers" ] || continue | |
48 | echo "- $(basename $app) ($servers)" | |
7b49779e TP |
49 | done |
50 | } | |
51 | ||
e9689537 ER |
52 | usage() { |
53 | cat >&2 <<EOF | |
f21ce9bd | 54 | Usage: $0 register httpd webapp |
64efe5c9 | 55 | Usage: $0 register httpd webapp/module |
f21ce9bd | 56 | Usage: $0 unregister httpd webapp |
64efe5c9 | 57 | Usage: $0 unregister httpd webapp/module |
7b49779e TP |
58 | Usage: $0 list [$webservers] |
59 | Usage: $0 list-apps [$webservers] | |
f21ce9bd | 60 | |
a715016d | 61 | Where httpd is one of the webservers |
f21ce9bd ER |
62 | apache 1.x: apache |
63 | apache 2.x: httpd | |
64 | lighttpd: lighttpd | |
64efe5c9 ER |
65 | |
66 | webapp modules are supported, | |
c907433c | 67 | "drupal tinymce" module webapp name would be "drupal/tinymce". |
e9689537 ER |
68 | EOF |
69 | } | |
70 | ||
a715016d ER |
71 | die() { |
72 | echo >&2 "$0: $*" | |
73 | exit 1 | |
74 | } | |
75 | ||
76 | checkconfig() { | |
cd3edc5c | 77 | if [ -z "$httpd" ] || [ -z "$app" ]; then |
7b49779e | 78 | usage |
5ea8d8d5 | 79 | return 1 |
cd3edc5c ER |
80 | fi |
81 | ||
a715016d ER |
82 | # sanity check |
83 | if [ ! -d "$webapps/$app" ]; then | |
cd3edc5c | 84 | die "'$app' is not webapp? (Missing directory: $webapps/$app)" |
a715016d | 85 | fi |
5ec58d25 | 86 | if [ ! -d "/etc/$httpd/webapps.d" ]; then |
cd3edc5c | 87 | die "'$httpd' is not a webserver? (Missing directory: /etc/$httpd/webapps.d)" |
a715016d ER |
88 | fi |
89 | } | |
90 | ||
e9689537 ER |
91 | case "$action" in |
92 | register) | |
5ea8d8d5 | 93 | checkconfig && webapp_register |
e9689537 ER |
94 | ;; |
95 | unregister) | |
5ea8d8d5 | 96 | checkconfig && webapp_unregister |
e9689537 | 97 | ;; |
2ec41251 ER |
98 | list) |
99 | webapp_list $2 | |
100 | ;; | |
7b49779e TP |
101 | list-apps) |
102 | webapp_list_apps $2 | |
103 | ;; | |
e9689537 ER |
104 | *) |
105 | usage | |
106 | exit 1 | |
107 | esac |