summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2016-09-24 12:14:27 -0300
committerSilvio Rhatto <rhatto@riseup.net>2016-09-24 12:14:27 -0300
commit07bb3f7af94c114a91213a9cf05194f234109b54 (patch)
tree62889722084915f12007e3ff09f2715a66a04c4b /share
parent851abf3d77640fb1ba279e60dec3101efaa97ef4 (diff)
downloadhydra-07bb3f7af94c114a91213a9cf05194f234109b54.tar.gz
hydra-07bb3f7af94c114a91213a9cf05194f234109b54.tar.bz2
Newkeys: fix logic
Diffstat (limited to 'share')
-rwxr-xr-xshare/hydra/newkeys58
1 files changed, 38 insertions, 20 deletions
diff --git a/share/hydra/newkeys b/share/hydra/newkeys
index baffe28..84180ba 100755
--- a/share/hydra/newkeys
+++ b/share/hydra/newkeys
@@ -19,7 +19,17 @@
function hydra_newkeys {
# Generates ssh and gpg keys for new or existing nodes
# GPG keys should be manually imported in the nodes
- if [ ! -z "$1" ]; then
+ local node
+ local which
+
+ if [ -z "$1" ]; then
+ which="new"
+ else
+ which="$1"
+ fi
+
+ if [ ! -z "$2" ]; then
+ shift
NODES="$*"
else
NODES="`hydra $HYDRA nodes`"
@@ -27,19 +37,24 @@ function hydra_newkeys {
for node in $NODES; do
node="`hydra_get_fqdn_from_nodename $node`"
- sshkey="$HYDRA_FOLDER/keyring/keys/nodes/$fqdn/ssh/id_rsa.asc"
- gpgkey="$HYDRA_FOLDER/keyring/keys/nodes/$fqdn/gpg/key.asc"
- if [ "$1" == "all" ]; then
- hydra_genpairs
- elif [ "$1" == "all-ssh" ]; then
- hydra_genpairs ssh
- elif [ "$1" == "all-pgp" ]; then
- hydra_genpairs pgp
- elif [ ! -z "$1" ] && [ "$fqdn" == "$1" ]; then
- hydra_genpairs $2
- exit $?
- elif [ ! -e "$sshkey" ] || [ ! -e "$gpgkey" ]; then
- hydra_genpairs
+ sshkey="$HYDRA_FOLDER/keyring/keys/nodes/$node/ssh/id_rsa.asc"
+ gpgkey="$HYDRA_FOLDER/keyring/keys/nodes/$node/gpg/key.asc"
+
+ if [ "$which" == "all" ]; then
+ hydra_genpairs ssh $node
+ hydra_genpairs openpgp $node
+ elif [ "$which" == "new" ]; then
+ if [ ! -e "$sshkey" ]; then
+ hydra_genpairs ssh $node
+ fi
+
+ if [ ! -e "$gpgkey" ]; then
+ hydra_genpairs openpgp $node
+ fi
+ elif [ "$which" == "ssh" ]; then
+ hydra_genpairs ssh $node
+ elif [ "$which" == "openpgp" ]; then
+ hydra_genpairs openpgp $node
fi
done
}
@@ -47,16 +62,19 @@ function hydra_newkeys {
function hydra_genpairs {
BASEDIR="/tmp"
- if [ "$1" != "pgp" ]; then
- keyringer $HYDRA genpair ssh nodes/$fqdn/ssh/id_rsa $fqdn
- fi
+ local which="$1"
+ local node="$2"
- if [ "$1" != "ssh" ]; then
- keyringer $HYDRA genpair gpg nodes/$fqdn/gpg/key $fqdn
+ if [ "$which" == "openpgp" ]; then
+ keyringer $HYDRA genpair gpg nodes/$node/gpg/key $node
+ elif [ "$which" == "ssh" ]; then
+ keyringer $HYDRA genpair ssh nodes/$node/ssh/id_rsa $node
+ else
+ return
fi
hydra_set_tmpfile genpair
- echo "Importing keys for $fqdn" > $TMPWORK
+ echo "Importing $which keys for $node" > $TMPWORK
keyringer $HYDRA git commit -F $TMPWORK
keyringer $HYDRA git push