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