-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_linux.sh
More file actions
executable file
·301 lines (267 loc) · 11.3 KB
/
Copy pathsetup_linux.sh
File metadata and controls
executable file
·301 lines (267 loc) · 11.3 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
set -e
# Resolve script directory up-front, before any `cd` later in the script can
# break a relative ${BASH_SOURCE[0]} (e.g. when invoked as ./setup_linux.sh).
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function show_help() {
cat <<EOF
Usage: $0 [options]
Setup script for a new development machine.
Installs tools and configurations based on the dotfiles repository.
Options:
--help Show this help message
EOF
exit 0
}
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--help) show_help ;;
*) echo "Unknown parameter passed: $1"; echo "Use --help for usage information."; exit 1 ;;
esac
shift
done
# setup.sh - Setup script for a new development machine
# Installs tools and configurations based on the dotfiles repository.
echo "[setup] Starting setup..."
# Check if running on a Debian/Ubuntu based system
if [ -f /etc/debian_version ]; then
echo "[system] Detected Debian/Ubuntu system."
# Update package list
sudo apt-get update
# Install apt packages
echo "[system] Installing system packages..."
# Packages that may not exist on older Debian; install individually to tolerate missing ones
APT_PACKAGES=(
bubblewrap ca-certificates cmake curl gcc g++ git gnupg iproute2 jq
libevent-dev libncurses5-dev libncursesw5-dev
make python3 python3-pip python3-venv ripgrep rsync
software-properties-common stow sudo ssh sshpass
unzip uuid-runtime
)
# Try distribution-specific names
for pkg in "7zip" "p7zip-full"; do
if apt-cache show "$pkg" &>/dev/null; then APT_PACKAGES+=("$pkg"); break; fi
done
if apt-cache show "python3-pynvim" &>/dev/null; then APT_PACKAGES+=("python3-pynvim"); fi
if apt-cache show "zoxide" &>/dev/null; then APT_PACKAGES+=("zoxide"); fi
sudo apt-get install -y "${APT_PACKAGES[@]}"
# Install pynvim via pip if apt package unavailable
if ! python3 -c "import pynvim" &>/dev/null; then
echo "[system] Installing pynvim via pip3..."
python3 -m pip install --user pynvim 2>/dev/null || pip3 install --user pynvim 2>/dev/null || sudo python3 -m pip install pynvim
fi
# Install zoxide from GitHub if not available via apt
if ! command -v zoxide &>/dev/null; then
echo "[zoxide] Installing zoxide from GitHub..."
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
fi
# Install Fish shell
if ! command -v fish &> /dev/null; then
if [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release 2>/dev/null; then
# Ubuntu: use PPA for latest Fish 4.x
echo "[fish] Installing Fish shell from PPA (Ubuntu)..."
sudo add-apt-repository -y ppa:fish-shell/release-4
sudo apt-get update
sudo apt-get install -y fish
else
# Debian: try backports first, fallback to repo version
echo "[fish] Installing Fish shell (Debian)..."
DISTRO_CODENAME=$(lsb_release -cs 2>/dev/null || (. /etc/os-release && echo "$VERSION_CODENAME"))
if sudo apt-get install -y -t "${DISTRO_CODENAME}-backports" fish 2>/dev/null; then
echo "[fish] Installed Fish from backports."
else
echo "[fish] Backports not available, installing from default repo..."
sudo apt-get install -y fish
fi
fi
else
echo "[fish] Fish is already installed."
fi
# Install Docker
if ! command -v docker &> /dev/null; then
echo "[docker] Installing Docker from official apt repo..."
. /etc/os-release
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL "https://download.docker.com/linux/${ID}/gpg" \
| sudo gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" \
| sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
if ! id -nG "$USER" | grep -qw docker; then
echo "[docker] Adding $USER to docker group (re-login required to take effect)..."
sudo usermod -aG docker "$USER"
fi
else
echo "[docker] Docker is already installed."
fi
else
echo "[system] Warning: Not on Debian/Ubuntu. Skipping apt package installation."
echo "[system] Please ensure you have the equivalent packages installed manually."
fi
# Install latest fzf from GitHub releases
if ! command -v fzf &> /dev/null; then
echo "[fzf] Installing latest fzf from GitHub..."
curl -L "https://github.com/junegunn/fzf/releases/download/v0.67.0/fzf-0.67.0-linux_amd64.tar.gz" -o /tmp/fzf.tar.gz
sudo tar -xzf /tmp/fzf.tar.gz -C /tmp
sudo mv /tmp/fzf /usr/local/bin/
sudo chmod +x /usr/local/bin/fzf
rm /tmp/fzf.tar.gz
echo "[fzf] fzf installed successfully."
else
echo "[fzf] fzf is already installed."
fi
# Install fd from GitHub releases
if ! command -v fd &> /dev/null; then
echo "[fd] Installing fd from GitHub..."
sudo curl -L "https://github.com/sharkdp/fd/releases/download/v10.3.0/fd-v10.3.0-x86_64-unknown-linux-gnu.tar.gz" -o /tmp/fd.tar.gz
sudo tar -xzf /tmp/fd.tar.gz -C /tmp
sudo mv /tmp/fd-v10.3.0-x86_64-unknown-linux-gnu/fd /usr/local/bin/
sudo chmod +x /usr/local/bin/fd
rm -rf /tmp/fd.tar.gz /tmp/fd-v10.3.0-x86_64-unknown-linux-gnu
echo "[fd] fd installed successfully."
else
echo "[fd] fd is already installed."
fi
# Install tmux from source
if ! command -v tmux &> /dev/null; then
echo "[tmux] Installing tmux (v3.6a) from source..."
TMUX_TEMP_DIR=$(mktemp -d)
cd "$TMUX_TEMP_DIR"
curl -L https://github.com/tmux/tmux/releases/download/3.6a/tmux-3.6a.tar.gz -o tmux-3.6a.tar.gz
tar xzf tmux-3.6a.tar.gz
cd tmux-3.6a
./configure --prefix=/usr/local CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
make
sudo make install
cd /
rm -rf "$TMUX_TEMP_DIR"
echo "[tmux] tmux installed successfully."
else
echo "[tmux] tmux is already installed."
fi
# Install Node.js
if ! command -v node &> /dev/null; then
echo "[node] Installing Node.js (v24.4.0)..."
curl -s https://nodejs.org/dist/v24.4.0/node-v24.4.0-linux-x64.tar.xz | sudo tar -xJ --strip-components=1 -C /usr/local
else
echo "[node] Node.js is already installed."
fi
# Install Yazi (File Manager)
if ! command -v yazi &> /dev/null; then
echo "[yazi] Installing Yazi..."
TEMP_DIR=$(mktemp -d)
curl -L https://github.com/sxyazi/yazi/releases/download/v25.5.31/yazi-x86_64-unknown-linux-musl.zip -o "$TEMP_DIR/yazi.zip"
unzip "$TEMP_DIR/yazi.zip" -d "$TEMP_DIR"
sudo cp "$TEMP_DIR/yazi-x86_64-unknown-linux-musl/ya" /usr/local/bin/
sudo cp "$TEMP_DIR/yazi-x86_64-unknown-linux-musl/yazi" /usr/local/bin/
rm -rf "$TEMP_DIR"
else
echo "[yazi] Yazi is already installed."
fi
# Install Neovim
if ! command -v nvim &> /dev/null; then
echo "[neovim] Installing Neovim (v0.12.2)..."
curl -L https://github.com/neovim/neovim-releases/releases/download/v0.12.2/nvim-linux-x86_64.tar.gz | sudo tar zxf - -C /usr/local/ --strip-components=1
else
echo "[neovim] Neovim is already installed."
fi
# Install uv
if ! command -v uv &> /dev/null; then
echo "[uv] Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
fi
# Install OpenCode
if ! command -v opencode &> /dev/null; then
echo "[opencode] Installing OpenCode..."
curl -fsSL https://opencode.ai/install | bash
else
echo "[opencode] OpenCode is already installed."
fi
# Install Rust (rustup)
if ! command -v rustup &> /dev/null; then
echo "[rust] Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
echo "[rust] Rust installed."
else
echo "[rust] Rust is already installed."
fi
# Stow Dotfiles
if [ -d "$SCRIPT_DIR/stow-dotfiles" ]; then
echo "[stow] Stowing dotfiles..."
cd "$SCRIPT_DIR/stow-dotfiles"
# Pre-resolve conflicts: stow refuses to overwrite existing regular files
# (e.g. ~/.config/fish/fish_variables auto-created by fish on first run,
# ~/.claude/settings.json created by Claude Code). Back them up to .bak
# so stow can plant its symlink.
for pkg in */; do
pkg="${pkg%/}"
while IFS= read -r -d '' src; do
rel="${src#$pkg/}"
target="$HOME/$rel"
if [ -e "$target" ] && [ ! -L "$target" ] && [ ! -d "$target" ]; then
echo "[stow] Backing up conflicting $target -> $target.bak"
mv "$target" "$target.bak"
fi
done < <(find "$pkg" -type f -print0)
done
stow -t "$HOME" -R */
cd "$SCRIPT_DIR"
else
echo "[stow] Error: stow-dotfiles directory not found in $SCRIPT_DIR"
fi
# Set LANG if not already set
BASHRC="$HOME/.bashrc"
if [ -z "$LANG" ]; then
echo "[bash] Setting LANG=en_US.UTF-8 in $BASHRC..."
if ! grep -q "export LANG=en_US.UTF-8" "$BASHRC" 2>/dev/null; then
echo "export LANG=en_US.UTF-8" >> "$BASHRC"
echo "[bash] LANG set in $BASHRC."
else
echo "[bash] LANG already configured in $BASHRC."
fi
export LANG=en_US.UTF-8
fi
# Setup Fish Shell
echo "[fish] Setting up Fish shell..."
echo "[fish] Fish version: $(fish --version)"
# Install Fisher and plugins.
# PatrickF1/fzf.fish uses `set -f` (function-local scope) which was added in
# fish 3.5; on older fish (e.g. Debian buster ships 3.1.2) the plugin emits
# errors on every shell start. Skip the install there — config.fish already
# falls back to the native `fzf --fish | source` integration.
FISH_VER=$(fish -c 'echo $version' 2>/dev/null)
FISH_MAJOR=${FISH_VER%%.*}
FISH_MINOR=$(echo "$FISH_VER" | cut -d. -f2)
if [ "${FISH_MAJOR:-0}" -gt 3 ] || { [ "${FISH_MAJOR:-0}" -eq 3 ] && [ "${FISH_MINOR:-0}" -ge 5 ]; }; then
fish -c 'curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install PatrickF1/fzf.fish'
else
echo "[fish] Skipping fisher/fzf.fish install: fish $FISH_VER is too old (need >= 3.5). Native 'fzf --fish | source' in config.fish covers fzf integration."
fi
# Configure .bashrc to start fish automatically (from README.md)
echo "[bash] Configuring .bashrc to automatically start fish..."
if [ -f "$BASHRC" ]; then
# Check if we already added it to avoid duplicates
if ! grep -q "exec fish" "$BASHRC"; then
cat >> "$BASHRC" << 'EOF'
if [[ $(ps --no-header --pid=$PPID --format=comm) != "fish" && -z ${BASH_EXECUTION_STRING} && ${SHLVL} == 1 ]]
then
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=''
exec fish $LOGIN_OPTION
fi
EOF
echo "[bash] Updated $BASHRC to launch fish."
else
echo "[bash] Fish launch logic already in $BASHRC."
fi
fi
echo "==================================================="
echo "[setup] Setup complete!"
echo "[setup] Please restart your shell or log out and back in."
echo "[setup] Fish has been configured to launch automatically from .bashrc."
echo "==================================================="