-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·146 lines (131 loc) · 5.67 KB
/
setup.sh
File metadata and controls
executable file
·146 lines (131 loc) · 5.67 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
#!/usr/bin/env sh
set -e
DOTFILES_REPO="${DOTFILES_REPOSITORY:-git@github.com:haydenk/dotfiles.git}"
DOTFILES_DIR="$HOME/.cfg"
if [ -n "$CODESPACES" ]; then
# Dotfiles are already cloned locally by Codespaces — no network needed
DOTFILES_REPO="$(cd "$(dirname "$0")" && pwd)"
fi
# Use a function — aliases are not expanded in sh scripts
config() {
/usr/bin/git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
}
echo "==> Cloning dotfiles..."
# https://www.atlassian.com/git/tutorials/dotfiles
if [ -d "$DOTFILES_DIR" ]; then
echo " $DOTFILES_DIR already exists, skipping clone."
else
git clone --bare "$DOTFILES_REPO" "$DOTFILES_DIR"
fi
config config --local status.showUntrackedFiles no
echo "==> Checking out dotfiles..."
mkdir -p "$HOME/.config-backup"
if ! config checkout master 2>/dev/null; then
echo " Backing up conflicting files to ~/.config-backup..."
config checkout master 2>&1 \
| grep -E '^\s+\.' \
| awk '{print $1}' \
| while IFS= read -r f; do
mkdir -p "$HOME/.config-backup/$(dirname "$f")"
mv "$HOME/$f" "$HOME/.config-backup/$f"
done
config checkout master
fi
# -----------------------------------------------------------------------------
# Install apt essentials so the first shell works out of the box.
# Heavier / non-apt tools (oh-my-zsh, mise, fisher, claude, codex, qsv) are
# installed on demand via the `dotfiles_bootstrap` shell function.
#
# Skip with: DOTFILES_SKIP_INSTALL=1 ./setup.sh
# -----------------------------------------------------------------------------
if [ -n "$DOTFILES_SKIP_INSTALL" ]; then
echo "==> Skipping tool install (DOTFILES_SKIP_INSTALL set)."
elif ! command -v apt-get >/dev/null 2>&1; then
echo "==> Skipping tool install (apt-get not found — non-Debian system)."
else
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
echo "==> Skipping tool install (need root or sudo)."
DOTFILES_SKIP_INSTALL=1
fi
fi
if [ -z "$DOTFILES_SKIP_INSTALL" ]; then
echo "==> Installing apt essentials..."
# eza lives in its own apt repo; add it once if missing.
if ! command -v eza >/dev/null 2>&1 && [ ! -f /etc/apt/sources.list.d/gierens.list ]; then
echo " + adding eza apt repo"
$SUDO mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc \
| $SUDO gpg --yes --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" \
| $SUDO tee /etc/apt/sources.list.d/gierens.list >/dev/null
$SUDO chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
fi
$SUDO apt-get update -qq
# Build the install list dynamically — only ask apt for things we
# don't already have. Lets re-runs of setup.sh stay fast.
pkgs=""
for p in eza bat fd-find ripgrep fzf git-flow pwgen vim; do
case "$p" in
fd-find) cmd=fd ;;
*) cmd=$p ;;
esac
# bat ships as `batcat` on Ubuntu <22.04
if [ "$cmd" = "bat" ] && command -v batcat >/dev/null 2>&1; then
continue
fi
# fd ships as `fdfind` on Ubuntu
if [ "$cmd" = "fd" ] && command -v fdfind >/dev/null 2>&1; then
continue
fi
command -v "$cmd" >/dev/null 2>&1 || pkgs="$pkgs $p"
done
if [ -n "$pkgs" ]; then
echo " + apt:$pkgs"
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pkgs
else
echo " + apt essentials already installed"
fi
# Symlink batcat -> bat and fdfind -> fd if needed (Ubuntu naming).
mkdir -p "$HOME/.local/bin"
if command -v batcat >/dev/null 2>&1 && ! command -v bat >/dev/null 2>&1; then
ln -sf "$(command -v batcat)" "$HOME/.local/bin/bat"
fi
if command -v fdfind >/dev/null 2>&1 && ! command -v fd >/dev/null 2>&1; then
ln -sf "$(command -v fdfind)" "$HOME/.local/bin/fd"
fi
# git-delta — not in older apt repos; pull from GitHub releases.
if ! command -v delta >/dev/null 2>&1; then
echo " + git-delta (GitHub release)"
tmp=$(mktemp -d)
arch=$(uname -m)
case "$arch" in
x86_64) delta_arch="x86_64-unknown-linux-musl" ;;
aarch64) delta_arch="aarch64-unknown-linux-gnu" ;;
*) delta_arch="" ;;
esac
if [ -n "$delta_arch" ]; then
version=$(curl -fsSL https://api.github.com/repos/dandavison/delta/releases/latest \
| grep '"tag_name"' \
| sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')
if [ -n "$version" ] && curl -fsSL \
"https://github.com/dandavison/delta/releases/download/${version}/delta-${version}-${delta_arch}.tar.gz" \
| tar xz --strip-components=1 -C "$tmp" 2>/dev/null
then
mv "$tmp/delta" "$HOME/.local/bin/delta"
else
echo " (skipped: download failed; install delta later via dotfiles_bootstrap)"
fi
else
echo " (skipped: unsupported arch $arch)"
fi
rm -rf "$tmp"
fi
fi
fi
echo ""
echo "==> Done! Open a new shell to apply your dotfiles."
echo " For oh-my-zsh, mise, claude, codex, qsv: run 'dotfiles_bootstrap'."