dots


dots / config / .local / bin
xxwhirlpool  ·  2026-03-29

keyback

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