From 963eb51234fa733bdb22d645b7101c62fef6ad90 Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Tue, 21 May 2024 15:29:08 +0200
Subject: ceres: Version 0.4.0-1

---
 ceres/0001-Disable-logging-time-stamps.patch | 25 +++++++++++++
 ceres/0002-Select-default-storage.patch      | 22 +++++++++++
 ceres/PKGBUILD                               | 56 ++++++++++++++++++++--------
 ceres/ceres.service                          |  2 +-
 4 files changed, 89 insertions(+), 16 deletions(-)
 create mode 100644 ceres/0001-Disable-logging-time-stamps.patch
 create mode 100644 ceres/0002-Select-default-storage.patch

diff --git a/ceres/0001-Disable-logging-time-stamps.patch b/ceres/0001-Disable-logging-time-stamps.patch
new file mode 100644
index 0000000..1fffb28
--- /dev/null
+++ b/ceres/0001-Disable-logging-time-stamps.patch
@@ -0,0 +1,25 @@
+From dc488654d653ae05f1bf22603955f5a9b967ccd6 Mon Sep 17 00:00:00 2001
+From: xengineering <me@xengineering.eu>
+Date: Wed, 22 May 2024 20:09:34 +0200
+Subject: [PATCH] Disable logging time stamps
+
+---
+ main.go | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/main.go b/main.go
+index b77c803..c0ac533 100644
+--- a/main.go
++++ b/main.go
+@@ -13,6 +13,8 @@ import (
+ )
+ 
+ func main() {
++	log.SetFlags(0)
++
+ 	flag.Parse()
+ 
+ 	if flags.version {
+-- 
+2.45.1
+
diff --git a/ceres/0002-Select-default-storage.patch b/ceres/0002-Select-default-storage.patch
new file mode 100644
index 0000000..fe35150
--- /dev/null
+++ b/ceres/0002-Select-default-storage.patch
@@ -0,0 +1,22 @@
+From fae7cf2b129cf3fc740305cb1fb1ae362a402c0a Mon Sep 17 00:00:00 2001
+From: xengineering <me@xengineering.eu>
+Date: Wed, 22 May 2024 20:22:10 +0200
+Subject: [PATCH] Select default storage
+
+---
+ default_config.json | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/default_config.json b/default_config.json
+index e4415f3..dd6dd5b 100644
+--- a/default_config.json
++++ b/default_config.json
+@@ -1,4 +1,4 @@
+ {
+ 	"http_address": "127.0.0.1:8080",
+-	"storage_file_path": "storage"
++	"storage_file_path": "/var/lib/ceres"
+ }
+-- 
+2.45.1
+
diff --git a/ceres/PKGBUILD b/ceres/PKGBUILD
index 9a80003..02dab78 100644
--- a/ceres/PKGBUILD
+++ b/ceres/PKGBUILD
@@ -1,32 +1,58 @@
 # Maintainer: xengineering <me@xengineering.eu>
 pkgname=ceres
-pkgver=0.3.1
+pkgver=0.4.0
 pkgrel=1
 pkgdesc="Recipe server for your favorite dishes"
 arch=('x86_64' 'aarch64')
-url="https://xengineering.eu/git/ceres"
+url='https://xengineering.eu/git/ceres'
 license=('AGPL')
 makedepends=('coreutils' 'git' 'make' 'go')
 backup=('etc/ceres/config.json')
-source=("https://cgit.xengineering.eu/ceres/snapshot/ceres-${pkgver}.tar.zst"
+source=("git+https://cgit.xengineering.eu/ceres#tag=$pkgver?signed"
         'ceres.service'
         'sysuser.conf'
-        'ceres.tmpfile.d')
-sha256sums=('d558212251c077b3420c09c6e7c57e9dff5c85173f4d9d4b00f411fa19c7005e'
-            'da4b6201e9bcf2cc3ae94b274338b58abc5368d77e0df1ece578644a415d8ace'
+        'ceres.tmpfile.d'
+        '0001-Disable-logging-time-stamps.patch'
+        '0002-Select-default-storage.patch')
+sha256sums=('SKIP'
+            '7b9284940f307a63547d2346e53431842d8bb3e37eb87a422948fdddd8e09a12'
             'a8c7c3d6af65bd7255b0f693430c6ba53d646123feebec9a1e37f8723c21942b'
-            '5a953a802b1478dd7f7e32dbd8ac8d97946bbef0579e3cce4b87e32151855e51')
+            '5a953a802b1478dd7f7e32dbd8ac8d97946bbef0579e3cce4b87e32151855e51'
+            'ee87321e1be9aa8c6fbc1f8dc0d704d6ad7de72d28d8de35d360165d9cbcd62f'
+            'b58224a1fa194320e7da97a8d04f14eac2d67e48314f8ccc9ddff250aa2f40c5')
+
+validpgpkeys=(
+	'A13B258878787F943F6C68F00FD1F84233FA8900'  # xengineering <me@xengineering.eu>
+)
+
+prepare() {
+	patch "${srcdir}/${pkgname}/main.go" 0001-Disable-logging-time-stamps.patch
+	patch "${srcdir}/${pkgname}/default_config.json" 0002-Select-default-storage.patch
+	cd "${srcdir}/${pkgname}"
+	git submodule init
+	git submodule update
+}
 
 build() {
-	cd "$pkgname-$pkgver"
-	make
+	cd "${srcdir}/${pkgname}"
+	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=readonly -modcacherw"
+	go build -ldflags "-X main.version=${pkgver}" -o "build/${pkgname}" xengineering.eu/ceres
+}
+
+check() {
+	cd "${srcdir}/${pkgname}"
+	make tests
 }
 
 package() {
-	cd "$pkgname-$pkgver"
-	make DESTDIR="$pkgdir" install
-	rm -rf "${pkgdir}/var"
-	install -Dm644 "${srcdir}"/ceres.service "${pkgdir}"/usr/lib/systemd/system/ceres.service
-	install -Dm644 "${srcdir}"/sysuser.conf "${pkgdir}"/usr/lib/sysusers.d/ceres.conf
-	install -Dm644 "${srcdir}"/ceres.tmpfile.d "${pkgdir}"/usr/lib/tmpfiles.d/ceres.conf
+	cd "${srcdir}/${pkgname}"
+	install -D -m 755 "${srcdir}/${pkgname}/build/ceres" "${pkgdir}/usr/bin/ceres"
+	install -D -m 644 "${srcdir}/${pkgname}/default_config.json" "${pkgdir}/etc/ceres/config.json"
+	install -D -m 644 "${srcdir}/ceres.service" "${pkgdir}/usr/lib/systemd/system/ceres.service"
+	install -D -m 644 "${srcdir}/sysuser.conf" "${pkgdir}/usr/lib/sysusers.d/ceres.conf"
+	install -D -m 644 "${srcdir}/ceres.tmpfile.d" "${pkgdir}/usr/lib/tmpfiles.d/ceres.conf"
 }
diff --git a/ceres/ceres.service b/ceres/ceres.service
index 49fbe8b..c4fdb9f 100644
--- a/ceres/ceres.service
+++ b/ceres/ceres.service
@@ -5,7 +5,7 @@ After=network.target
 [Service]
 User=ceres
 Group=ceres
-ExecStart=/usr/bin/ceres
+ExecStart=/usr/bin/ceres -c /etc/ceres/config.json
 
 [Install]
 WantedBy=multi-user.target
-- 
cgit v1.2.3-70-g09d2