summaryrefslogtreecommitdiff
path: root/opt/gotify/MAKEPKG
blob: fe0e0703caf6ac8a483b6b9f4b79444c3fc7f12d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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