From d827c398f00e965f5b57447c7d730f96442e1173 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 8 Oct 2024 11:36:46 -0500 Subject: [PATCH] try to rename as gowebd put the HTML assets raw in the binary also I'm how old and still committed a binary. squashed Signed-off-by: Jeff Carr --- .gitignore | 1 + Makefile | 15 +++++++++++---- README | 3 +++ args.go | 12 +++++++++--- build | 5 +++-- control | 4 ++-- gowebd.service | 8 ++++---- main.go | 17 ++++++++++++++--- postinst | 2 +- repoHTML.go | 14 +++++++++++--- resources/Makefile | 19 +++++++++++++++++++ resources/install.sh | 4 ---- resources/ipv6.png | Bin 0 -> 3654 bytes 13 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 README create mode 100644 resources/Makefile delete mode 100755 resources/install.sh create mode 100644 resources/ipv6.png 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 0000000000000000000000000000000000000000..6767c59b1c2e69c092fb2694ea9568a3fb3d61c6 GIT binary patch literal 3654 zcmZ`+XHe4*u>2(?bO<#lLE#Tlq=Pg;2vvz7gpyE2suZP5lNJ#aY&4}O^cLww1cU@3 z0#XGPM4BRmW`atuPv7VF=4Nka_S4SY%*|dB+UyDks~{@?030Y|L(9L6`v+#mzr9<> zWdHy`3El<qKY*oTI8#Z@F0V+)!2 z^{YpT_xnqQ_0u1mqfjgYC5J+VFWGE*NO18qv87Y4FkltApC)kf~_-W6E1s~$PJ*!HoC z0^}QC>SiC8aFQfUHE|3d^tfPCFyDi}TcpbyANGY%7Sx9$GNFXiYF7Ohzbn>f`MZ`T z*>!zPluQy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