-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles.sh
More file actions
executable file
·74 lines (59 loc) · 1.69 KB
/
Copy pathdotfiles.sh
File metadata and controls
executable file
·74 lines (59 loc) · 1.69 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
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# This script can be used to install my dotfiles from scratch, or to update existing ones.
# Requires git to be installed.
set -eu
REPO="https://github.com/meemo/dotfiles"
DOTFILES_DIR="$HOME/dotfiles"
BACKUP_DIR="/tmp/dotfiles_backup_$(date +%Y%m%d_%H%M%S)"
safe_copy() {
src="$1"
dest="$2"
# Skip if source doesn't exist
[ ! -e "$src" ] && return
# Create backup if destination exists
if [ -e "$dest" ]; then
mkdir -p "$BACKUP_DIR"
mv "$dest" "$BACKUP_DIR/$(basename "$dest")"
fi
cp -R "$src" "$dest"
}
cleanup() {
if [ -d "$DOTFILES_DIR.tmp" ]; then
rm -rf "$DOTFILES_DIR.tmp"
fi
}
trap cleanup EXIT
main() {
if ! command -v git >/dev/null 2>&1; then
echo "Error: git is required but not installed"
exit 1
fi
if [ -d "$DOTFILES_DIR" ]; then
if [ -d "$DOTFILES_DIR/.git" ]; then
echo "Updating existing dotfiles..."
cd "$DOTFILES_DIR"
git pull
else
echo "Found existing dotfiles directory without git"
mv "$DOTFILES_DIR" "$DOTFILES_DIR.old"
git clone "$REPO" "$DOTFILES_DIR"
fi
else
echo "Cloning dotfiles repository..."
git clone "$REPO" "$DOTFILES_DIR"
fi
echo "Installing dotfiles..."
cd "$DOTFILES_DIR"
for file in .??*; do
# Skip git files
case "$file" in
.git|.gitignore|.gitmodules) continue ;;
esac
safe_copy "$file" "$HOME/$file"
done
echo "Dotfiles installation complete"
if [ -d "$BACKUP_DIR" ]; then
echo "Backup of existing files created in: $BACKUP_DIR"
fi
}
main