From 717f2bdc06c241ee0fb65c1d6802fe6ba5ce87d5 Mon Sep 17 00:00:00 2001 From: Patrick Kissling Date: Thu, 26 Oct 2023 15:21:11 +0200 Subject: [PATCH] Install private SSH and GPG key from 1Password --- Makefile | 2 +- gpg/install.sh | 10 ++++++++++ ssh/install.sh | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1bf4b7c..eaa2ebb 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ git: bootstrap @chmod +x git/install.sh @./git/install.sh -gpg: bootstrap +gpg: bootstrap brew @chmod +x gpg/install.sh @./gpg/install.sh diff --git a/gpg/install.sh b/gpg/install.sh index dcf4ae2..cddde67 100755 --- a/gpg/install.sh +++ b/gpg/install.sh @@ -11,3 +11,13 @@ ln -sfv "${HOME}"/dotfiles/gpg/gpg-agent_"${USAGE}".conf "${HOME}"/.gnupg/gpg-ag # import public gpg keys gpg --import ~/dotfiles/gpg/private.asc gpg --import ~/dotfiles/gpg/work.asc + +# add private gpg key from 1password, if not exist +if [ -z "$(gpg --list-secret-keys)" ]; then + if [ "${USAGE}" = "work" ]; then + ONE_PASSWORD_DOCUMENT_ID="qoudpafw75h5i3lw7nyt67ewmq" + else + ONE_PASSWORD_DOCUMENT_ID="n5zwvjshndohrik5k7jrjktfxe" + fi + gpg --import <(op document get "${ONE_PASSWORD_DOCUMENT_ID}") +fi diff --git a/ssh/install.sh b/ssh/install.sh index 0e492a0..19a4c2a 100755 --- a/ssh/install.sh +++ b/ssh/install.sh @@ -15,3 +15,16 @@ ln -sfv "${HOME}"/.ssh/"${USAGE}".priv "${HOME}"/.ssh/id_rsa # create symlinks for config file ln -sfv "${HOME}"/dotfiles/ssh/config "${HOME}"/.ssh + +# add private ssh key from 1password, if not exist +if [ ! -f "${HOME}"/.ssh/"${USAGE}.priv" ]; then + if [ "${USAGE}" = "work" ]; then + ONE_PASSWORD_VAULT="Azena" + ONE_PASSWORD_KEY_ID="2vgwjhx6xauti4mpxiltsalzyy" + else + ONE_PASSWORD_VAULT="Personal" + ONE_PASSWORD_KEY_ID="2uc6ialn2lqxqlpitlil4howha" + fi + op read op://"${ONE_PASSWORD_VAULT}"/"${ONE_PASSWORD_KEY_ID}"/'private key' > "${HOME}"/.ssh/"${USAGE}.priv" + chmod 600 ~/.ssh/id_rsa +fi