-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_local.sh
More file actions
executable file
·61 lines (49 loc) · 1.36 KB
/
Copy pathimport_local.sh
File metadata and controls
executable file
·61 lines (49 loc) · 1.36 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
#!/bin/bash
# Import local configs from another machine
# Decrypts age-encrypted archive
set -e
ARCHIVE="$1"
if [ -z "$ARCHIVE" ] || [ ! -f "$ARCHIVE" ]; then
echo "Usage: ./import_local.sh <archive.tar.gz.age>"
echo ""
echo "Example: ./import_local.sh ~/dotfiles_local_20240115_143022.tar.gz.age"
exit 1
fi
echo "=== Importing Local Configs ==="
echo ""
# Create temp directory
IMPORT_DIR=$(mktemp -d)
# Decrypt and extract
echo "Decrypting archive..."
age -d "$ARCHIVE" | tar -xzf - -C "$IMPORT_DIR"
# Files to import and their destinations
declare -A FILES=(
[".secrets"]="$HOME/.secrets"
[".zshrc.local"]="$HOME/.zshrc.local"
["config.local"]="$HOME/.ssh/config.local"
[".gitconfig.local"]="$HOME/.gitconfig.local"
)
# Ensure directories exist
mkdir -p "$HOME/.ssh"
# Import files
for name in "${!FILES[@]}"; do
src="$IMPORT_DIR/$name"
dest="${FILES[$name]}"
if [ -f "$src" ]; then
if [ -f "$dest" ]; then
echo " ! $(basename $dest) exists, backing up..."
mv "$dest" "$dest.bak.$(date +%s)"
fi
cp "$src" "$dest"
chmod 600 "$dest"
echo " ✓ $(basename $dest)"
fi
done
# Clean up
rm -rf "$IMPORT_DIR"
echo ""
echo "=== Import Complete ==="
echo ""
echo "Restart your terminal or run: source ~/.zshrc"
echo ""
echo "You can now delete the archive: rm $ARCHIVE"