# [PATCH 4/5] git-instaweb: Fall back to Apache when LigHTTP was not found

4 messages from 2006-07-26 to 2006-07-26. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/4991

## Johannes Schindelin, 2006-07-26 14:34

Subject: [PATCH 4/5] git-instaweb: Fall back to Apache when LigHTTP was not found
Message-ID: <Pine.LNX.4.63.0607261633560.29667@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0607261633560.29667%40wbgn013.biozentrum.uni-wuerzburg.de

```

Apache is more likely to be installed...

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 git-instaweb.sh |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/git-instaweb.sh b/git-instaweb.sh
index 1d3ea73..242b55e 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -25,9 +25,6 @@ conf=$GIT_DIR/gitweb/httpd.conf
 
 # Defaults:
 
-# if installed, it doesn't need further configuration (module_path)
-test -z "$httpd" && httpd='lighttpd -f'
-
 # probably the most popular browser among gitweb users
 test -z "$browser" && browser='firefox'
 
@@ -135,6 +132,15 @@ do
 	shift
 done
 
+# if installed, it doesn't need further configuration (module_path)
+if [ -z "$httpd" ]; then
+	httpd='lighttpd -f'
+	which "$httpd" >/dev/null 2>&1 || httpd='apache2 -f'
+	which "$httpd" >/dev/null 2>&1 || httpd='apache -f'
+	which "$httpd" >/dev/null 2>&1 || httpd='httpd -f'
+	which "$httpd" >/dev/null || exit 1
+fi
+
 mkdir -p "$GIT_DIR/gitweb/tmp"
 GIT_EXEC_PATH="`git --exec-path`"
 GIT_DIR="$fqgitdir"
-- 
1.4.2.rc2.g6a4e

```

## Junio C Hamano, 2006-07-26 19:22

Subject: Re: [PATCH 4/5] git-instaweb: Fall back to Apache when LigHTTP was not found
Message-ID: <7vr708qih4.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vr708qih4.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0607261633560.29667@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Apache is more likely to be installed...
>
> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> ---
>  git-instaweb.sh |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/git-instaweb.sh b/git-instaweb.sh
> index 1d3ea73..242b55e 100755
> --- a/git-instaweb.sh
> +++ b/git-instaweb.sh
> @@ -25,9 +25,6 @@ conf=$GIT_DIR/gitweb/httpd.conf
>  
>  # Defaults:
>  
> -# if installed, it doesn't need further configuration (module_path)
> -test -z "$httpd" && httpd='lighttpd -f'
> -
>  # probably the most popular browser among gitweb users
>  test -z "$browser" && browser='firefox'
>  
> @@ -135,6 +132,15 @@ do
>  	shift
>  done
>  
> +# if installed, it doesn't need further configuration (module_path)
> +if [ -z "$httpd" ]; then
> +	httpd='lighttpd -f'
> +	which "$httpd" >/dev/null 2>&1 || httpd='apache2 -f'
> +	which "$httpd" >/dev/null 2>&1 || httpd='apache -f'
> +	which "$httpd" >/dev/null 2>&1 || httpd='httpd -f'
> +	which "$httpd" >/dev/null || exit 1
> +fi
> +

Please don't use "which" in scripts.  Consult this thread:

http://thread.gmane.org/gmane.comp.version-control.git/23382/focus=23394

```

## Johannes Schindelin, 2006-07-26 19:57

Subject: Re: [PATCH 4/5] git-instaweb: Fall back to Apache when LigHTTP was not found
Message-ID: <Pine.LNX.4.63.0607262153380.29667@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0607262153380.29667%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <7vr708qih4.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Wed, 26 Jul 2006, Junio C Hamano wrote:

> Please don't use "which" in scripts.  Consult this thread:
> 
> http://thread.gmane.org/gmane.comp.version-control.git/23382/focus=23394

I remembered vaguely, so I searched in git-instaweb:

$ git grep -n which next:git-instaweb.sh
next:git-instaweb.sh:40: [white space...] which $httpd_only >/dev/null

Well, the fallback mechanism might not be that useful anyway: if you have 
apache, you have to specify the modules path. I'll do a patch instead 
which exits cleanly if either $httpd or $browser could not be executed, 
okay?

Ciao,
Dscho

```

## Johannes Schindelin, 2006-07-26 21:11

Subject: [PATCH] instaweb: Be more clear if httpd or the browser fail
Message-ID: <Pine.LNX.4.63.0607262310350.29667@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0607262310350.29667%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <Pine.LNX.4.63.0607262153380.29667@wbgn013.biozentrum.uni-wuerzburg.de>

```

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

On Wed, 26 Jul 2006, Johannes Schindelin wrote:

> Well, the fallback mechanism might not be that useful anyway: if you have 
> apache, you have to specify the modules path. I'll do a patch instead 
> which exits cleanly if either $httpd or $browser could not be executed, 
> okay?

Here you are

 git-instaweb.sh |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/git-instaweb.sh b/git-instaweb.sh
index 1d3ea73..585ad7c 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -54,6 +54,10 @@ start_httpd () {
 			fi
 		done
 	fi
+	if test $? != 0; then
+		echo "Could not execute http daemon $httpd."
+		exit 1
+	fi
 }
 
 stop_httpd () {
@@ -189,7 +193,7 @@ EOF
 	else
 		# plain-old CGI
 		list_mods=`echo "$httpd" | sed "s/-f$/-l/"`
-		$list_mods | grep 'mod_cgi\.c' >/dev/null || \
+		$list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
 		echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
 		cat >> "$conf" <<EOF
 AddHandler cgi-script .cgi
@@ -239,4 +243,5 @@ esac
 
 start_httpd
 test -z "$browser" && browser=echo
-$browser http://127.0.0.1:$port
+url=http://127.0.0.1:$port
+$browser $url || echo $url
-- 
1.4.2.rc2.g84db

```
