forked from tutumcloud/dockup
-
Notifications
You must be signed in to change notification settings - Fork 9
/
gen-test-key.sh
executable file
·54 lines (44 loc) · 1.53 KB
/
gen-test-key.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# build dockup image (because we need to use gpg 1)
docker build -t wetransform/dockup:local .
key_name="test-key"
key_passphrase="dockup-test"
[ -f "${key_name}.pub" ] && rm ${key_name}.pub
[ -f "${key_name}.sec" ] && rm ${key_name}.sec
# create configuration for batch key creation
# see https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html
cat > tmpGenKey.txt <<EOF
%echo Generating a key...
Key-Type: RSA
Key-Length: 1024
Subkey-Type: RSA
Subkey-Length: 1024
Name-Real: ${key_name}
Expire-Date: 0
Passphrase: ${key_passphrase}
%pubring /mnt/parent/${key_name}.pub
%secring /mnt/parent/${key_name}.sec
# Perform the key generation
%commit
%echo done
EOF
# generate key with Docker
docker run --rm \
-v $(pwd)/:/mnt/parent \
--name dockup-gen-key wetransform/dockup:local \
gpg --batch --gen-key /mnt/parent/tmpGenKey.txt
rc=$?; if [ $rc -ne 0 ]; then echo "ERROR: Key generation failed"; exit $rc; fi
# Some not used instructions:
#
# Name-Comment: with stupid passphrase
# Name-Email: [email protected]
#
# Helpful article on file encryption and handling keys with GPG:
# http://serverfault.com/a/489148/238696
rc=$?; if [ $rc -ne 0 ]; then echo "ERROR: Key generation failed"; exit $rc; fi
rm tmpGenKey.txt
docker run --rm \
-v $(pwd)/:/mnt/parent \
--name dockup-list-key wetransform/dockup:local \
gpg --no-default-keyring --secret-keyring "/mnt/parent/$key_name.sec" \
--keyring "/mnt/parent/$key_name.pub" --list-secret-keys