File PKGBUILD of Package gotosocial-hardened

# Maintainer: Oleksandr Natalenko <oleksandr@natalenko.name>

pkgname=gotosocial-hardened
pkgver=0.20.1
pkgrel=1
pkgdesc="ActivityPub social network server"
url=https://gotosocial.org
license=(AGPL-3.0-or-later)
arch=(x86_64)
backup=(etc/credstore/gotosocial/config.yaml
		etc/gotosocial/template/2fa.tmpl
		etc/gotosocial/template/404.tmpl
		etc/gotosocial/template/about.tmpl
		etc/gotosocial/template/authorize.tmpl
		etc/gotosocial/template/confirm-email.tmpl
		etc/gotosocial/template/confirmed-email.tmpl
		etc/gotosocial/template/domain-allowlist.tmpl
		etc/gotosocial/template/domain-blocklist.tmpl
		etc/gotosocial/template/email_confirm.tmpl
		etc/gotosocial/template/email_new_report.tmpl
		etc/gotosocial/template/email_new_signup.tmpl
		etc/gotosocial/template/email_report_closed.tmpl
		etc/gotosocial/template/email_reset.tmpl
		etc/gotosocial/template/email_signup_approved.tmpl
		etc/gotosocial/template/email_signup_rejected.tmpl
		etc/gotosocial/template/email_test.tmpl
		etc/gotosocial/template/error.tmpl
		etc/gotosocial/template/finalize.tmpl
		etc/gotosocial/template/index.tmpl
		etc/gotosocial/template/index_register.tmpl
		etc/gotosocial/template/index_what_is_this.tmpl
		etc/gotosocial/template/login-info.tmpl
		etc/gotosocial/template/login_button.tmpl
		etc/gotosocial/template/maintenance.tmpl
		etc/gotosocial/template/oob.tmpl
		etc/gotosocial/template/page.tmpl
		etc/gotosocial/template/page_footer.tmpl
		etc/gotosocial/template/page_header.tmpl
		etc/gotosocial/template/page_ogmeta.tmpl
		etc/gotosocial/template/page_stylesheets.tmpl
		etc/gotosocial/template/profile-gallery.tmpl
		etc/gotosocial/template/profile.tmpl
		etc/gotosocial/template/profile_about_user.tmpl
		etc/gotosocial/template/profile_fields.tmpl
		etc/gotosocial/template/profile_header.tmpl
		etc/gotosocial/template/settings.tmpl
		etc/gotosocial/template/sign-in.tmpl
		etc/gotosocial/template/sign-up.tmpl
		etc/gotosocial/template/signed-up.tmpl
		etc/gotosocial/template/status.tmpl
		etc/gotosocial/template/status_attachment.tmpl
		etc/gotosocial/template/status_attributes.tmpl
		etc/gotosocial/template/status_header.tmpl
		etc/gotosocial/template/status_info.tmpl
		etc/gotosocial/template/status_poll.tmpl
		etc/gotosocial/template/tag.tmpl
		etc/gotosocial/template/thread.tmpl)
source=(https://codeberg.org/superseriousbusiness/gotosocial/archive/v${pkgver}.tar.gz
		config.diff
		yarn.tar.zst
		gotosocial.service)
makedepends=(go go-swagger yarn nodejs)
conflicts=(gotosocial)
provides=(gotosocial)
replaces=(gotosocial)
sha256sums=('1a9e2e929a8fa58421ac7d5a066717827c80f57aabeffe86762edff90ba1e123'
            '27f700352456475d6d4645663b1782b9ec46c425c74edcf661bed3ad32a76570'
            '3d8d7b553962ea3873a18b76f93ae02d4c0df5ab8f546109a81ffaca1abe828d'
            '888303d842537fb12ef8ff140c1b8a32091c3121ea090b74eadea985bb3c57d0')

prepare() {
	cd gotosocial

	patch -N example/config.yaml -i ../config.diff
}

build() {
	cd gotosocial

	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=vendor -modcacherw -buildvcs=false"
	mkdir build

	swagger generate spec --scan-models --exclude-deps -o web/assets/swagger.yaml
	sed -i "s|REPLACE_ME|${pkgver}|" web/assets/swagger.yaml

	go build -o build/gotosocial -ldflags="-X 'main.Version=${pkgver}'" ./cmd/gotosocial/

	yarn --offline --cache-folder "${srcdir}"/yarn --cwd web/source install
	yarn --offline --cache-folder "${srcdir}"/yarn --cwd web/source ts-patch install
	yarn --offline --cache-folder "${srcdir}"/yarn --cwd web/source build
}

package() {
	cd gotosocial

	install -Dt "${pkgdir}"/usr/bin -m0755 build/gotosocial
	install -Dt "${pkgdir}"/usr/lib/systemd/system -m0644 ../gotosocial.service

	install -Dt "${pkgdir}"/etc/credstore/gotosocial -m0400 example/config.yaml
	chmod 700 "${pkgdir}"/etc/credstore

	install -d "${pkgdir}"/usr/share/gotosocial
	cp -r web/assets/* "${pkgdir}"/usr/share/gotosocial

	install -d "${pkgdir}"/etc/gotosocial
	cp -r web/template "${pkgdir}"/etc/gotosocial
}
openSUSE Build Service is sponsored by