{"thread":{"id":"17729","subject":"[PATCH 1/1] git-instaweb: support for apache2/lighttpd by other names","startedAt":"2009-02-11T18:40:29Z","lastAt":"2009-06-16T09:02:09Z","messageCount":2,"participants":["Luciano Miguel Ferreira Rocha"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"104253","messageId":"20090211184029.GB1127@bit.office.eurotux.com","threadId":"17729","inReplyTo":null,"subject":"[PATCH 1/1] git-instaweb: support for apache2/lighttpd by other names","fromName":"Luciano Miguel Ferreira Rocha","fromEmail":"luciano@eurotux.com","sentAt":"2009-02-11T18:40:29Z","receivedAt":"2009-02-11T18:40:29Z","isPatch":true,"sender":{"key":"luciano@eurotux.com","avatar":null},"body":"Some distributions include the Apache httpd server as just \"httpd\", but\nspecifying the option --httpd=httpd doesn't work, as git-instaweb uses\nthe program name to detect the type of server used.\n\nNow the output if $httpd -v is used to also detect the server type.\n\nRemove also the hard-coded path to apache2 modules, use apache2's\ncompilation options.\n\nSigned-off-by: Luciano M. F. Rocha <luciano@eurotux.com>\n---\n git-instaweb.sh |  137 +++++++++++++++++++++++++++++++-----------------------\n 1 files changed, 79 insertions(+), 58 deletions(-)\n\ndiff --git a/git-instaweb.sh b/git-instaweb.sh\nindex 0843372..8c5aeb2 100755\n--- a/git-instaweb.sh\n+++ b/git-instaweb.sh\n@@ -31,53 +31,84 @@ conf=\"$GIT_DIR/gitweb/httpd.conf\"\n \n # Defaults:\n \n-# if installed, it doesn't need further configuration (module_path)\n-test -z \"$httpd\" && httpd='lighttpd -f'\n-\n # any untaken local port will do...\n test -z \"$port\" && port=1234\n \n-resolve_full_httpd () {\n-\tcase \"$httpd\" in\n-\t*apache2*|*lighttpd*)\n-\t\t# ensure that the apache2/lighttpd command ends with \"-f\"\n-\t\tif ! echo \"$httpd\" | grep -- '-f *$' >/dev/null 2>&1\n-\t\tthen\n-\t\t\thttpd=\"$httpd -f\"\n-\t\tfi\n-\t\t;;\n-\tesac\n+# add sbin directories to path, usually not done for normal users\n+PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin\n \n-\thttpd_only=\"$(echo $httpd | cut -f1 -d' ')\"\n-\tif case \"$httpd_only\" in /*) : ;; *) which $httpd_only >/dev/null;; esac\n-\tthen\n-\t\tfull_httpd=$httpd\n-\telse\n-\t\t# many httpds are installed in /usr/sbin or /usr/local/sbin\n-\t\t# these days and those are not in most users $PATHs\n-\t\t# in addition, we may have generated a server script\n-\t\t# in $fqgitdir/gitweb.\n-\t\tfor i in /usr/local/sbin /usr/sbin \"$fqgitdir/gitweb\"\n-\t\tdo\n-\t\t\tif test -x \"$i/$httpd_only\"\n-\t\t\tthen\n-\t\t\t\tfull_httpd=$i/$httpd\n-\t\t\t\treturn\n-\t\t\tfi\n-\t\tdone\n-\n-\t\techo >&2 \"$httpd_only not found. Install $httpd_only or use\" \\\n-\t\t     \"--httpd to specify another httpd daemon.\"\n-\t\texit 1\n-\tfi\n-}\n+# in addition, we may have generated a server script in $fqgitdir/gitweb.\n+PATH=$PATH:\"$fqgitdir/gitweb\"\n+\n+# search for a server if not defined\n+if test -z \"$httpd\"; then\n+\tfor httpd in lighttpd apache2 httpd; do\n+\t\ttype $httpd >/dev/null 2>&1 && break\n+\t\thttpd=\n+\tdone\n+fi\n+\n+# can't proceed without a server\n+if test -z \"$httpd\"; then\n+\techo >&2 \"No HTTP server found, specify and/or install one.\"\n+\texit 1\n+fi\n+\n+# check if server can be executed\n+httpd_only=\"$(echo $httpd | cut -f1 -d' ')\"\n+if ! type $httpd_only >/dev/null 2>&1; then\n+\techo >&2 \"$httpd_only not found. Install $httpd_only or use\" \\\n+\t     \"--httpd to specify another httpd daemon.\"\n+fi\n+\n+# add option -f?\n+uses_opt_f=\n+\n+# configuration generator\n+confgenerator=\n+\n+case \"$httpd\" in\n+*lighttpd*)\n+\tconfgenerator=lighttpd_conf\n+\tuses_opt_f=1\n+\t;;\n+*apache2*)\n+\tconfgenerator=apache2_conf\n+\tuses_opt_f=1\n+\t;;\n+webrick)\n+\tconfgenerator=webrick_conf\n+\t;;\n+*)\n+\t# deduce from server version string\n+\tcase \"$($httpd_only -v 2>/dev/null)\" in\n+\t\t*Apache/2.*)\n+\t\t\tconfgenerator=apache2_conf\n+\t\t\tuses_opt_f=1\n+\t\t\t;;\n+\t\t*lighttpd*)\n+\t\t\tconfgenerator=lighttpd_conf\n+\t\t\tuses_opt_f=1\n+\t\t\t;;\n+\t\t*)\n+\t\t\techo >&2 \"Unknown httpd specified: $httpd\"\n+\t\t\texit 1\n+\t\t\t;;\n+\tesac\n+esac\n \n start_httpd () {\n \t# here $httpd should have a meaningful value\n-\tresolve_full_httpd\n \n-\t# don't quote $full_httpd, there can be arguments to it (-f)\n-\t$full_httpd \"$fqgitdir/gitweb/httpd.conf\"\n+\t# ensure that the apache2/lighttpd command ends with \"-f\"\n+\tif test -n \"$uses_opt_f\" &&\n+\t\t! echo \"$httpd\" | grep -- '-f *$' >/dev/null 2>&1\n+\tthen\n+\t\thttpd=\"$httpd -f\"\n+\tfi\n+\n+\t# don't quote $httpd, there can be arguments to it (-f)\n+\t$httpd \"$fqgitdir/gitweb/httpd.conf\"\n \tif test $? != 0; then\n \t\techo \"Could not execute http daemon $httpd.\"\n \t\texit 1\n@@ -189,7 +220,13 @@ EOF\n }\n \n apache2_conf () {\n-\ttest -z \"$module_path\" && module_path=/usr/lib/apache2/modules\n+\tif test -z \"$module_path\"; then\n+\t\t# get module path from binary\n+\t\tmodule_path=$(\n+\t\t\teval $($httpd_only -V | sed -n -e '/ -D.*=/s/.*-D//p')\n+\t\t\techo $HTTPD_ROOT/modules\n+\t\t)\n+\tfi\n \tmkdir -p \"$GIT_DIR/gitweb/logs\"\n \tbind=\n \ttest x\"$local\" = xtrue && bind='127.0.0.1:'\n@@ -232,8 +269,7 @@ PerlPassEnv GIT_EXEC_DIR\n EOF\n \telse\n \t\t# plain-old CGI\n-\t\tresolve_full_httpd\n-\t\tlist_mods=$(echo \"$full_httpd\" | sed \"s/-f$/-l/\")\n+\t\tlist_mods=$(echo \"$httpd\" | sed \"s/-f$/-l/\")\n \t\t$list_mods | grep 'mod_cgi\\.c' >/dev/null 2>&1 || \\\n \t\techo \"LoadModule cgi_module $module_path/mod_cgi.so\" >> \"$conf\"\n \t\tcat >> \"$conf\" <<EOF\n@@ -271,22 +307,7 @@ EOFGITWEB\n gitweb_cgi \"$GIT_DIR/gitweb/gitweb.cgi\"\n gitweb_css \"$GIT_DIR/gitweb/gitweb.css\"\n \n-case \"$httpd\" in\n-*lighttpd*)\n-\tlighttpd_conf\n-\t;;\n-*apache2*)\n-\tapache2_conf\n-\t;;\n-webrick)\n-\twebrick_conf\n-\t;;\n-*)\n-\techo \"Unknown httpd specified: $httpd\"\n-\texit 1\n-\t;;\n-esac\n-\n+eval $confgenerator\n start_httpd\n url=http://127.0.0.1:$port\n \n-- \n1.6.2.rc0.36.g86413.dirty\n"},{"id":"116398","messageId":"20090616090209.GA3835@bit.office.eurotux.com","threadId":"17729","inReplyTo":"20090211184029.GB1127@bit.office.eurotux.com","subject":"Re: [PATCH 1/1] git-instaweb: support for apache2/lighttpd by other names","fromName":"Luciano Miguel Ferreira Rocha","fromEmail":"luciano@eurotux.com","sentAt":"2009-06-16T09:02:09Z","receivedAt":"2009-06-16T09:02:09Z","isPatch":true,"sender":{"key":"luciano@eurotux.com","avatar":null},"body":"On Wed, Feb 11, 2009 at 06:40:29PM +0000, Luciano Miguel Ferreira Rocha wrote:\n> Some distributions include the Apache httpd server as just \"httpd\", but\n> specifying the option --httpd=httpd doesn't work, as git-instaweb uses\n> the program name to detect the type of server used.\n> \n> Now the output if $httpd -v is used to also detect the server type.\n> \n> Remove also the hard-coded path to apache2 modules, use apache2's\n> compilation options.\n\n<snip>\n\nI got no replies. Is there any interest in this? Or in a pure perl\nserver option?\n\n-- \nLuciano Rocha <luciano@eurotux.com>\nEurotux Informática, S.A. <http://www.eurotux.com/>\n"}]}