git-instaweb: improve auto-discovery of httpd and call conventions.
This patch allows calling: git-instaweb -d apache2 and have the script Do The Right Thing. In particular, the auto-discovery mechanism has been extended in order to be used for module listing as well, and the call convention is that if the daemon is apache2/lighttpd and the parameter to the "-d" option does not end by "-f", the "-f" is added to the end of the option itself. Change all backticks to $( ... ) as per Documentation/CodingGuidelines. Signed-off-by: Flavio Poletti <flavio@polettix.it> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Flavio Poletti committed
Jun 12, 2008 at 23:54 UTC
43d60d2e59cb466717290984becc8687fc632ca1
1 file changed
+33
-15
git-instaweb.sh
+33
-15
@@ -22,10 +22,10 @@ restart restart the web server
22
. git-sh-setup
23
24
fqgitdir="$GIT_DIR"
25
-local="`git config --bool --get instaweb.local`"
26
-httpd="`git config --get instaweb.httpd`"
27
-port=`git config --get instaweb.port`
28
-module_path="`git config --get instaweb.modulepath`"
25
+local="$(git config --bool --get instaweb.local)"
26
+httpd="$(git config --get instaweb.httpd)"
27
+port=$(git config --get instaweb.port)
28
+module_path="$(git config --get instaweb.modulepath)"
29
30
conf="$GIT_DIR/gitweb/httpd.conf"
31
@@ -37,11 +37,21 @@ test -z "$httpd" && httpd='lighttpd -f'
37
# any untaken local port will do...
38
test -z "$port" && port=1234
39
40
-start_httpd () {
41
- httpd_only="`echo $httpd | cut -f1 -d' '`"
40
+resolve_full_httpd () {
41
+ case "$httpd" in
42
+ *apache2*|*lighttpd*)
43
+ # ensure that the apache2/lighttpd command ends with "-f"
44
+ if ! echo "$httpd" | grep -- '-f *$' >/dev/null 2>&1
45
+ then
46
+ httpd="$httpd -f"
47
+ fi
48
+ ;;
49
+ esac
50
+
51
+ httpd_only="$(echo $httpd | cut -f1 -d' ')"
52
if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev/null;; esac
53
then
44
- $httpd "$fqgitdir/gitweb/httpd.conf"
54
+ full_httpd=$httpd
55
else
56
# many httpds are installed in /usr/sbin or /usr/local/sbin
57
# these days and those are not in most users $PATHs
@@ -51,16 +61,23 @@ start_httpd () {
61
do
62
if test -x "$i/$httpd_only"
63
then
54
- # don't quote $httpd, there can be
55
- # arguments to it (-f)
56
- $i/$httpd "$fqgitdir/gitweb/httpd.conf"
64
+ full_httpd=$i/$httpd
65
return
66
fi
67
done
60
- echo "$httpd_only not found. Install $httpd_only or use" \
61
- "--httpd to specify another http daemon."
68
+
69
+ echo >&2 "$httpd_only not found. Install $httpd_only or use" \
70
+ "--httpd to specify another httpd daemon."
71
exit 1
72
fi
73
+}
74
+
75
+start_httpd () {
76
+ # here $httpd should have a meaningful value
77
+ resolve_full_httpd
78
+
79
+ # don't quote $full_httpd, there can be arguments to it (-f)
80
+ $full_httpd "$fqgitdir/gitweb/httpd.conf"
81
if test $? != 0; then
82
echo "Could not execute http daemon $httpd."
83
exit 1
@@ -68,7 +85,7 @@ start_httpd () {
85
}
86
87
stop_httpd () {
71
- test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
88
+ test -f "$fqgitdir/pid" && kill $(cat "$fqgitdir/pid")
89
}
90
91
while test $# != 0
@@ -116,7 +133,7 @@ do
133
done
134
135
mkdir -p "$GIT_DIR/gitweb/tmp"
119
-GIT_EXEC_PATH="`git --exec-path`"
136
+GIT_EXEC_PATH="$(git --exec-path)"
137
GIT_DIR="$fqgitdir"
138
export GIT_EXEC_PATH GIT_DIR
139
@@ -215,7 +232,8 @@ PerlPassEnv GIT_EXEC_DIR
232
EOF
233
else
234
# plain-old CGI
218
- list_mods=`echo "$httpd" | sed "s/-f$/-l/"`
235
+ resolve_full_httpd
236
+ list_mods=$(echo "$full_httpd" | sed "s/-f$/-l/")
237
$list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
238
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
239
cat >> "$conf" <<EOF