-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_tools.sh
More file actions
375 lines (328 loc) · 12.6 KB
/
Copy pathinstall_tools.sh
File metadata and controls
375 lines (328 loc) · 12.6 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#!/bin/bash
# ==============================================================================
# MODERN LINUX TOOLKIT INSTALLER
# Installs a curated set of modern CLI tools on Linux
# Supports: Debian/Ubuntu, Fedora, Arch Linux
# Architectures: x86_64, aarch64
# ==============================================================================
set -euo pipefail
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# ==============================================================================
# ENVIRONMENT DETECTION
# ==============================================================================
ARCH=$(uname -m)
DISTRO=""
DISTRO_LIKE=""
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
DISTRO_LIKE=${ID_LIKE:-}
fi
case "$ARCH" in
x86_64) log_info "Detected architecture: x86_64" ;;
aarch64) log_info "Detected architecture: ARM64 (aarch64)" ;;
*)
log_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
if [ "$EUID" -ne 0 ]; then
log_error "Please run this script with sudo."
exit 1
fi
# ==============================================================================
# PACKAGE MANAGER HELPERS
# ==============================================================================
pm_install() {
case "$DISTRO" in
ubuntu|debian|pop|linuxmint|elementary)
DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
;;
fedora|rhel|centos)
dnf install -y "$@"
;;
arch|manjaro|endeavouros)
pacman -Sy --noconfirm "$@"
;;
*)
if echo "$DISTRO_LIKE" | grep -qi "debian\|ubuntu"; then
DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
elif echo "$DISTRO_LIKE" | grep -qi "fedora\|rhel\|centos"; then
dnf install -y "$@"
elif echo "$DISTRO_LIKE" | grep -qi "arch"; then
pacman -Sy --noconfirm "$@"
else
log_warn "Unknown distro ($DISTRO), cannot install: $*"
return 1
fi
;;
esac
}
pm_update() {
case "$DISTRO" in
ubuntu|debian|pop|linuxmint|elementary)
apt-get update -y || true
;;
fedora|rhel|centos)
dnf check-update || true
;;
arch|manjaro|endeavouros)
pacman -Sy --noconfirm
;;
*)
if echo "$DISTRO_LIKE" | grep -qi "debian\|ubuntu"; then
apt-get update -y || true
fi
;;
esac
}
is_debian_like() {
[[ "$DISTRO" =~ ^(ubuntu|debian|pop|linuxmint|elementary)$ ]] || echo "$DISTRO_LIKE" | grep -qi "debian\|ubuntu"
}
is_fedora_like() {
[[ "$DISTRO" =~ ^(fedora|rhel|centos)$ ]] || echo "$DISTRO_LIKE" | grep -qi "fedora\|rhel\|centos"
}
is_arch_like() {
[[ "$DISTRO" =~ ^(arch|manjaro|endeavouros)$ ]] || echo "$DISTRO_LIKE" | grep -qi "arch"
}
# ==============================================================================
# BASE DEPENDENCIES
# ==============================================================================
log_info "Installing base dependencies..."
# Clean up any repo files left over from previous script runs
sed -i '/deb\.gierens\.de\|maveonair.*helix/d' /etc/apt/sources.list.d/*.list 2>/dev/null || true
pm_update
# Common tools required everywhere
BASE_DEPS="curl wget git tar unzip gpg ca-certificates"
if is_debian_like; then
pm_install $BASE_DEPS xz-utils software-properties-common
elif is_fedora_like; then
pm_install $BASE_DEPS xz
elif is_arch_like; then
pm_install $BASE_DEPS xz
fi
# Verify essential tools are available
for cmd in curl wget tar unzip gpg; do
if ! command -v "$cmd" &>/dev/null; then
log_error "Essential tool '$cmd' is missing after install attempt."
exit 1
fi
done
log_success "Base dependencies ready."
# ==============================================================================
# GITHUB RELEASE INSTALLER
# ==============================================================================
INSTALL_DIR="/usr/local/bin"
install_from_github() {
local repo="$1"
local filter="$2"
local binary_name="$3"
local needs_runtime="${4:-false}"
log_info "Installing $binary_name from $repo..."
# Arch filter: some projects use "x86_64"/"aarch64", others "x86_64"/"arm64"
local arch_filter
if [ "$ARCH" = "x86_64" ]; then
arch_filter="x86_64|amd64"
else
arch_filter="(aarch64|arm64)"
fi
local api_response
api_response=$(curl -sfL "https://api.github.com/repos/$repo/releases/latest" 2>/dev/null || true)
if [ -z "$api_response" ]; then
log_warn "Could not reach GitHub API for $repo. Check your internet connection. Skipping."
return 1
fi
local download_url
download_url=$(echo "$api_response" \
| grep "browser_download_url" \
| grep -iE "$filter" \
| grep -iE "$arch_filter" \
| grep -viE 'no_libgit|-dbg-|-debug-' \
| grep -vE '\.(sha256|sha512|asc|sig|sum)$' \
| grep -v 'sha256sum' \
| cut -d '"' -f 4 \
| head -n 1)
if [ -z "$download_url" ]; then
log_warn "Could not find a matching download for $binary_name (filter: $filter, arch: $ARCH). Skipping."
return 1
fi
local tmpdir
tmpdir=$(mktemp -d)
local filename
filename=$(basename "$download_url")
log_info " Downloading $filename..."
curl -#fL -o "$tmpdir/$filename" "$download_url" || {
log_warn "Download failed for $binary_name. Skipping."
rm -rf "$tmpdir"
return 1
}
case "$filename" in
*.tar.xz)
tar -xJf "$tmpdir/$filename" -C "$tmpdir"
;;
*.tar.gz|*.tgz)
tar -xzf "$tmpdir/$filename" -C "$tmpdir"
;;
*.zip)
unzip -qo "$tmpdir/$filename" -d "$tmpdir"
;;
*.deb)
log_info " Installing .deb package directly..."
dpkg -i "$tmpdir/$filename" 2>/dev/null || {
log_warn "Direct .deb install failed, extracting binary..."
mkdir -p "$tmpdir/deb_extract"
dpkg-deb -x "$tmpdir/$filename" "$tmpdir/deb_extract"
local bin_path
bin_path=$(find "$tmpdir/deb_extract" -type f -name "$binary_name" 2>/dev/null | head -n 1)
if [ -n "$bin_path" ]; then
cp "$bin_path" "$INSTALL_DIR/$binary_name"
chmod +x "$INSTALL_DIR/$binary_name"
log_success "$binary_name extracted from .deb to $INSTALL_DIR/$binary_name"
fi
}
rm -rf "$tmpdir"
return 0
;;
*)
log_warn "Unknown archive format: $filename. Skipping $binary_name."
rm -rf "$tmpdir"
return 1
;;
esac
local binary_path
binary_path=$(find "$tmpdir" -type f -name "$binary_name" 2>/dev/null | head -n 1)
if [ -n "$binary_path" ]; then
cp "$binary_path" "$INSTALL_DIR/$binary_name"
chmod +x "$INSTALL_DIR/$binary_name"
log_success "$binary_name installed to $INSTALL_DIR/$binary_name"
else
log_warn "Binary '$binary_name' not found inside the extracted archive."
ls -la "$tmpdir" 2>/dev/null | head -5
rm -rf "$tmpdir"
return 1
fi
# Install runtime support directory if requested (e.g., helix runtime/ tree)
if [ "$needs_runtime" = "true" ]; then
local runtime_src
runtime_src=$(find "$tmpdir" -type d -name "runtime" 2>/dev/null | head -n 1)
if [ -n "$runtime_src" ]; then
mkdir -p "/usr/lib/$binary_name"
cp -r "$runtime_src" "/usr/lib/$binary_name/"
log_success "Runtime files installed to /usr/lib/$binary_name/runtime"
else
log_warn "No 'runtime' directory found for $binary_name."
fi
fi
rm -rf "$tmpdir"
}
# ==============================================================================
# TOOL INSTALLATION
# ==============================================================================
# --- EZA (modern ls replacement) ---
if command -v eza &>/dev/null; then
log_success "eza already installed."
elif is_debian_like; then
log_info "Installing eza from official repository..."
mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc 2>/dev/null | gpg --dearmor -o /etc/apt/keyrings/gierens.gpg 2>/dev/null || {
log_warn "eza GPG key import failed. Falling back to binary install."
install_from_github "eza-community/eza" "linux-gnu" "eza"
}
if [ -f /etc/apt/keyrings/gierens.gpg ]; then
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] https://deb.gierens.de/ stable main" \
| tee /etc/apt/sources.list.d/gierens.list > /dev/null
chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
apt-get update 2>/dev/null && apt-get install -y eza 2>/dev/null && log_success "eza installed." \
|| { log_warn "eza repo install failed. Removing repo and falling back to binary."; rm -f /etc/apt/sources.list.d/gierens.list; install_from_github "eza-community/eza" "linux-gnu" "eza"; }
fi
elif is_fedora_like; then
pm_install eza 2>/dev/null && log_success "eza installed." \
|| { log_warn "eza package not found in repos. Trying binary..."; install_from_github "eza-community/eza" "linux-gnu" "eza"; }
elif is_arch_like; then
pm_install eza && log_success "eza installed."
else
install_from_github "eza-community/eza" "linux-gnu" "eza"
fi
# --- REPO-BASED TOOLS (ncdu, btop, jq, ripgrep, fzf, fd, bat) ---
if is_debian_like; then
log_info "Installing repo-based tools..."
pm_install ncdu btop jq ripgrep fzf fd-find bat
# Debian/Ubuntu ship fd as fdfind and bat as batcat
command -v fd &>/dev/null || command -v fdfind &>/dev/null && ln -sf "$(which fdfind)" /usr/local/bin/fd || true
command -v bat &>/dev/null || command -v batcat &>/dev/null && ln -sf "$(which batcat)" /usr/local/bin/bat || true
elif is_fedora_like; then
pm_install ncdu btop jq ripgrep fzf fd-find bat
elif is_arch_like; then
pm_install ncdu btop jq ripgrep fzf fd bat
fi
# --- HELIX EDITOR ---
if command -v hx &>/dev/null; then
log_success "Helix (hx) already installed."
else
install_from_github "helix-editor/helix" "linux" "hx" "true"
fi
if command -v hx &>/dev/null; then
HELIX_RUNTIME=$(hx --health 2>/dev/null | grep "runtime" | head -1 || echo "")
if echo "$HELIX_RUNTIME" | grep -qi "not found\|missing\|error"; then
if [ -d "/usr/lib/hx/runtime" ]; then
export HELIX_RUNTIME=/usr/lib/hx/runtime
log_info "Set HELIX_RUNTIME=/usr/lib/hx/runtime"
fi
fi
fi
# --- LAZYGIT ---
install_from_github "jesseduffield/lazygit" "Linux" "lazygit"
# --- LAZYDOCKER ---
install_from_github "jesseduffield/lazydocker" "Linux" "lazydocker"
# --- LAZYSQL ---
install_from_github "jorgerojas26/lazysql" "Linux" "lazysql"
# --- YAZI (terminal file manager) ---
# Prefer .deb on Debian/Ubuntu, otherwise use musl zip
if is_debian_like; then
install_from_github "sxyazi/yazi" "linux-gnu" "yazi"
else
install_from_github "sxyazi/yazi" "linux-musl" "yazi"
fi
# ==============================================================================
# SUMMARY & SHELL CONFIGURATION
# ==============================================================================
echo ""
echo "================================================================"
echo -e "${GREEN}INSTALLATION COMPLETE${NC}"
echo "================================================================"
echo ""
installed_list=""
for tool in eza hx lazygit lazydocker lazysql yazi ncdu btop jq rg fzf fd bat; do
if command -v "$tool" &>/dev/null; then
installed_list+=" ${GREEN}✓${NC} $tool\n"
else
installed_list+=" ${RED}✗${NC} $tool\n"
fi
done
echo -e "$installed_list"
echo ""
echo "To enable the new tools, add these aliases to ~/.bashrc or ~/.zshrc:"
echo ""
cat <<'CONFIG_EOF'
# --- MODERN LINUX ALIASES ---
alias ls='eza --icons --group-directories-first'
alias ll='eza -alF --icons --group-directories-first'
alias tree='eza --tree --icons'
alias cat='bat'
alias grep='rg'
alias fm='yazi'
alias lg='lazygit'
alias ld='lazydocker'
alias usage='ncdu --color dark -rr -x --exclude .git --exclude node_modules'
CONFIG_EOF
echo ""
echo "Then run: source ~/.bashrc"
echo "================================================================"