aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--Makefile19
-rw-r--r--dist/config.toml13
-rw-r--r--dist/scrapbook.service11
-rw-r--r--main.go26
-rw-r--r--web/command/html/site.go10
6 files changed, 64 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index 5fc24f2..b23adf8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
-config.toml
+/config.toml
scrapbook
-out
+runlocal
+*.tgz
+description-pak
+*.deb
diff --git a/Makefile b/Makefile
index 2a9c96b..f07be5a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
BINARY_NAME=scrapbook
SYS_CONF_DIR=/etc/scrapbook
-SYS_CONF_DIR=/var/lib/scrapbook
+SYS_DATA_DIR=/var/lib/scrapbook
+SYSTEMD_DIR=/etc/systemd/system
all: build
@@ -9,9 +10,19 @@ build:
runlocal:
PWD=$(shell pwd)
- mkdir -p out
- go build -ldflags "-X 'github.com/LMBishop/scrapbook/pkg/constants.SysConfDir=${PWD}/out/config' -X 'github.com/LMBishop/scrapbook/pkg/constants.SysDataDir=${PWD}/out/data'" -o out/${BINARY_NAME} main.go
- cd out; ./${BINARY_NAME}
+ mkdir -p runlocal
+ go build -ldflags "-X 'github.com/LMBishop/scrapbook/pkg/constants.SysConfDir=${PWD}/runlocal/config' -X 'github.com/LMBishop/scrapbook/pkg/constants.SysDataDir=${PWD}/runlocal/data'" -o runlocal/${BINARY_NAME} main.go
+ cd runlocal; ./${BINARY_NAME}
+
+install: build
+ install -Dm755 ${BINARY_NAME} /usr/local/bin/${BINARY_NAME}
+
+installconf:
+ install -Dm755 dist/scrapbook.service ${SYSTEMD_DIR}/
+ install -Dm755 dist/config.toml ${SYS_CONF_DIR}/config.toml
+ if ! getent passwd scrapbook > /dev/null; then \
+ useradd --system --create-home --shell /usr/sbin/nologin --home-dir ${SYS_DATA_DIR} scrapbook ;\
+ fi
clean:
go clean
diff --git a/dist/config.toml b/dist/config.toml
new file mode 100644
index 0000000..a557edc
--- /dev/null
+++ b/dist/config.toml
@@ -0,0 +1,13 @@
+[Listen]
+Address = '0.0.0.0'
+Port = 80
+
+[Command]
+Host = ''
+Secret = ''
+
+[[API]]
+Enable = true
+
+[[Web]]
+Enable = true
diff --git a/dist/scrapbook.service b/dist/scrapbook.service
new file mode 100644
index 0000000..c12ed45
--- /dev/null
+++ b/dist/scrapbook.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=scrapbook server
+
+[Service]
+User=scrapbook
+Group=scrapbook
+Restart=always
+ExecStart=/usr/local/bin/scrapbook
+
+[Install]
+WantedBy=multi-user.target
diff --git a/main.go b/main.go
index 5be14da..8292649 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"net/http"
+ "os"
"path"
"path/filepath"
@@ -32,21 +33,16 @@ func main() {
siteIndex := index.NewSiteIndex()
- err = index.ScanDirectory(path.Join(constants.SysDataDir, "sites"), siteIndex)
+ sitesDirectory := path.Join(constants.SysDataDir, "sites")
+ os.MkdirAll(sitesDirectory, 0o755)
+
+ err = index.ScanDirectory(sitesDirectory, siteIndex)
if err != nil {
panic(fmt.Errorf("could not scan data directory: %w", err))
}
slog.Info("initial data directory scan complete", "sites", len(siteIndex.GetSites()))
- if cfg.Command.Host == "" {
- slog.Warn("command interface host is empty - neither api or web interface will be accessible")
- }
-
- if cfg.Command.Secret == "" {
- slog.Warn("command interface secret is empty - neither api or web interface will be accessible")
- }
-
secretKey := make([]byte, 32)
rand.Read(secretKey)
@@ -54,10 +50,18 @@ func main() {
mux := http.NewServeMux()
- mux.Handle(fmt.Sprintf("%s/api/", cfg.Command.Host), http.StripPrefix("/api/", api.NewMux(&cfg, siteIndex)))
- mux.Handle(fmt.Sprintf("%s/", cfg.Command.Host), web.NewMux(&cfg, siteIndex, authenticator))
+ if cfg.Command.Host == "" {
+ slog.Warn("command interface host is empty - neither api or web interface will be accessible")
+ } else {
+ mux.Handle(fmt.Sprintf("%s/api/", cfg.Command.Host), http.StripPrefix("/api/", api.NewMux(&cfg, siteIndex)))
+ mux.Handle(fmt.Sprintf("%s/", cfg.Command.Host), web.NewMux(&cfg, siteIndex, authenticator))
+ }
mux.HandleFunc("/", server.ServeSite(siteIndex))
+ if cfg.Command.Secret == "" {
+ slog.Warn("command interface secret is empty - neither api or web interface will be accessible")
+ }
+
err = http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Listen.Address, cfg.Listen.Port), mux)
slog.Error("http server closing", "reason", err.Error())
}
diff --git a/web/command/html/site.go b/web/command/html/site.go
index b3e0cc1..cb1fa31 100644
--- a/web/command/html/site.go
+++ b/web/command/html/site.go
@@ -63,12 +63,12 @@ func SitePage(mainConfig *config.MainConfig, site *site.Site) Node {
}
}),
),
- Div(
- Class("control-group group-right"),
-
- navButton("Upload new version", "upload"),
- ),
}),
+ Div(
+ Class("control-group group-right"),
+
+ navButton("Upload new version", "upload"),
+ ),
H2(Text("Information")),