diff options
| author | Jeff Carr <[email protected]> | 2024-10-08 11:36:46 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-11 17:15:57 -0500 | 
| commit | d827c398f00e965f5b57447c7d730f96442e1173 (patch) | |
| tree | 0b89a8c17918ecdbb28887e4b228ab746517939c | |
| parent | c6be85e92f00b527ccd2e7bf55f804f9a1619e88 (diff) | |
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 <[email protected]>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 15 | ||||
| -rw-r--r-- | README | 3 | ||||
| -rw-r--r-- | args.go | 12 | ||||
| -rwxr-xr-x | build | 5 | ||||
| -rw-r--r-- | control | 4 | ||||
| -rw-r--r-- | gowebd.service | 8 | ||||
| -rw-r--r-- | main.go | 17 | ||||
| -rwxr-xr-x | postinst | 2 | ||||
| -rw-r--r-- | repoHTML.go | 14 | ||||
| -rw-r--r-- | resources/Makefile | 19 | ||||
| -rwxr-xr-x | resources/install.sh | 4 | ||||
| -rw-r--r-- | resources/ipv6.png | bin | 0 -> 3654 bytes | 
13 files changed, 78 insertions, 26 deletions
@@ -3,4 +3,5 @@ go.mod  go.sum  go.wit.com +gowebd  files/ @@ -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 @@ -0,0 +1,3 @@ +makes the website go.wit.com + +TODO: make it generic so it can use different DNS names @@ -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)  } @@ -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/ @@ -1,6 +1,6 @@ -Source: go.wit.com +Source: gowebd  Build-Depends: golang -Package: go.wit.com +Package: gowebd  Maintainer: Jeff Carr <[email protected]>  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 @@ -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, "<!DOCTYPE html>")  	fmt.Fprintln(w, "<html>")  	fmt.Fprintln(w, "    <head>") -	fmt.Fprintln(w, "        <meta http-equiv=\"refresh\" content=\"3; url=https://go.wit.com/\">") +	fmt.Fprintln(w, "        <meta http-equiv=\"refresh\" content=\"3; url=https://" + HOSTNAME + "/\">")  	fmt.Fprintln(w, "    </head>")  	fmt.Fprintln(w, "    <body>")  	fmt.Fprintln(w, "        IPv4 IS NOT SUPPORTED<br>") @@ -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 Binary files differnew file mode 100644 index 0000000..6767c59 --- /dev/null +++ b/resources/ipv6.png  | 
