From 725ad632103977854df765c6521e0e2d52397d94 Mon Sep 17 00:00:00 2001
From: tobtoht <tob@featherwallet.org>
Date: Mon, 4 Nov 2024 18:19:56 +0100
Subject: [PATCH] build: add make convenience wrapper for guix scripts

---
 Makefile                   | 19 +++++++++++++++
 contrib/guix/guix-attest   | 47 +++++++++++++++++++++++++++++++++++---
 contrib/guix/guix-codesign | 20 +++++++++++++---
 contrib/guix/guix-verify   | 16 ++++++++++---
 4 files changed, 93 insertions(+), 9 deletions(-)
 create mode 100644 Makefile

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..eee37bb
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+build:
+	@./contrib/guix/guix-build
+
+codesign:
+	@./contrib/guix/guix-codesign
+
+attest:
+	@./contrib/guix/guix-attest
+
+verify:
+	@./contrib/guix/guix-attest
+
+clean:
+	@./contrib/guix/guix-clean
+
+DEFAULT_GOAL := default
+default: build
+
+.PHONY: default build attest verify clean
diff --git a/contrib/guix/guix-attest b/contrib/guix/guix-attest
index e9a0b81..fa2fbe1 100755
--- a/contrib/guix/guix-attest
+++ b/contrib/guix/guix-attest
@@ -66,9 +66,50 @@ Example w/o signing, just creating SHA256SUMS:
 EOF
 }
 
-if [ -z "$GUIX_SIGS_REPO" ] || [ -z "$SIGNER" ]; then
-    cmd_usage
-    exit 1
+if [ -z "${GUIX_SIGS_REPO}" ]; then
+    echo "[HINT] Fork and clone the feather-sigs repo, if you haven't already:"
+    echo "https://github.com/feather-wallet/feather-sigs"
+    echo ""
+
+    printf "Enter path to 'feather-sigs' repo: "
+    read -r repo
+
+    if [ ! -d "${repo}" ]; then
+        echo "ERR: directory does not exist"
+        exit 1
+    fi
+
+    export GUIX_SIGS_REPO="$repo"
+    wizard=1
+fi
+
+if [ -z "${SIGNER}" ]; then
+    printf "Enter your GitHub username: "
+    read -r signer
+
+    if [ -z "$signer" ]; then
+        echo "ERR: signer name can't be empty"
+        exit 1
+    fi
+
+    echo ""
+    echo "[HINT] To find your GPG fingerprint use:"
+    echo "gpg --list-secret-keys --keyid-format=long"
+    echo "It should look like: E87BD921CDD885C9D78A38C5E45B10DD027D2472"
+    echo ""
+
+    printf "Enter fingerprint of your GPG key: "
+    read -r fingerprint
+
+    export SIGNER="${fingerprint}=${signer}"
+    wizard=1
+fi
+
+if [ -n "$wizard" ]; then
+    echo ""
+    echo "Next time, invoke this command as:"
+    echo "env GUIX_SIGS_REPO=${GUIX_SIGS_REPO} SIGNER=${SIGNER} make attest"
+    echo ""
 fi
 
 ################
diff --git a/contrib/guix/guix-codesign b/contrib/guix/guix-codesign
index ad08df0..4afd5b0 100755
--- a/contrib/guix/guix-codesign
+++ b/contrib/guix/guix-codesign
@@ -35,8 +35,22 @@ EOF
 }
 
 if [ -z "$GUIX_SIGS_REPO" ]; then
-    cmd_usage
-    exit 1
+    echo "[HINT] Fork and clone the feather-sigs repo:"
+    echo "https://github.com/feather-wallet/feather-sigs"
+    echo ""
+
+    printf "Enter path to 'feather-sigs' repo: "
+    read -r GUIX_SIGS_REPO
+
+    if [ ! -d "${GUIX_SIGS_REPO}" ]; then
+        echo "Directory does not exist"
+        exit 1
+    fi
+
+    echo ""
+    echo "Next time, invoke this command as:"
+    echo "env GUIX_SIGS_REPO=${GUIX_SIGS_REPO} make codesign"
+    echo ""
 fi
 
 ################
@@ -73,7 +87,7 @@ fi
 
 if ! git -C "$GUIX_SIGS_REPO" diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then
     cat << EOF
-ERR: The DETACHED CODESIGNATURE git worktree is dirty, which may lead to broken builds.
+ERR: The FEATHER SIGS git worktree is dirty, which may lead to broken builds.
 
      Aborting...
 
diff --git a/contrib/guix/guix-verify b/contrib/guix/guix-verify
index 02fc6f2..440228a 100755
--- a/contrib/guix/guix-verify
+++ b/contrib/guix/guix-verify
@@ -37,9 +37,19 @@ Example overriding signer's manifest to use as base
 EOF
 }
 
-if [ -z "$GUIX_SIGS_REPO" ]; then
-    cmd_usage
-    exit 1
+if [ -z "${GUIX_SIGS_REPO}" ]; then
+    printf "Enter path to 'feather-sigs' repo: "
+    read -r GUIX_SIGS_REPO
+
+    if [ ! -d "${GUIX_SIGS_REPO}" ]; then
+        echo "Directory does not exist"
+        exit 1
+    fi
+
+    echo ""
+    echo "Next time, invoke this command as:"
+    echo "env GUIX_SIGS_REPO=${GUIX_SIGS_REPO} make verify"
+    echo ""
 fi
 
 ################