-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·107 lines (84 loc) · 2.51 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·107 lines (84 loc) · 2.51 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -euo pipefail
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
info() {
printf "${BLUE}==>${NC} %s\n" "$1"
}
success() {
printf "${GREEN}==>${NC} %s\n" "$1"
}
error() {
printf "${RED}==>${NC} %s\n" "$1" >&2
}
if [ "$#" -ne 0 ]; then
error 'Usage: ./install.sh'
exit 1
fi
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_ROOT="$HOME/.dotfiles-backups/$(date +%Y%m%d%H%M%S)-$$"
backup_created=0
install_homebrew() {
if command -v brew >/dev/null 2>&1; then
info "Homebrew already installed"
return
fi
info "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
local brew_path
for brew_path in /opt/homebrew/bin/brew /usr/local/bin/brew; do
if [ -x "$brew_path" ]; then
eval "$("$brew_path" shellenv)"
break
fi
done
if ! command -v brew >/dev/null 2>&1; then
error "Homebrew installation did not complete"
exit 1
fi
}
install_config() {
local repository_path="$1"
local home_path="$2"
local source_path="$DOTFILES_DIR/$repository_path"
local target_path="$HOME/$home_path"
local backup_path="$BACKUP_ROOT/$home_path"
local temporary_path
if [ ! -f "$source_path" ] || [ -L "$source_path" ]; then
error "Invalid repository file: $source_path"
exit 1
fi
if [ -e "$target_path" ] && [ ! -L "$target_path" ] && [ -f "$target_path" ] && cmp -s "$source_path" "$target_path"; then
info "Already up to date: $target_path"
return
fi
mkdir -p "$(dirname "$target_path")"
temporary_path="$(mktemp "$(dirname "$target_path")/.dotfiles-install.XXXXXX")"
cp -p "$source_path" "$temporary_path"
if [ -e "$target_path" ] || [ -L "$target_path" ]; then
mkdir -p "$(dirname "$backup_path")"
mv "$target_path" "$backup_path"
backup_created=1
fi
if ! mv -f "$temporary_path" "$target_path"; then
if [ -e "$backup_path" ] || [ -L "$backup_path" ]; then
mv "$backup_path" "$target_path"
fi
error "Could not install: $target_path"
exit 1
fi
success "Installed $target_path"
}
install_homebrew
info "Installing terminal tools and applications"
brew bundle --file="$DOTFILES_DIR/terminal/Brewfile"
install_config 'terminal/ghostty/config' '.config/ghostty/config'
install_config 'terminal/starship/starship.toml' '.config/starship.toml'
install_config 'terminal/zsh/.zshrc' '.zshrc'
install_config 'terminal/zsh/.zsh_plugins.txt' '.zsh_plugins.txt'
if [ "$backup_created" -eq 1 ]; then
info "Previous configuration saved under $BACKUP_ROOT"
fi
success "Installation complete"