Commit 0384861
xxwhirlpool
·
2026-03-29 14:15:23 -0400 EDT
parent 7e16a33
add `keyback`
1 files changed,
+39,
-0
+39,
-0
| ... | ... | @@ -0,0 +1,39 @@ | |
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | help_msg() { | |
| 4 | + | echo "Usage: keyback [OPTIONS]" | |
| 5 | + | echo "Options: --pgp | --ssh | --sync" | |
| 6 | + | } | |
| 7 | + | ||
| 8 | + | if [[ $(hostname) == "mariposa" ]]; then # laptop | |
| 9 | + | input_dir=".mariposa_key_backup" | |
| 10 | + | elif [[ $(hostname) == "kwangya" ]]; then # PC | |
| 11 | + | input_dir=".kwangya_key_backup" | |
| 12 | + | fi | |
| 13 | + | ||
| 14 | + | target_dir="$HOME/$input_dir" | |
| 15 | + | ||
| 16 | + | make_target_dir() { | |
| 17 | + | [[ ! -d "$target_dir" ]]; mkdir "$target_dir" || echo "directory already exists, continuing..." | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | backup_pgp_all() { | |
| 21 | + | make_target_dir | |
| 22 | + | gpg --export-secret-keys --armor --output "$target_dir"/gpg_all.asc | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | backup_ssh_all() { | |
| 26 | + | make_target_dir | |
| 27 | + | tar cvzf "$target_dir"/ssh_all.tar.gz "$HOME"/.ssh | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | sync_backups() { | |
| 31 | + | rsync -avzp "$target_dir" athena:/home/kat/backups/keys || echo "sync failed" && exit 1 | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | case "$1" in | |
| 35 | + | "") help_msg;; | |
| 36 | + | "--pgp") backup_pgp_all && sync_backups;; | |
| 37 | + | "--ssh") backup_ssh_all && sync_backups;; | |
| 38 | + | "--sync") sync_backups;; | |
| 39 | + | esac |