install.fairie/home/private_dot_ssh/run_onchanges_after_decrypt-ssh-keys.tmpl

26 lines
1 KiB
Cheetah
Raw Normal View History

2023-03-19 23:38:30 -07:00
{{- if (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) -}}
#!/usr/bin/env bash
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
logg info 'Decrypting SSH keys stored in the `home/.chezmoitemplates/ssh` folder of the Install Doctor repo / fork.'
2023-03-20 02:47:35 -07:00
find "{{ .chezmoi.sourceDir }}/.chezmoitemplates/ssh" -type f | while read SSH_FILE; do
2023-03-20 02:32:51 -07:00
### Decrypt SSH file with Chezmoi
2023-03-19 23:38:30 -07:00
logg info 'Decrypting the $(basename "$SSH_FILE") encrypted SSH file'
chezmoi decrypt "$SSH_FILE" > "$HOME/.ssh/$(basename "$SSH_FILE")" || EXIT_CODE=$?
2023-03-20 02:32:51 -07:00
### Handle failed decryption with warning log message
2023-03-19 23:38:30 -07:00
if [ -n "$EXIT_CODE" ]; then
logg warn "Unable to decrypt the file stored in $SSH_FILE"
fi
2023-03-20 02:32:51 -07:00
### Apply appropriate permission to decrypted ~/.ssh file
if [ -f "$HOME/.ssh/$(basename "$SSH_FILE")" ]; then
logg info "Applying appropriate permissions on $HOME/.ssh/$(basename "$SSH_FILE")"
chmod 600 "$HOME/.ssh/$(basename "$SSH_FILE")"
fi
2023-03-20 02:40:26 -07:00
done
2023-03-19 23:38:30 -07:00
{{ end -}}