summaryrefslogtreecommitdiff
path: root/bin/sign.sh
diff options
context:
space:
mode:
authorJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:08:41 -0300
committerJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:50:43 -0300
commitf9a77c5c27aede4e5978eb55d9b7af781b680a1d (patch)
treed545e325ba1ae756fc2eac66fac1001b6753c40d /bin/sign.sh
feat!: initial commit
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'bin/sign.sh')
-rwxr-xr-xbin/sign.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/bin/sign.sh b/bin/sign.sh
new file mode 100755
index 0000000..92fd207
--- /dev/null
+++ b/bin/sign.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Exit codes:
+# 0 - Success
+# 1 - Missing args
+# 2 - File not found
+
+set -e
+
+usage() {
+ echo "Usage: $(basename "$0") [-u KEY_ID] <file-to-sign>" >&2
+ echo "\t-u KEY_ID\tUse a specific GPG key to sign with (optional)" >&2
+ exit 1
+}
+
+USER_KEY=""
+
+while getopts ":u:" opt; do
+ case "$opt" in
+ u) USER_KEY="$OPTARG" ;;
+ *) usage ;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+if [ $# -ne 1 ]; then
+ echo "Error: Missing file to sign." >&2
+ usage
+fi
+
+FILE="$1"
+
+if [ ! -f "$FILE" ]; then
+ echo "Error: File '$FILE' not found." >&2
+ exit 2
+fi
+
+GPG_CMD="gpg --include-key-block --openpgp -b"
+
+if [ -n "$USER_KEY" ]; then
+ GPG_CMD="$GPG_CMD --local-user $USER_KEY"
+fi
+
+eval "$GPG_CMD \"$FILE\"" && echo "Signature created: ${FILE}.sig"