From e8c18c99049d3a245626463b4e7c9aad943ca2bd Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Fri, 25 Nov 2022 05:05:02 +0000 Subject: [PATCH] Update dotfiles/.local/share/chezmoi/home/dot_ssh/create_encrypted_private_readonly_private_id_rsa.tmpl, dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys.tmpl --- ...e_encrypted_private_readonly_private_id_rsa.tmpl | 6 ++++-- ...> run_onchanges_after_generate-public-keys.tmpl} | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) rename dotfiles/.local/share/chezmoi/home/dot_ssh/{run_onchanges_after_generate-public-keys => run_onchanges_after_generate-public-keys.tmpl} (52%) diff --git a/dotfiles/.local/share/chezmoi/home/dot_ssh/create_encrypted_private_readonly_private_id_rsa.tmpl b/dotfiles/.local/share/chezmoi/home/dot_ssh/create_encrypted_private_readonly_private_id_rsa.tmpl index 46e895af..e6793853 100644 --- a/dotfiles/.local/share/chezmoi/home/dot_ssh/create_encrypted_private_readonly_private_id_rsa.tmpl +++ b/dotfiles/.local/share/chezmoi/home/dot_ssh/create_encrypted_private_readonly_private_id_rsa.tmpl @@ -1,5 +1,7 @@ -{{- if ( bitwarden "item" "dev.betelgeuse.ssh.personal.id_rsa.private" ).notes -}} -{{- ( bitwarden "item" "dev.betelgeuse.ssh.personal.id_rsa.private" ).notes -}} +{{- $bwAuthenticated = eq (fromJson (output "bw" "status")).status "authenticated" }} +{{- if $bwAuthenticated -}} +{{- writeToStdout "BitWarden is authenticated!" -}} +{{- (bitwarden "item" "dev.betelgeuse.ssh.personal.id_rsa.private").notes -}} {{- else -}} {{- $sshLocation = (joinPath .chezmoi.homeDir ".ssh" "id_rsa") -}} {{- if not (stat $sshLocation) -}} diff --git a/dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys b/dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys.tmpl similarity index 52% rename from dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys rename to dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys.tmpl index c6f0df22..860f3792 100644 --- a/dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys +++ b/dotfiles/.local/share/chezmoi/home/dot_ssh/run_onchanges_after_generate-public-keys.tmpl @@ -1,12 +1,15 @@ #!/usr/bin/env bash -{{ $sshFiles = (output "find" "$HOME/.ssh" "-type" "f") }} -{{ range $sshFile := $sshFiles }} -# .ssh hash: {{ include ".ssh" | sha256sum }} -# {{ $sshFile }} hash: {{ include $sshFile | sha256sum }} -{{ end }} +{{ $sshFiles := (output "find" (joinPath .chezmoi.homeDir ".ssh") "-type" "f") -}} +{{- range $sshFile := splitList "\n" $sshFiles -}} +{{- if ne $sshFile "" -}} +# {{ $sshFile }} hash: {{ $sshFile | sha256sum }} +{{ end -}} +{{- end }} +source "$HOME/.config/shell/exports" logg 'Ensuring RSA public keys are present' + find "$HOME/.ssh" -type f | while read FILE; do if [ ! -f "${FILE}" ] && cat "$FILE" | grep 'BEGIN RSA PRIVATE KEY'; then logg 'Generating missing public key for `'"$FILE"'`'