forked from rio/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·85 lines (71 loc) · 2.98 KB
/
Copy pathsetup
File metadata and controls
executable file
·85 lines (71 loc) · 2.98 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
#!/bin/bash
set -euo pipefail
# Ensure ~/.local/bin is on PATH (mise installs tools here)
case ":$PATH:" in
*:"$HOME/.local/bin":*) ;;
*) export PATH="$HOME/.local/bin:$PATH" ;;
esac
# ── Collect config values upfront ────────────────────────────────────────────
CHEZMOI_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi"
CHEZMOI_CONFIG="$CHEZMOI_CONFIG_DIR/chezmoi.toml"
if [ ! -f "$CHEZMOI_CONFIG" ]; then
echo "==> Configuring dotfiles"
if [ -t 0 ]; then
# Interactive mode: prompt for values
while [ -z "$cfg_name" ]; do
read -rp "Git user.name: " cfg_name
done
while [ -z "$cfg_email" ]; do
read -rp "Git user.email: " cfg_email
done
read -rp "GPG key fingerprint (leave blank to skip): " cfg_gpg
read -rp "Tailscale auth key (leave blank to skip): " cfg_ts
else
# Non-interactive mode: use environment variables
cfg_name="${GIT_USER_NAME:-}"
cfg_email="${GIT_USER_EMAIL:-}"
cfg_gpg="${GPG_KEY:-}"
cfg_ts="${TAILSCALE_AUTHKEY:-}"
fi
# Validate: name and email are required in non-interactive mode
if [ ! -t 0 ] && { [ -z "$cfg_name" ] || [ -z "$cfg_email" ]; }; then
echo "ERROR: GIT_USER_NAME and GIT_USER_EMAIL must be set in non-interactive mode" >&2
exit 1
fi
# Escape backslashes and double-quotes for TOML string values
toml_quote() { printf '"%s"' "$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')"; }
mkdir -p "$CHEZMOI_CONFIG_DIR"
cat > "$CHEZMOI_CONFIG" <<EOF
[data]
name = $(toml_quote "$cfg_name")
email = $(toml_quote "$cfg_email")
gpg_signing_key = $(toml_quote "$cfg_gpg")
tailscale_authkey = $(toml_quote "$cfg_ts")
EOF
chmod 600 "$CHEZMOI_CONFIG"
fi
# ── Install Homebrew if missing ───────────────────────────────────────────────
if ! command -v brew >/dev/null; then
echo "==> Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Add brew to PATH for this session
if [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
elif [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# ── Install zsh via brew if missing ──────────────────────────────────────────
if ! command -v zsh >/dev/null; then
echo "==> Installing zsh"
brew install zsh
fi
# ── Bootstrap chezmoi and apply dotfiles ─────────────────────────────────────
if command -v chezmoi >/dev/null; then
chezmoi init --apply --source "$PWD"
exit 0
fi
if command -v mise >/dev/null; then
mise exec chezmoi -- chezmoi init --apply --source "$PWD" && exit 0
fi
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply --source "$PWD"