From d4b274c08ce2bec53105a68442623a437f4b4226 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 25 Jan 2011 12:43:43 -0800 Subject: [PATCH] Include a gitweb config file; use it. --- website/camweb.go | 51 +++++++++++++++++++++++++-------------- website/gitweb-camli.conf | 35 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 website/gitweb-camli.conf diff --git a/website/camweb.go b/website/camweb.go index fb0454c03..d22049c32 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -17,10 +17,10 @@ import ( const defaultAddr = ":31798" // default webserver address var ( - httpAddr = flag.String("http", defaultAddr, "HTTP service address (e.g., '"+defaultAddr+"')") - root = flag.String("root", "", "Website root (parent of 'static', 'content', and 'tmpl") - gitwebScript = flag.String("gitwebscript", "/usr/lib/cgi-bin/gitweb.cgi", "Path to gitweb.cgi, or blank to disable.") - gitwebFiles = flag.String("gitwebfiles", "/usr/share/gitweb", "Path to gitweb's static files.") + httpAddr = flag.String("http", defaultAddr, "HTTP service address (e.g., '"+defaultAddr+"')") + root = flag.String("root", "", "Website root (parent of 'static', 'content', and 'tmpl") + gitwebScript = flag.String("gitwebscript", "/usr/lib/cgi-bin/gitweb.cgi", "Path to gitweb.cgi, or blank to disable.") + gitwebFiles = flag.String("gitwebfiles", "/usr/share/gitweb", "Path to gitweb's static files.") pageHtml, errorHtml *template.Template ) @@ -121,7 +121,7 @@ func readTemplates() { func serveError(w http.ResponseWriter, r *http.Request, relpath string, err os.Error) { contents := applyTemplate(errorHtml, "errorHtml", err) // err may contain an absolute path! w.WriteHeader(http.StatusNotFound) - servePage(w, "File "+relpath, "", contents) + servePage(w, "File "+relpath, "", contents) } func mainHandler(rw http.ResponseWriter, req *http.Request) { @@ -151,14 +151,14 @@ func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath strin data, err := ioutil.ReadFile(absPath) if err != nil { serveError(rw, req, absPath, err) - return + return } - servePage(rw, "", "", []byte(data)) + servePage(rw, "", "", []byte(data)) } -type gitwebHandler struct{ - Cgi http.Handler - Static http.Handler +type gitwebHandler struct { + Cgi http.Handler + Static http.Handler } func (h *gitwebHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { @@ -174,21 +174,36 @@ func main() { flag.Parse() readTemplates() + if *root == "" { + var err os.Error + *root, err = os.Getwd() + if err != nil { + log.Exitf("Failed to getwd: %v", err) + } + } + mux := http.DefaultServeMux mux.Handle("/favicon.ico", http.FileServer(path.Join(*root, "static"), "/")) mux.Handle("/static/", http.FileServer(path.Join(*root, "static"), "/static/")) - mux.Handle("/test.cgi", &CgiHandler{ExecutablePath: path.Join(*root, "test.cgi")}) + + testCgi := &CgiHandler{ExecutablePath: path.Join(*root, "test.cgi"), + Root: "/test.cgi", + } + mux.Handle("/test.cgi", testCgi) + mux.Handle("/test.cgi/foo", testCgi) + mux.Handle("/code", http.RedirectHandler("/code/", http.StatusFound)) if *gitwebScript != "" { + env := os.Environ() + env = append(env, "GITWEB_CONFIG="+path.Join(*root, "gitweb-camli.conf")) mux.Handle("/code/", &gitwebHandler{ - Cgi: &CgiHandler{ExecutablePath: *gitwebScript}, - Static: http.FileServer(*gitwebFiles, "/code/"), + Cgi: &CgiHandler{ + ExecutablePath: *gitwebScript, + Root: "/code/", + Environ: env, + }, + Static: http.FileServer(*gitwebFiles, "/code/"), }) - // For now, also register this alias for convenience. - // Some distros' default gitweb config links to resources - // in the current directory but Lucid links to /gitweb/ instead. - // TODO: specify a gitweb config file. - mux.Handle("/gitweb/", http.FileServer(*gitwebFiles, "/gitweb/")) } mux.HandleFunc("/", mainHandler) diff --git a/website/gitweb-camli.conf b/website/gitweb-camli.conf new file mode 100644 index 000000000..080fbd66c --- /dev/null +++ b/website/gitweb-camli.conf @@ -0,0 +1,35 @@ +# path to git projects (.git) +$projectroot = "/var/lib/git"; + +# directory to use for temp files +$git_temp = "/tmp"; + +# target of the home link on top of all pages +#$home_link = $my_uri || "/"; + +# html text to include at home page +$home_text = "indextext.html"; + +# file with project list; by default, simply scan the projectroot dir. +$projects_list = $projectroot; + +# stylesheet to use +$stylesheet = "/code/gitweb.css"; + +# javascript code for gitweb +$javascript = "/code/gitweb.js"; + +# logo to use +$logo = "/code/git-logo.png"; + +# the 'favicon' +$favicon = "/code/git-favicon.png"; + +$site_name = "Camlistore Git"; + +$site_header = "

HEADER

"; + +$home_link_str = "camlistore"; + +$my_uri = "/code/"; +