summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-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"