-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·223 lines (195 loc) · 6.34 KB
/
bootstrap.sh
File metadata and controls
executable file
·223 lines (195 loc) · 6.34 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env bash
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
DOTFILES_REPO="git@github.com:arjenbloemsma/dotfiles.git"
DOTFILES_DIR="$HOME/dotfiles"
# Detect OS and package manager
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ -f /etc/os-release ]]; then
. /etc/os-release
echo "${ID,,}"
else
echo "unknown"
fi
}
# Install prerequisites based on OS
install_prerequisites() {
local os=$(detect_os)
echo "Detected OS: $os"
echo ""
echo "Installing prerequisites..."
case "$os" in
macos)
if ! command -v brew >/dev/null 2>&1; then
echo -e "${YELLOW}→${NC} Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install git stow
;;
ubuntu|debian)
# Install build essentials and curl for Homebrew
sudo apt update
sudo apt install -y build-essential curl git
if ! command -v brew >/dev/null 2>&1; then
echo -e "${YELLOW}→${NC} Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> "$HOME/.profile"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
brew install stow
;;
arch)
# Install base packages with pacman
sudo pacman -S --noconfirm git stow base-devel
# Install yay if not present
if ! command -v yay >/dev/null 2>&1; then
echo -e "${YELLOW}→${NC} Installing yay..."
git clone https://aur.archlinux.org/yay.git /tmp/yay
cd /tmp/yay
makepkg -si --noconfirm
cd -
rm -rf /tmp/yay
echo -e "${GREEN}✓${NC} yay installed"
fi
;;
*)
echo -e "${RED}✗${NC} Unsupported OS: $os"
echo "Supported: macOS, Ubuntu, Arch"
exit 1
;;
esac
echo -e "${GREEN}✓${NC} Prerequisites installed"
echo ""
}
# Check SSH key for GitHub
check_ssh_key() {
echo "Checking SSH key..."
if [[ ! -f "$HOME/.ssh/id_ed25519" ]] && [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
echo -e "${YELLOW}⚠${NC} No SSH key found"
echo ""
echo "Generate SSH key:"
echo " ssh-keygen -t ed25519 -C \"your.email@example.com\""
echo ""
echo "Add to GitHub:"
echo " cat ~/.ssh/id_ed25519.pub"
echo " https://github.com/settings/keys"
echo ""
read -p "Press Enter after adding SSH key to GitHub..."
else
echo -e "${GREEN}✓${NC} SSH key exists"
fi
echo ""
}
# Clone or update dotfiles repo
clone_dotfiles() {
if [[ -d "$DOTFILES_DIR/.git" ]]; then
echo "Updating dotfiles..."
cd "$DOTFILES_DIR"
git pull
echo -e "${GREEN}✓${NC} Dotfiles updated"
cd -
else
echo "Cloning dotfiles..."
if ! git clone "$DOTFILES_REPO" "$DOTFILES_DIR" 2>/dev/null; then
echo -e "${RED}✗${NC} Failed to clone with SSH"
echo ""
echo "Trying HTTPS fallback..."
HTTPS_REPO="https://github.com/arjenbloemsma/dotfiles.git"
git clone "$HTTPS_REPO" "$DOTFILES_DIR"
echo -e "${YELLOW}⚠${NC} Cloned via HTTPS - configure SSH for push access later"
fi
echo -e "${GREEN}✓${NC} Dotfiles cloned"
fi
echo ""
}
# Setup zsh as default shell
setup_zsh() {
local os=$(detect_os)
echo "Setting up zsh..."
# Install zsh if not present
if ! command -v zsh >/dev/null 2>&1; then
case "$os" in
macos)
brew install zsh
;;
ubuntu|debian)
sudo apt install -y zsh
;;
arch)
yay -S --noconfirm zsh
;;
esac
echo -e "${GREEN}✓${NC} zsh installed"
else
echo -e "${GREEN}✓${NC} zsh already installed"
fi
# Set zsh as default shell if not already
if [[ "$SHELL" != *"zsh"* ]]; then
local zsh_path=$(which zsh)
echo -e "${YELLOW}→${NC} Changing default shell to zsh..."
chsh -s "$zsh_path"
echo -e "${GREEN}✓${NC} Default shell changed to zsh"
echo -e "${YELLOW}→${NC} Log out and back in for shell change to take effect"
else
echo -e "${GREEN}✓${NC} zsh already default shell"
fi
# Setup XDG_CONFIG_HOME and ZDOTDIR in .zshenv
if [[ ! -f "$HOME/.zshenv" ]]; then
echo -e "${YELLOW}→${NC} Creating ~/.zshenv..."
cat > "$HOME/.zshenv" << 'EOF'
export XDG_CONFIG_HOME="$HOME/.config"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
EOF
echo -e "${GREEN}✓${NC} XDG_CONFIG_HOME and ZDOTDIR configured"
else
# Update existing .zshenv if needed
if ! grep -q "XDG_CONFIG_HOME" "$HOME/.zshenv" 2>/dev/null; then
echo 'export XDG_CONFIG_HOME="$HOME/.config"' >> "$HOME/.zshenv"
fi
if ! grep -q "ZDOTDIR" "$HOME/.zshenv" 2>/dev/null; then
echo 'export ZDOTDIR="$XDG_CONFIG_HOME/zsh"' >> "$HOME/.zshenv"
echo -e "${GREEN}✓${NC} ZDOTDIR configured"
else
echo -e "${GREEN}✓${NC} XDG_CONFIG_HOME and ZDOTDIR already configured"
fi
fi
echo ""
}
# Run install script
run_install() {
cd "$DOTFILES_DIR"
if [[ -x "./install.sh" ]]; then
echo "Running install.sh..."
echo ""
./install.sh "$@"
else
echo -e "${YELLOW}⚠${NC} install.sh not found or not executable"
echo "Run manually: cd $DOTFILES_DIR && ./install.sh"
fi
}
# Main
main() {
echo "🚀 Dotfiles Bootstrap"
echo ""
install_prerequisites
setup_zsh
check_ssh_key
clone_dotfiles
run_install "$@"
echo ""
echo -e "${GREEN}✓${NC} Bootstrap complete!"
echo ""
echo "Next steps:"
echo " 1. Configure git: edit ~/.config/git/config.local"
echo " 2. Log out and back in for shell changes to take effect"
}
main "$@"