diff --git a/ilot/listmonk/APKBUILD b/ilot/listmonk/APKBUILD new file mode 100644 index 0000000..00951f0 --- /dev/null +++ b/ilot/listmonk/APKBUILD @@ -0,0 +1,71 @@ +# Contributor: Antoine Martin (ayakael) +# Maintainer: Antoine Martin (ayakael) +pkgname=listmonk +pkgver=3.0.0 +pkgrel=0 +pkgdesc='Self-hosted newsletter and mailing list manager with a modern dashboard' +arch="all" +url=https://listmonk.app +license="AGPL3" +depends=" + libcap-setcap + postgresql + procps + " +makedepends="go npm nodejs yarn" +source=" + $pkgname-$pkgver.tar.gz::https://github.com/knadh/listmonk/archive/v$pkgver.tar.gz + listmonk.sh + listmonk.openrc + " +install="$pkgname.pre-install $pkgname.post-install $pkgname.post-upgrade" +subpackages="$pkgname-openrc" +pkgusers="listmonk" +pkggroups="listmonk" + +build() { + go build \ + -trimpath \ + -buildmode=pie \ + -mod=readonly \ + -modcacherw \ + -ldflags "-extldflags '$LDFLAGS' -X 'main.buildString=Alpine Linux v$pkgver-$pkgrel' -X 'main.versionString=v$pkgver'" \ + -o $pkgname \ + cmd/*.go + + ( + cd frontend + export YARN_CACHE_FOLDER="$srcdir/node_modules" + export VUE_APP_VERSION="v$pkgver" + yarn install --frozen-lockfile + yarn build + ) +} + +check() { + go test ./... +} + +package() { + install -Dm755 "$srcdir"/listmonk.sh "$pkgdir"/usr/bin/listmonk + install -Dm644 config.toml.sample "$pkgdir"/etc/listmonk/config.toml + install -Dm644 -t "$pkgdir"/usr/share/webapps/listmonk/ \ + schema.sql \ + queries.sql \ + config.toml.sample + install -Dm755 listmonk "$pkgdir"/usr/share/webapps/listmonk/ + install -Dm644 -t "$pkgdir"/usr/share/webapps/listmonk/frontend/dist/ \ + frontend/dist/static/favicon.png + cp -a frontend/dist/static "$pkgdir"/usr/share/webapps/listmonk/frontend/dist/static + cp -a frontend/dist/index.html "$pkgdir"/usr/share/webapps/listmonk/frontend/dist/index.html + cp -a static "$pkgdir"/usr/share/webapps/listmonk/ + cp -a i18n "$pkgdir"/usr/share/webapps/listmonk/ + install -Dm755 "$srcdir"/$pkgname.openrc \ + "$pkgdir"/etc/init.d/$pkgname + ln -s /etc/listmonk/config.toml "$pkgdir"/usr/share/webapps/listmonk/config.toml +} +sha512sums=" +afd0ea1d4d2b2753c3043526590cf09c45a541a2d818f5d1581644ffd10818326fd553a3b04bca59494860a7bb6e96364b08afd33d337a9fc5c71bedd1a5ee6c listmonk-3.0.0.tar.gz +939450af4b23708e3d23a5a88fad4c24b957090bdd21351a6dd520959e52e45e5fcac117a3eafa280d9506616dae39ad3943589571f008cac5abe1ffd8062424 listmonk.sh +8e9c0b1f335c295fb741418246eb17c7566e5e4200a284c6483433e8ddbf5250aa692435211cf062ad1dfcdce3fae9148def28f03f2492d33fe5e66cbeebd4bd listmonk.openrc +" diff --git a/ilot/listmonk/listmonk.openrc b/ilot/listmonk/listmonk.openrc new file mode 100644 index 0000000..e2ccb5b --- /dev/null +++ b/ilot/listmonk/listmonk.openrc @@ -0,0 +1,29 @@ +#!/sbin/openrc-run + +name="$RC_SVCNAME" +cfgfile="/etc/conf.d/$RC_SVCNAME.conf" +pidfile="/run/$RC_SVCNAME.pid" +working_directory="/usr/share/webapps/listmonk" +command="/usr/share/webapps/listmonk/listmonk" +command_user="listmonk" +command_group="listmonk" +start_stop_daemon_args="" +command_background="yes" +output_log="/var/log/listmonk/$RC_SVCNAME.log" +error_log="/var/log/listmonk/$RC_SVCNAME.err" + +depend() { + need postgresql +} + +start_pre() { + cd "$working_directory" + checkpath --directory --owner $command_user:$command_group --mode 0775 \ + /var/log/listmonk \ + /var/lib/listmonk +} + +stop_pre() { + ebegin "Killing child processes" + kill $(ps -o pid= --ppid $(cat $pidfile)) || true +} diff --git a/ilot/listmonk/listmonk.post-install b/ilot/listmonk/listmonk.post-install new file mode 100644 index 0000000..fe3cc8d --- /dev/null +++ b/ilot/listmonk/listmonk.post-install @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu + +setcap 'cap_net_bind_service=+ep' /usr/share/webapps/listmonk/listmonk + +if [ "${0##*.}" = 'post-upgrade' ]; then + cat >&2 <<-EOF + * + * To finish Listmonk upgrade run: + * + * listmonk --upgrade + * + EOF +else + cat >&2 <<-EOF + * + * 1. Adjust settings in /etc/listmonk/config.toml. + * + * 2. Create database for Listmonk: + * + * psql -c "CREATE ROLE listmonk PASSWORD 'top-secret' INHERIT LOGIN;" + * psql -c "CREATE DATABASE listmonk OWNER listmonk ENCODING 'UTF-8';" + * + * 3. Run "listmonk --install" + * + EOF +fi diff --git a/ilot/listmonk/listmonk.post-upgrade b/ilot/listmonk/listmonk.post-upgrade new file mode 120000 index 0000000..0b729b1 --- /dev/null +++ b/ilot/listmonk/listmonk.post-upgrade @@ -0,0 +1 @@ +listmonk.post-install \ No newline at end of file diff --git a/ilot/listmonk/listmonk.pre-install b/ilot/listmonk/listmonk.pre-install new file mode 100644 index 0000000..71eb3a0 --- /dev/null +++ b/ilot/listmonk/listmonk.pre-install @@ -0,0 +1,21 @@ +#!/bin/sh +# It's very important to set user/group correctly. + +listmonk_dir='/var/lib/listmonk' + +if ! getent group listmonk 1>/dev/null; then + echo '* Creating group listmonk' 1>&2 + + addgroup -S listmonk +fi + +if ! id listmonk 2>/dev/null 1>&2; then + echo '* Creating user listmonk' 1>&2 + + adduser -DHS -G listmonk -h "$listmonk_dir" -s /bin/sh \ + -g "added by apk for listmonk" listmonk + passwd -u listmonk 1>/dev/null # unlock +fi + + +exit 0 diff --git a/ilot/listmonk/listmonk.sh b/ilot/listmonk/listmonk.sh new file mode 100644 index 0000000..d89ca52 --- /dev/null +++ b/ilot/listmonk/listmonk.sh @@ -0,0 +1,12 @@ + +#!/bin/sh + +BUNDLE_DIR='/usr/share/webapps/listmonk' + +cd $BUNDLE_DIR + +if [ "$(id -un)" != 'listmonk' ]; then + exec su listmonk -c '"$0" "$@"' -- ./listmonk "$@" +else + exec ./listmonk "$@" +fi