-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·61 lines (52 loc) · 1.84 KB
/
export.sh
File metadata and controls
executable file
·61 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env zsh
set -euo pipefail
info() { printf ' \033[35m***\033[0m %s\n' "$1"; }
warn() { printf ' \033[33m!!!\033[0m %s\n' "$1"; }
ok() { printf ' \033[32m ✓ \033[0m %s\n' "$1"; }
prompt() { printf ' \033[35m***\033[0m %s ' "$1"; } # no newline; user input follows on the same line
default_output="$HOME/Desktop/dotfiles-export-$(date +%Y%m%d).tgz.gpg"
prompt "Output file [$default_output]:"
read -r output_path
output_path="${output_path:-$default_output}"
tmp=$(mktemp -d)
trap "rm -rf $tmp" EXIT
# SSH private keys
info 'Collecting SSH private keys...'
mkdir -p "$tmp/ssh"
for key in ~/.ssh/id_*(N); do
[[ "$key" == *.pub ]] && continue
cp "$key" "$tmp/ssh/"
ok "$(basename "$key")"
done
# Local SSH config.d fragments (skip symlinks — those are versioned in dotfiles)
info 'Collecting local SSH config fragments...'
mkdir -p "$tmp/ssh/config.d"
for fragment in ~/.ssh/config.d/*(N); do
[[ -L "$fragment" ]] && continue
cp "$fragment" "$tmp/ssh/config.d/"
ok "config.d/$(basename "$fragment")"
done
# GPG private keys
info 'Collecting GPG keys...'
mkdir -p "$tmp/gpg"
if gpg --list-secret-keys --keyid-format LONG 2>/dev/null | grep -q '^sec'; then
gpg --export-secret-keys --armor > "$tmp/gpg/private-keys.asc"
gpg --export-ownertrust > "$tmp/gpg/owner-trust.txt"
ok 'GPG keys exported'
else
warn 'No GPG secret keys found, skipping'
fi
# ~/.secrets
info 'Collecting ~/.secrets...'
if [[ -f ~/.secrets && -s ~/.secrets ]]; then
cp ~/.secrets "$tmp/secrets"
ok '~/.secrets'
else
warn '~/.secrets is empty or missing, skipping'
fi
# Encrypt
info 'Creating encrypted bundle (you will be prompted for a passphrase)...'
tar -czf - -C "$tmp" . | gpg --symmetric --armor --output "$output_path"
ok "Bundle saved to $output_path"
echo ''
info "Transfer $output_path to your new machine and run import.sh"