Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·113 lines (100 loc) · 4.76 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·113 lines (100 loc) · 4.76 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
#!/usr/bin/env bash
# Bootstrap nredf dotfiles on a fresh machine (macOS, Ubuntu, Debian, …).
#
# Usage (after pushing to GitHub):
# bash <(curl -fsSL https://raw.githubusercontent.com/NemesisRE/dotfiles/main/bootstrap.sh)
#
# Or using chezmoi's own one-liner (no need to clone first):
# sh -c "$(curl -fsLS get.chezmoi.io)" -- -b ~/.local/bin init --apply NemesisRE/dotfiles
#
# The DOTFILES_REPO env var can override the GitHub user/repo slug.
set -euo pipefail
DOTFILES_REPO="${DOTFILES_REPO:-NemesisRE/dotfiles}"
step() { printf '\033[1m==> %s\033[0m\n' "$*"; }
info() { printf ' %s\n' "$*"; }
warn() { printf '\033[33m WARNING: %s\033[0m\n' "$*"; }
# sudo is only needed when not already root, and only used when it exists;
# a missing prerequisite package manager install must warn, not crash the
# whole bootstrap under `set -e`.
SUDO=""
if [[ "$(id -u)" -ne 0 ]] && command -v sudo &>/dev/null; then
SUDO="sudo"
fi
# ── Prerequisites ──────────────────────────────────────────────────────────────
if [[ "$(uname -s)" == "Darwin" ]]; then
if [[ -x /opt/homebrew/bin/brew ]] && [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then
export PATH="/opt/homebrew/bin:${PATH}"
fi
if ! xcode-select -p &>/dev/null; then
step "Installing Xcode Command Line Tools"
xcode-select --install || true
fi
if ! command -v brew &>/dev/null && [[ ! -x /opt/homebrew/bin/brew && ! -x /usr/local/bin/brew ]]; then
step "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || true
if [[ -x /opt/homebrew/bin/brew ]] && [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then
export PATH="/opt/homebrew/bin:${PATH}"
fi
fi
elif command -v apt-get &>/dev/null; then
MISSING=()
command -v curl &>/dev/null || MISSING+=(curl)
command -v git &>/dev/null || MISSING+=(git)
if [[ ${#MISSING[@]} -gt 0 ]]; then
step "Installing prerequisites: ${MISSING[*]}"
if ! { ${SUDO} apt-get update -qq && ${SUDO} apt-get install -y -qq "${MISSING[@]}"; }; then
warn "apt-get install failed; continuing without: ${MISSING[*]}"
fi
fi
elif command -v dnf &>/dev/null; then
MISSING=()
command -v curl &>/dev/null || MISSING+=(curl)
command -v git &>/dev/null || MISSING+=(git)
if [[ ${#MISSING[@]} -gt 0 ]]; then
step "Installing prerequisites: ${MISSING[*]}"
if ! ${SUDO} dnf install -y -q "${MISSING[@]}"; then
warn "dnf install failed; continuing without: ${MISSING[*]}"
fi
fi
elif command -v pacman &>/dev/null; then
MISSING=()
command -v curl &>/dev/null || MISSING+=(curl)
command -v git &>/dev/null || MISSING+=(git)
if [[ ${#MISSING[@]} -gt 0 ]]; then
step "Installing prerequisites: ${MISSING[*]}"
if ! ${SUDO} pacman -Sy --needed --noconfirm "${MISSING[@]}"; then
warn "pacman install failed; continuing without: ${MISSING[*]}"
fi
fi
fi
# ── chezmoi ────────────────────────────────────────────────────────────────────
LOCAL_BIN="${HOME}/.local/bin"
mkdir -p "${LOCAL_BIN}"
export PATH="${LOCAL_BIN}:${PATH}"
if ! command -v chezmoi &>/dev/null; then
step "Installing chezmoi"
sh -c "$(curl -fsLS get.chezmoi.io)" -- -b "${LOCAL_BIN}"
fi
# ── Apply dotfiles ─────────────────────────────────────────────────────────────
# chezmoi init --apply will:
# 1. Clone this repo to ~/.local/share/chezmoi
# 2. Run .chezmoiscripts/run_once_before_install-tools.sh (installs aqua, links sheldon via aqua)
# 3. Apply all managed dotfiles to ~/
step "Applying dotfiles (${DOTFILES_REPO})"
chezmoi init --apply "${DOTFILES_REPO}"
AQUA_BIN="${AQUA_ROOT_DIR:-${XDG_DATA_HOME:-${HOME}/.local/share}/aquaproj-aqua}/bin"
if [[ -d "${AQUA_BIN}" ]] && [[ ":$PATH:" != *":${AQUA_BIN}:"* ]]; then
export PATH="${AQUA_BIN}:${PATH}"
fi
if command -v aqua &>/dev/null; then
step "Linking aqua-managed tools"
aqua install -a -l >/dev/null 2>&1 || true
fi
# ── Done ───────────────────────────────────────────────────────────────────────
step "Done"
info "Open a new terminal (or run: exec \$SHELL) to activate your shell config."
info ""
info "Useful commands:"
info " chezmoi update — pull latest dotfiles and re-apply"
info " chezmoi edit ~/.zshrc — edit a managed file"
info " aqua install — install/update all managed CLI tools"