Subject: [PATCH] testing/forgejo: add aport

From: Eragon <[email-masked]>
Date: Sat, 7 Jan 2023 00:14:47 +0100

https://forgejo.org
Self-hosted, lightweight software forge - A soft fork of Gitea
---
 testing/forgejo/APKBUILD            | 100 ++++++++++++++++++++++++++++
 testing/forgejo/forgejo.confd       |   4 ++
 testing/forgejo/forgejo.ini         |  32 +++++++++
 testing/forgejo/forgejo.initd       |  15 +++++
 testing/forgejo/forgejo.pre-install |   7 ++
 testing/forgejo/forgejo.sysusers    |   1 +
 6 files changed, 159 insertions(+)
 create mode 100644 testing/forgejo/APKBUILD
 create mode 100644 testing/forgejo/forgejo.confd
 create mode 100644 testing/forgejo/forgejo.ini
 create mode 100644 testing/forgejo/forgejo.initd
 create mode 100644 testing/forgejo/forgejo.pre-install
 create mode 100644 testing/forgejo/forgejo.sysusers

diff --git a/testing/forgejo/APKBUILD b/testing/forgejo/APKBUILD
new file mode 100644
index 0000000000..04737b60ce
--- /dev/null
+++ b/testing/forgejo/APKBUILD
@@ -0,0 +1,100 @@
+# Contributor: Carlo Landmeter <[email-masked]>
+# Contributor: 6543 <[email-masked]>
+# Contributor: techknowlogick <[email-masked]>
+# Contributor: Twann <tw4nn [at] disroot [dot] org>
+# Contributor: Maximilian Friedersdorff <[email-masked]>
+# Contributor: kageru <[email-masked]>
+# Contributor: Sam Whited <[email-masked]>
+# Contributor: Francois Menning <[email-masked]>
+# Contributor: Anton Kudryavtsev <[email-masked]>
+# Contributor: Frederik Schwan <frederik dot schwan at linux dot com>
+# Contributor: Thomas Fanninger <[email-masked]>
+# Contributor: Alexander F Rødseth <[email-masked]>
+# Contributor: Thomas Laroche <[email-masked]>
+# Maintainer: Eragon <[email-masked]>
+
+pkgname=forgejo
+pkgver=1.18.0
+_pkgrel=1
+pkgrel=0
+pkgdesc="Self-hosted, lightweight software forge - A soft fork of Gitea"
+url="https://forgejo.org"
+arch="all"
+license="MIT"
+depends="git git-lfs gnupg"
+makedepends="go libcap"
+checkdepends="bash openssh openssh-keygen sqlite tzdata"
+install="$pkgname.pre-install"
+pkgusers="forgejo"
+pkggroups="www-data"
+subpackages="$pkgname-openrc"
+source="$pkgname-$pkgver.tar.gz::https://codeberg.org/forgejo/forgejo/archive/v$pkgver-$_pkgrel.tar.gz
+	$pkgname.initd
+	$pkgname.confd
+	$pkgname.ini
+	"
+builddir="$srcdir/forgejo-src-$pkgver"
+
+# TODO : Get the check back in working condition
+# Need help on that because I can't get them to work - Eragon
+options="!check"
+
+build() {
+	cd $srcdir/$pkgname
+
+	export GOPATH="$srcdir/go"
+	export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw $GOFLAGS"
+
+	export CGO_CPPFLAGS="$CPPFLAGS"
+	export CGO_CFLAGS="$CFLAGS"
+	export CGO_CXXFLAGS="$CXXFLAGS"
+	export CGO_LDFLAGS="$LDFLAGS"
+
+	unset LDFLAGS
+	## make FHS compliant
+	LDFLAGS="$LDFLAGS -X code.gitea.io/gitea/modules/setting.CustomConf=/etc/forgejo/app.ini"
+	LDFLAGS="$LDFLAGS -X code.gitea.io/gitea/modules/setting.AppWorkPath=/var/lib/forgejo/"
+	LDFLAGS="$LDFLAGS -X code.gitea.io/gitea/modules/setting.StaticRootPath=/usr/share/webapps/forgejo/"
+	export LDFLAGS
+
+	export TAGS="tidb sqlite sqlite_unlock_notify"
+
+	## make should run without any parallelism
+	## parallelsm breaks the bindata target which relies on execution order
+	make backend -j1
+
+	# FIXME I don't understand why but go doesn't respect the -modcacherw option
+	chmod -R +w $GOPATH
+}
+
+package() {
+	for dir in $pkgname $pkgname/git $pkgname/data $pkgname/db $pkgname/custom; do
+		install -d -m 750 -o $pkgusers -g www-data \
+			"$pkgdir"/var/lib/$dir
+	done
+
+	install -d -m 755 -o $pkgusers -g www-data "$pkgdir"/var/log/$pkgname
+
+	install -D -m 755 "$srcdir"/$pkgname/gitea "$pkgdir"/usr/bin/$pkgname
+
+	# Allow non root to bind to port 80.
+	setcap cap_net_bind_service=+ep \
+		"$pkgdir"/usr/bin/$pkgname
+
+	install -D -m 644 -o $pkgusers -g www-data "$srcdir"/forgejo.ini \
+		"$pkgdir"/etc/$pkgname/app.ini
+	chown $pkgusers:www-data "$pkgdir"/etc/$pkgname
+
+	install -d -m 755 "$pkgdir"/usr/share/webapps/$pkgname
+	mv "$srcdir"/$pkgname/options "$srcdir"/$pkgname/public \
+		"$srcdir"/$pkgname/templates "$pkgdir"/usr/share/webapps/$pkgname/
+
+	install -D -m 644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
+	install -D -m 755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
+}
+sha512sums="
+1547e799de7066dbabad698acdf0cdedca4e2b18ac059e6a255c5b05d9231b2930810efe6d7be1fb3de6f28d47a95be499014ddd0d05f6e4754661e9765e6040  forgejo-1.18.0.tar.gz
+1fe168baac09bea86ab24e1f6283da9fdd8cd5d2bfc9822e521043a141612ae2dba1742f40d14f04a4ef58fbf875048edd5776f689ed09137997eb210fe0ec58  forgejo.initd
+a9367570a53b878f0fb9df39b5463ed6e24124e2b30a27a0d53ad76a8b03d0dbc4531ff07629bdd28cf4fcceb33c26b8efc2a30732b88f91ddc657b5df0c901c  forgejo.confd
+1c08ff558ec35b1f0bb1900f328f35a5fed5e29a14703ce451ecd902f3094b9c64de8a0adb3e5c69ad853b3c62a3558015095bc44affb8af41f20cd358f1b3d5  forgejo.ini
+"
diff --git a/testing/forgejo/forgejo.confd b/testing/forgejo/forgejo.confd
new file mode 100644
index 0000000000..72e31f3de1
--- /dev/null
+++ b/testing/forgejo/forgejo.confd
@@ -0,0 +1,4 @@
+FORGEJO_USER=forgejo
+FORGEJO_CONF=/etc/forgejo/app.ini
+FORGEJO_WORK_DIR=/var/lib/forgejo
+FORGEJO_LOG_FILE=/var/log/forgejo/http.log
diff --git a/testing/forgejo/forgejo.ini b/testing/forgejo/forgejo.ini
new file mode 100644
index 0000000000..9d739836e7
--- /dev/null
+++ b/testing/forgejo/forgejo.ini
@@ -0,0 +1,32 @@
+; forgejo doesn't contain a default config file
+; and instead expects the user to only define
+; the settings they want to change.
+; This file contains some base settings
+
+RUN_USER = forgejo
+RUN_MODE = prod
+
+[repository]
+ROOT = /var/lib/forgejo/repos
+SCRIPT_TYPE = sh
+; set this here so the default isn’t sneakily changed upstream
+DEFAULT_BRANCH = main
+
+[server]
+STATIC_ROOT_PATH = /usr/share/webapps/forgejo
+APP_DATA_PATH    = /var/lib/forgejo/data
+LFS_START_SERVER = true
+
+[database]
+DB_TYPE = sqlite3
+PATH = /var/lib/forgejo/db/gitea.db
+SSL_MODE = disable
+LOG_SQL = false
+
+[session]
+PROVIDER = file
+
+[log]
+ROOT_PATH = /var/log/forgejo/
+MODE = file
+LEVEL = Info
diff --git a/testing/forgejo/forgejo.initd b/testing/forgejo/forgejo.initd
new file mode 100644
index 0000000000..2c45ff281d
--- /dev/null
+++ b/testing/forgejo/forgejo.initd
@@ -0,0 +1,15 @@
+#!/sbin/openrc-run
+
+supervisor=supervise-daemon
+name=forgejo
+command="/usr/bin/forgejo"
+command_user="${FORGEJO_USER:-forgejo}"
+command_args="web --config '${FORGEJO_CONF:-/etc/forgejo/app.ini}'"
+supervise_daemon_args="--env GITEA_WORK_DIR='${FORGEJO_WORK_DIR:-/var/lib/forgejo}' --chdir '${FORGEJO_WORK_DIR:-/var/lib/forgejo}' --stdout '${FORGEJO_LOG_FILE:-/var/log/forgejo/http.log}' --stderr '${FORGEJO_LOG_FILE:-/var/log/forgejo/http.log}'"
+pidfile="/run/forgejo.pid"
+
+depend() {
+        use logger dns
+        need net
+        after firewall
+}
diff --git a/testing/forgejo/forgejo.pre-install b/testing/forgejo/forgejo.pre-install
new file mode 100644
index 0000000000..c4ac5f46d5
--- /dev/null
+++ b/testing/forgejo/forgejo.pre-install
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+addgroup -S -g 82 www-data 2>/dev/null
+adduser -S -D -h /var/lib/forgejo -s /bin/ash -G www-data -g forgejo forgejo 2>/dev/null \
+        && passwd -u forgejo 2>/dev/null
+
+exit 0
diff --git a/testing/forgejo/forgejo.sysusers b/testing/forgejo/forgejo.sysusers
new file mode 100644
index 0000000000..149bc0e2b6
--- /dev/null
+++ b/testing/forgejo/forgejo.sysusers
@@ -0,0 +1 @@
+u forgejo - "Forgejo daemon user" /var/lib/forgejo /usr/bin/bash
--
2.39.0