Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·118 lines (103 loc) · 4.24 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·118 lines (103 loc) · 4.24 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
#!/usr/bin/env bash
# install.sh - One-liner bootstrap for a fresh Mac.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/haacked/dotfiles/main/install.sh | bash
#
# Or from another branch:
# curl -fsSL https://raw.githubusercontent.com/haacked/dotfiles/main/install.sh | BRANCH=somebranch bash
#
# This installs the Xcode Command Line Tools (for git), clones the dotfiles to
# ~/.dotfiles, points the origin remote at SSH, and runs script/bootstrap.
set -euo pipefail
REPO_HTTPS="https://github.com/haacked/dotfiles.git"
REPO_SSH="git@github.com:haacked/dotfiles.git"
BRANCH="${BRANCH:-main}"
DOTFILES="$HOME/.dotfiles"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}⚠${NC} $1"; }
error() { echo -e "${RED}✗${NC} $1"; }
ensure_xcode_clt() {
if xcode-select -p &>/dev/null; then
info "Xcode Command Line Tools already installed"
return
fi
info "Installing Xcode Command Line Tools (provides git)…"
warn "Accept the macOS dialog that appears, then wait for it to finish."
xcode-select --install &>/dev/null || true
# Wait for the GUI installer to complete, but don't hang forever if the user
# cancels the dialog or it never starts. 30 minutes covers a slow download.
local waited=0 timeout=1800
until xcode-select -p &>/dev/null; do
if [ "$waited" -ge "$timeout" ]; then
error "Timed out waiting for Xcode Command Line Tools."
error "Run 'xcode-select --install', let it finish, then re-run this installer."
exit 1
fi
sleep 5
waited=$((waited + 5))
done
info "Xcode Command Line Tools installed"
}
clone_or_update() {
if [ -d "$DOTFILES/.git" ]; then
info "Existing dotfiles found at $DOTFILES, updating…"
# Fetch over HTTPS so updates work even before an SSH key is set up (a
# prior run may have already pointed origin at SSH).
git -C "$DOTFILES" remote set-url origin "$REPO_HTTPS"
git -C "$DOTFILES" fetch origin "$BRANCH"
git -C "$DOTFILES" checkout "$BRANCH"
git -C "$DOTFILES" pull --ff-only origin "$BRANCH"
elif [ -e "$DOTFILES" ]; then
error "$DOTFILES exists but is not a git repo. Move it aside and re-run."
exit 1
else
info "Cloning dotfiles to $DOTFILES (branch: $BRANCH)…"
git clone --branch "$BRANCH" "$REPO_HTTPS" "$DOTFILES"
fi
# Prefer SSH for future pushes (keys may not exist yet; that's fine).
git -C "$DOTFILES" remote set-url origin "$REPO_SSH"
}
main() {
echo ""
echo "═══════════════════════════════════════════════════════"
echo " haacked dotfiles installer"
echo "═══════════════════════════════════════════════════════"
echo ""
if [ "$(uname -s)" != "Darwin" ]; then
error "This installer only supports macOS."
exit 1
fi
ensure_xcode_clt
clone_or_update
info "Running script/bootstrap…"
cd "$DOTFILES"
# bootstrap prompts (git name/email, link conflicts), so it needs a real
# terminal on stdin. When piped via `curl | bash`, stdin is the pipe, so read
# from /dev/tty instead — but only if a controlling terminal actually exists
# (it won't under CI or headless automation), otherwise fail clearly.
if [ -t 0 ]; then
script/bootstrap
elif [ -r /dev/tty ]; then
script/bootstrap < /dev/tty
else
error "No controlling terminal available for bootstrap prompts."
error "Clone the repo and run 'script/bootstrap' from an interactive shell instead."
exit 1
fi
echo ""
echo "═══════════════════════════════════════════════════════"
info "Installation complete!"
echo ""
echo "Next steps:"
echo " • Add an SSH key to GitHub so pushes work (origin is set to SSH)."
echo " • Restart your shell or run: exec zsh"
echo " • Re-run anytime with: dot"
echo "═══════════════════════════════════════════════════════"
echo ""
}
main "$@"