diff --git a/.gitignore b/.gitignore index dfd72b0..c36ba6b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ go.mod go.sum go.wit.com +gowebd files/ diff --git a/Makefile b/Makefile index 5b0506e..7f81a70 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +VERSION = $(shell git describe --tags) + all: @echo "make run # will build and run the daemon here" @echo "make debian # will build a debian package" @@ -19,9 +21,9 @@ restart: run: git pull echo "build it!" - GO111MODULE=off go build -v -x - ./go.wit.com - # setcap 'cap_net_bind_service=+ep' go.wit.com # allow the binary to open ports below 1024 + GO111MODULE=off go build -v -x -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}" + ./gowebd --port 2233 + # setcap 'cap_net_bind_service=+ep' gowebd # allow the binary to open ports below 1024 goimports: goimports -w *.go @@ -31,6 +33,11 @@ redomod: GO111MODULE= go mod init GO111MODULE= go mod tidy +clean: + rm -f go.* + rm -f go.wit.com + rm -f gowebd + # makes a .deb package debian: - go-deb --no-gui --repo go.wit.com/apps/go.wit.com + go-deb --no-gui --repo go.wit.com/apps/gowebd diff --git a/README b/README new file mode 100644 index 0000000..5f8d80a --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +makes the website go.wit.com + +TODO: make it generic so it can use different DNS names diff --git a/args.go b/args.go index 0a36c28..b15d6ac 100644 --- a/args.go +++ b/args.go @@ -10,11 +10,17 @@ import ( "go.wit.com/dev/alexflint/arg" ) -var args struct { +var argv args + +type args struct { ListRepos bool `arg:"--list-repos" help:"list all repositories"` - Port int `arg:"--port" help:"port to run on (default is 2520)"` + Port int `arg:"--port" default:"2520" help:"port to run on"` +} + +func (args) Version() string { + return "virtigo " + Version } func init() { - arg.MustParse(&args) + arg.MustParse(&argv) } diff --git a/build b/build index 0128ce5..f0a2833 100755 --- a/build +++ b/build @@ -7,9 +7,10 @@ cp gowebd.service files/lib/systemd/system/ # caddy file. propose this as the dir structure caddy should use mkdir -p files/etc/gowebd/ cp Caddyfile.go.wit.com files/etc/gowebd/ -cp resources/repomap files/etc/gowebd/ +cp resources/Makefile files/etc/gowebd/ # share dir mkdir -p files/usr/share/gowebd/ cp Makefile files/usr/share/gowebd/ -cp resources/repomap files/usr/share/gowebd/go.wit.com +cp -a resources/repomap files/usr/share/gowebd/go.wit.com +cp -a resources files/usr/share/gowebd/ diff --git a/control b/control index 5b8c9db..3e71116 100644 --- a/control +++ b/control @@ -1,6 +1,6 @@ -Source: go.wit.com +Source: gowebd Build-Depends: golang -Package: go.wit.com +Package: gowebd Maintainer: Jeff Carr Architecture: amd64 Depends: caddy diff --git a/gowebd.service b/gowebd.service index fecaeed..e7c5c0c 100644 --- a/gowebd.service +++ b/gowebd.service @@ -1,13 +1,13 @@ [Unit] -Description=go.wit.com +Description=gowebd [Service] User=root Type=simple -ExecStart=/usr/bin/go.wit.com -ExecStop=killall go.wit.com +ExecStart=/usr/bin/gowebd +ExecStop=killall gowebd Restart=on-failure -RestartSec=30 +RestartSec=5 [Install] WantedBy=multi-user.target diff --git a/main.go b/main.go index 1bd3aa2..6f6dbe2 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,8 @@ import ( "go.wit.com/log" ) +var Version string + //go:embed resources/* var resources embed.FS @@ -21,6 +23,8 @@ var versionMap map[string]string var configfile []string var keysSorted []string +var HOSTNAME string = "go.wit.com" + // remove '?' part and trailing '/' func cleanURL(url string) string { url = "/" + strings.Trim(url, "/") @@ -38,7 +42,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { requrl := parts[0] url, repourl := findkey(requrl) - log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl) + log.Warn("gowebd URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl) if repourl != "" { repoHTML(w, url, repourl) return @@ -96,6 +100,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) { writeFile(w, "skeleton.v2.css") return } + if tmp == "/favicon.ico" { + writeFile(w, "ipv6.png") + return + } // used for uptime monitor checking if tmp == "/uptime" { writeFile(w, "uptime.html") @@ -150,7 +158,10 @@ func main() { log.Println("found log =", versionMap["go.wit.com/log"]) http.HandleFunc("/", okHandler) // go https() - err := http.ListenAndServe(":2520", nil) + p := fmt.Sprintf(":%d", argv.Port) + log.Println("HOSTNAME set to:", HOSTNAME) + log.Println("Running on port", p) + err := http.ListenAndServe(p, nil) if err != nil { log.Println("Error starting server:", err) } @@ -160,7 +171,7 @@ func badurl(w http.ResponseWriter, badurl string) { fmt.Fprintln(w, "") fmt.Fprintln(w, "") fmt.Fprintln(w, " ") - fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED
") diff --git a/postinst b/postinst index e67e381..2fb34e2 100755 --- a/postinst +++ b/postinst @@ -5,4 +5,4 @@ cd /etc/gowebd/ ln -s /usr/share/gowebd/go.wit.com . # allow the binary to open ports below 1024 -setcap 'cap_net_bind_service=+ep' /usr/bin/go.wit.com +setcap 'cap_net_bind_service=+ep' /usr/bin/gowebd diff --git a/repoHTML.go b/repoHTML.go index a00897b..9985e19 100644 --- a/repoHTML.go +++ b/repoHTML.go @@ -64,11 +64,19 @@ func findkey(url string) (string, string) { } func readconfigfile() { + var pfile []byte + var err error repoMap = make(map[string]string) - pfile, err := resources.ReadFile("resources/repomap") + + pfile, err = os.ReadFile("/etc/gowebd/repomap") if err != nil { - log.Error(err, "missing repomap in the binary") - return + log.Error(err, "no repository map file found in /etc/gowebd/") + log.Error(err, "falling back to the repository map file built into the gowebd binary") + pfile, err = resources.ReadFile("resources/repomap") + if err != nil { + log.Error(err, "missing repomap in the binary") + return + } } configfile = strings.Split(string(pfile), "\n") for _, line := range configfile { diff --git a/resources/Makefile b/resources/Makefile new file mode 100644 index 0000000..380f57c --- /dev/null +++ b/resources/Makefile @@ -0,0 +1,19 @@ +all: + gowebd --version + @echo "make log # watch gowebd log" + @echo "make restart # restart gowebd" + @echo "make enable # enable gowebd on boot" + @echo "make status # show the systemd status of gowebd" + +log: + @journalctl -f -xeu gowebd.service + +status: + systemctl status gowebd.service + +enable: + systemctl enable gowebd.service + +restart: + systemctl stop gowebd.service + systemctl start gowebd.service diff --git a/resources/install.sh b/resources/install.sh deleted file mode 100755 index 88642a5..0000000 --- a/resources/install.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -x -# - -echo "TODO: make this work" diff --git a/resources/ipv6.png b/resources/ipv6.png new file mode 100644 index 0000000..6767c59 Binary files /dev/null and b/resources/ipv6.png differ