-
Notifications
You must be signed in to change notification settings - Fork 2
/
sign-remote
executable file
·42 lines (35 loc) · 1.11 KB
/
sign-remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Copyright © 2009 Stefano Zacchiroli <zack@upsilon.cc>
# Copyright © 2015 Joenio Costa <joenio@colivre.coop.br>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
if [ -z "$1" ] ; then
echo "Usage: sign-remote [GPG OPTIONS] HOSTNAME:PATH"
exit 2
fi
ARGV=($@)
url=${ARGV[-1]}
unset ARGV[${#ARGV[@]}-1]
GPG_OPTIONS=${ARGV[@]}
if [ -z "$GPG_OPTIONS" ]; then
GPG_OPTIONS="--batch"
fi
host=$(echo "$url" | cut -s -f 1 -d':')
path=$(echo "$url" | cut -s -f 2 -d':')
base=$(dirname "$path")
if [ -z "$host" -o -z "$path" ] ; then
echo "Malformed remote \"URL\", must follow the \"HOSTNAME:PATH\" convention."
exit 2
fi
tmp=`mktemp`
sig="$tmp.gpg"
trap "rm -f $tmp $sig" EXIT
echo "I: retrieving file to sign from remote host ..."
scp "$url" $tmp
echo "I: signing ..."
gpg --detach-sign $GPG_OPTIONS -o $sig $tmp
echo "I: sending back signature ..."
scp $sig "$host":"$path.gpg"
echo "I: remote signing done."