summaryrefslogtreecommitdiff
path: root/opt/gotify/MAKEPKG
diff options
context:
space:
mode:
Diffstat (limited to 'opt/gotify/MAKEPKG')
-rw-r--r--opt/gotify/MAKEPKG163
1 files changed, 163 insertions, 0 deletions
diff --git a/opt/gotify/MAKEPKG b/opt/gotify/MAKEPKG
new file mode 100644
index 0000000..fe0e070
--- /dev/null
+++ b/opt/gotify/MAKEPKG
@@ -0,0 +1,163 @@
+#!/bin/mkpkg
+# description: Self-hosted server for sending and receiving push messages
+# url: https://gotify.net/
+
+# Note: the Go binary embeds the WebUI via //go:embed, so nodejs/yarn are
+# required at build time. sqlite3 support comes from mattn/go-sqlite3, which is
+# cgo - a CGO_ENABLED=0 build compiles but panics on any database access. The
+# SQLite amalgamation is bundled by that module, so there is no link against
+# the system libsqlite3 (that needs -tags libsqlite3).
+
+name=gotify
+version=3.1.1
+release=2
+makedeps=(go nodejs yarn)
+groups=(gotify:user:gotify:/var/lib/gotify:750:901:901)
+services=(gotify)
+permissions=(
+ /usr/bin/gotify:root:gotify:750
+ /etc/gotify:root:gotify:750
+ /etc/gotify/server.env:root:gotify:640
+ /var/lib/gotify:gotify:gotify:750
+ /var/lib/gotify/images:gotify:gotify:750
+)
+source=(https://github.com/$name/server/archive/refs/tags/v$version.tar.gz)
+renames=($name-$version.tar.gz)
+sha256sums=(
+ "61e2b5d97ccbf1bba62420f8800b45295cd24b5cf9e149c24963554a0fbae1a5"
+)
+
+patch() {
+ cd server-$version
+
+ # vite 8 defaults build.cssMinify to lightningcss, whose prebuilt native
+ # binding is unusable here. gotify does not configure it; disabling the
+ # minifier drops the native dependency entirely.
+ sed -i "s|sourcemap: false,|sourcemap: false,\n cssMinify: false,|" ui/vite.config.ts
+}
+
+build() {
+ cd server-$version
+
+ # ui/serve.go has "//go:embed build/*", so the WebUI must be built before
+ # the Go build. puppeteer is a devDependency that fetches a Chromium
+ # tarball on install - skip it. --non-interactive is not cosmetic: it is
+ # the first thing checkUpdate() tests, and yarn's update check writes to
+ # /usr/local/share/.yarnrc when running as root.
+ export PUPPETEER_SKIP_DOWNLOAD=true
+ cd ui
+ yarn install --frozen-lockfile --non-interactive
+ yarn build
+ cd ..
+
+ export GOFLAGS="-trimpath -mod=readonly -v"
+ export GOTOOLCHAIN=local # do not fetch a toolchain from the module proxy
+ export CGO_ENABLED=1 # required by mattn/go-sqlite3
+
+ go build \
+ -ldflags "-s -w -X main.Version=$version -X main.BuildDate=$(date -u +%F) -X main.Mode=prod" \
+ -o bin/gotify \
+ .
+
+ install -Dm755 bin/gotify $PKG/usr/bin/gotify
+
+ # Config directory
+ install -d -m 750 $PKG/etc/gotify
+
+ printf '%s\n' \
+ '## rawnix Gotify configuration' \
+ '## Full reference: gotify-server.env.example in the source tarball' \
+ '## Every key also accepts a _FILE suffix to read the value from a file.' \
+ '' \
+ '# Listen on loopback + an unprivileged port. Terminate TLS in a reverse' \
+ '# proxy (see the caddy port) rather than in gotify itself.' \
+ 'GOTIFY_SERVER_LISTENADDR=127.0.0.1' \
+ 'GOTIFY_SERVER_PORT=8080' \
+ '' \
+ '# Unix socket instead of TCP. Requires the umask change noted in' \
+ '# /etc/sv/gotify/run, and the proxy must run with gotify as a' \
+ '# supplementary group.' \
+ '# GOTIFY_SERVER_LISTENADDR=unix:/run/gotify/gotify.sock' \
+ '' \
+ '# Uncomment when reached over HTTPS' \
+ '# GOTIFY_SERVER_SECURECOOKIE=true' \
+ '# GOTIFY_SERVER_TRUSTEDPROXIES=127.0.0.1/32,::1' \
+ '' \
+ '# Storage' \
+ 'GOTIFY_DATABASE_DIALECT=sqlite3' \
+ 'GOTIFY_DATABASE_CONNECTION=/var/lib/gotify/gotify.db' \
+ 'GOTIFY_UPLOADEDIMAGESDIR=/var/lib/gotify/images' \
+ '' \
+ '# Plugin loading disabled - an empty value means no directory is scanned' \
+ 'GOTIFY_PLUGINSDIR=' \
+ '' \
+ '# Initial admin account. CHANGE THIS BEFORE THE FIRST START: it is only' \
+ '# applied while the database is being created, later changes go through' \
+ '# the WebUI.' \
+ 'GOTIFY_DEFAULTUSER_NAME=admin' \
+ 'GOTIFY_DEFAULTUSER_PASS=admin' \
+ 'GOTIFY_PASSSTRENGTH=12' \
+ '' \
+ '# No self-service account creation' \
+ 'GOTIFY_REGISTRATION=false' \
+ '' \
+ '# Logging - svlogd gets plain text' \
+ 'GOTIFY_LOGLEVEL=info' \
+ 'NOCOLOR=1' \
+ > $PKG/etc/gotify/server.env
+
+ # State directory
+ install -d -m 750 $PKG/var/lib/gotify
+ install -d -m 750 $PKG/var/lib/gotify/images
+}
+
+post_build() {
+ # runit service
+ install -d $PKG/etc/sv/gotify/log
+
+ printf '%s\n' \
+ '#!/bin/sh' \
+ 'exec 2>&1' \
+ '' \
+ '# Prepare runtime directories (/var/lib/gotify ownership comes from' \
+ '# the package permissions= directive)' \
+ 'install -d -m 750 -o gotify -g gotify /run/gotify' \
+ '' \
+ '# For unix-socket mode the listener inherits the umask, and connecting' \
+ '# to a socket needs write permission. Uncomment to get 0770 on it, and' \
+ '# run the proxy with gotify as a supplementary group, e.g.' \
+ '# chpst -u caddy:caddy:gotify' \
+ '# umask 007' \
+ '' \
+ '# Load this file exclusively, skipping the ./ and $XDG_CONFIG_HOME lookups' \
+ 'export GOTIFY_CONFIG_FILE=/etc/gotify/server.env' \
+ '' \
+ 'exec chpst -u gotify:gotify gotify serve' \
+ > $PKG/etc/sv/gotify/run
+
+ printf '%s\n' \
+ '#!/bin/sh' \
+ 'mkdir -p /var/log/gotify' \
+ 'exec svlogd -tt /var/log/gotify' \
+ > $PKG/etc/sv/gotify/log/run
+
+ printf '%s\n' \
+ '#!/bin/sh' \
+ 'rm -rf /run/gotify' \
+ > $PKG/etc/sv/gotify/finish
+
+ chmod 755 $PKG/etc/sv/gotify/run
+ chmod 755 $PKG/etc/sv/gotify/log/run
+ chmod 755 $PKG/etc/sv/gotify/finish
+
+ # Service disabled by default - change the admin password in
+ # /etc/gotify/server.env, then: rm /etc/sv/gotify/down
+ touch $PKG/etc/sv/gotify/down
+}
+
+signify() {
+ untrusted comment: public key
+ RWTZ9IduCSQ/mL8337TEUinPwT92xFEUpD92hkS7IxcOnzTt9QdpohT3
+}
+
+# vim: filetype=sh