From b50ee0cf139e85c7c003234689e520789abf5b81 Mon Sep 17 00:00:00 2001 From: tuxwarrior Date: Mon, 6 May 2024 07:06:06 -0500 Subject: [PATCH] + deploySshKeys.sh --- dots/bin/deploySshKeys.sh | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 dots/bin/deploySshKeys.sh diff --git a/dots/bin/deploySshKeys.sh b/dots/bin/deploySshKeys.sh new file mode 100755 index 0000000..ae52fc6 --- /dev/null +++ b/dots/bin/deploySshKeys.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# klevstul :: 24.04 + +this_file_name=`basename "$0"` +echo "$this_file_name" + +# location of ssh keys +syncdir_env_var=SYNCDIR_${HOSTNAME} +src_ssh_dir=${!syncdir_env_var}/secrets/.ssh +trg_ssh_dir=~/.ssh + +echo "\$SYNCDIR_${HOSTNAME}=${!syncdir_env_var}" +echo "src_ssh_dir: ${src_ssh_dir}" + +if ! [[ -d ${src_ssh_dir} ]]; then + echo "error: non-existing directory '${src_ssh_dir}'" >&2; exit 1 +fi + +if ! [[ -d "$trg_ssh_dir" ]]; then + echo "creating non-existing target dir '${trg_ssh_dir}'." + mkdir -p ${trg_ssh_dir} +fi + +if ! [[ -f ${trg_ssh_dir}/id_rsa.pub ]]; then + echo "deploy id_rsa.pub" + cp ${src_ssh_dir}/id_rsa.pub ${trg_ssh_dir} +else + echo "id_rsa.pub already exist in ${trg_ssh_dir}" +fi + +if ! [[ -f ${trg_ssh_dir}/id_rsa.gpg ]]; then + echo "deploy id_rsa.gpg" + cp ${src_ssh_dir}/id_rsa.gpg ${trg_ssh_dir} +else + echo "id_rsa.gpg already exist in ${trg_ssh_dir}" +fi + +echo "do you want to decrypt id_rsa.gpg? (y/n)" +read user_input + +if [[ ${user_input} == "y" ]]; then + echo "yes" + echo "please, remember the hint: poq.l2" + gpg -d ${trg_ssh_dir}/id_rsa.gpg > ${trg_ssh_dir}/id_rsa +else + echo "no worries. you can manually decrypt the file, if needed:" + echo "gpg -d id_rsa.gpg > id_rsa" +fi