-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·490 lines (385 loc) · 15.8 KB
/
install.sh
File metadata and controls
executable file
·490 lines (385 loc) · 15.8 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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#!/usr/bin/env bash
# ============================================================================
# blxshell Installation Script
# ============================================================================
# Usage:
# Local: ./install.sh
# Remote: curl -fsSL https://raw.githubusercontent.com/USER/REPO/main/install.sh | bash
# bash <(curl -fsSL https://raw.githubusercontent.com/USER/REPO/main/install.sh)
# ============================================================================
set -eo pipefail
# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
readonly YELLOW='\033[0;33m'
readonly CYAN='\033[0;36m'
readonly BOLD='\033[1m'
readonly NC='\033[0m'
# Configuration
readonly REPO_URL="https://github.com/binarylinuxx/dots.git"
readonly REPO_BRANCH="main"
readonly BACKUP_DIR="$HOME/.cache/.config_backup"
readonly LOG_FILE="/tmp/blxshell_install_$(date +%Y%m%d_%H%M%S).log"
readonly PACKAGES=("blxshell-quickshell-git" "blxshell-shell" "blxshell-audio" "blxshell-hyprland" "blxshell-font-googlesans" "blxshell-font-bitcount")
readonly OPENSUSE_PACKAGES=("blxshell-quickshell-git" "blxshell-shell" "blxshell-audio" "blxshell-hyprland" "blxshell-fonts" "gcc-c++" "python3-devel")
readonly OBS_REPO_URL="https://download.opensuse.org/repositories/home:binarylinuxx:blxshell/openSUSE_Tumbleweed/"
readonly OBS_REPO_ALIAS="home_binarylinuxx_blxshell"
# State (will be set by detect_install_mode)
SCRIPT_DIR=""
REMOTE_INSTALL=false
INSTALL_DOTFILES=false
BACKUP_DONE=false
CLEANUP_DIR=""
# ============================================================================
# Utility Functions
# ============================================================================
log() { echo "[$(date '+%H:%M:%S')] $*" >> "$LOG_FILE"; }
info() { echo -e "${BLUE}::${NC} $1"; log "INFO: $1"; }
success() { echo -e "${GREEN}[+]${NC} $1"; log "SUCCESS: $1"; }
warning() { echo -e "${YELLOW}[!]${NC} $1"; log "WARNING: $1"; }
error() { echo -e "${RED}[-]${NC} $1"; log "ERROR: $1"; }
die() { error "$1"; exit 1; }
confirm() {
local prompt="$1" default="${2:-n}" response
# If not interactive (piped), use default
if [[ ! -t 0 ]]; then
[[ "$default" =~ ^[Yy]$ ]]
return $?
fi
[[ "$default" =~ ^[Yy] ]] && prompt="$prompt [Y/n]: " || prompt="$prompt [y/N]: "
echo -en "${YELLOW}${prompt}${NC}"
read -r response </dev/tty
[[ "${response:-$default}" =~ ^[Yy]$ ]]
}
command_exists() { command -v "$1" &>/dev/null; }
# ============================================================================
# Installation Mode Detection
# ============================================================================
detect_install_mode() {
# Method 1: Check if BASH_SOURCE points to a real file in a valid repo
if [[ -n "${BASH_SOURCE[0]}" ]] && [[ -f "${BASH_SOURCE[0]}" ]]; then
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null)"
if [[ -n "$script_dir" ]] && [[ -d "$script_dir/arch-deps" ]]; then
SCRIPT_DIR="$script_dir"
REMOTE_INSTALL=false
info "Detected: Running from local repository"
return 0
fi
fi
# Method 2: Check if we're in a git repo with the expected structure
if git rev-parse --git-dir &>/dev/null; then
local git_root
git_root="$(git rev-parse --show-toplevel 2>/dev/null)"
if [[ -n "$git_root" ]] && [[ -d "$git_root/arch-deps" ]]; then
SCRIPT_DIR="$git_root"
REMOTE_INSTALL=false
info "Detected: Running from git repository"
return 0
fi
fi
# Method 3: Running from curl/pipe - need to clone
REMOTE_INSTALL=true
SCRIPT_DIR="/tmp/blxshell_install_$$"
CLEANUP_DIR="$SCRIPT_DIR"
info "Detected: Remote installation (will clone repository)"
}
clone_repository() {
info "Cloning repository to $SCRIPT_DIR..."
if ! command_exists git; then
info "Installing git..."
if [[ "$IS_OPENSUSE" == true ]]; then
sudo zypper install -y git || die "Failed to install git"
else
sudo pacman -S --needed --noconfirm git || die "Failed to install git"
fi
fi
git clone --depth 1 --branch "$REPO_BRANCH" "$REPO_URL" "$SCRIPT_DIR" 2>&1 | tee -a "$LOG_FILE" || {
die "Failed to clone repository from $REPO_URL"
}
success "Repository cloned successfully"
}
# ============================================================================
# Pre-flight Checks
# ============================================================================
preflight_checks() {
info "Running pre-flight checks..."
# Don't run as root
[[ $EUID -eq 0 ]] && die "Do not run this script as root!"
# Validate OS
source "$SCRIPT_DIR/os_release_validator.sh"
validate_os
# Check internet
local ping_host="archlinux.org"
[[ "$IS_OPENSUSE" == true ]] && ping_host="opensuse.org"
if ! ping -c 1 -W 3 "$ping_host" &>/dev/null; then
warning "No internet connection detected"
confirm "Continue anyway?" || exit 1
fi
# For remote install, we need internet
if [[ "$REMOTE_INSTALL" == true ]]; then
ping -c 1 -W 3 github.com &>/dev/null || die "Internet required for remote installation!"
fi
# Check disk space (minimum 1GB)
local space
space=$(df -BG "$HOME" | awk 'NR==2 {gsub(/G/,""); print $4}')
if [[ "$space" -lt 1 ]]; then
warning "Low disk space: ${space}GB available"
confirm "Continue anyway?" || exit 1
fi
success "Pre-flight checks passed"
}
# ============================================================================
# Yay Installation
# ============================================================================
install_yay() {
if command_exists yay; then
success "yay already installed"
return 0
fi
info "Installing yay..."
sudo pacman -S --needed --noconfirm git base-devel || die "Failed to install base dependencies"
local tmp_dir="/tmp/yay_install_$$"
trap "rm -rf '$tmp_dir'" RETURN
git clone https://aur.archlinux.org/yay-bin.git "$tmp_dir" || die "Failed to clone yay"
(cd "$tmp_dir" && makepkg -si --noconfirm) || die "Failed to install yay"
command_exists yay && success "yay installed" || die "yay installation failed"
}
# ============================================================================
# openSUSE Package Installation
# ============================================================================
add_obs_repo() {
if zypper repos 2>/dev/null | grep -q "$OBS_REPO_ALIAS"; then
success "OBS repo already added"
sudo zypper --gpg-auto-import-keys refresh "$OBS_REPO_ALIAS" 2>&1 | tee -a "$LOG_FILE" || true
return 0
fi
info "Adding blxshell OBS repository..."
sudo zypper addrepo --refresh --name "blxshell (home:binarylinuxx:blxshell)" \
"$OBS_REPO_URL" "$OBS_REPO_ALIAS" 2>&1 | tee -a "$LOG_FILE" || {
die "Failed to add OBS repository"
}
info "Importing OBS repository GPG key..."
sudo zypper --gpg-auto-import-keys refresh "$OBS_REPO_ALIAS" 2>&1 | tee -a "$LOG_FILE" || {
die "Failed to refresh OBS repository"
}
success "OBS repository added"
}
install_opensuse_packages() {
echo -e "\n${BOLD}${BLUE}══════ Installing Packages (openSUSE) ══════${NC}\n"
add_obs_repo
info "Packages to install:"
for pkg in "${OPENSUSE_PACKAGES[@]}"; do
echo -e " ${GREEN}✓${NC} $pkg"
done
info "Installing blxshell packages via zypper..."
# shellcheck disable=SC2086
if ! sudo zypper install -y --allow-vendor-change "${OPENSUSE_PACKAGES[@]}" 2>&1 | tee -a "$LOG_FILE"; then
error "Failed to install packages"
return 1
fi
success "All packages installed!"
}
# ============================================================================
# Package Installation
# ============================================================================
get_depends() {
local pkgbuild="$1"
bash -c "source '$pkgbuild' 2>/dev/null && echo \"\${depends[*]}\""
}
install_package() {
local pkg_name="$1"
local pkg_dir="$SCRIPT_DIR/arch-deps/$pkg_name"
echo -e "\n${CYAN}━━━ $pkg_name ━━━${NC}"
[[ -f "$pkg_dir/PKGBUILD" ]] || { error "PKGBUILD not found for $pkg_name"; return 1; }
local depends
depends=$(get_depends "$pkg_dir/PKGBUILD")
if [[ -n "$depends" ]]; then
info "Installing dependencies: $depends"
# shellcheck disable=SC2086
if ! yay -S --sudoloop --needed --noconfirm --asdeps --overwrite '*' $depends 2>&1 | tee -a "$LOG_FILE"; then
error "Failed to install dependencies"
return 1
fi
fi
info "Building $pkg_name..."
(cd "$pkg_dir" && makepkg -Afc --noconfirm) 2>&1 | tee -a "$LOG_FILE" || {
error "Failed to build $pkg_name"
return 1
}
local pkg_file
pkg_file=$(find "$pkg_dir" -maxdepth 1 -name "*.pkg.tar.zst" -newer "$pkg_dir/PKGBUILD" | head -1)
[[ -n "$pkg_file" ]] || { error "No package file found"; return 1; }
info "Installing $pkg_name..."
sudo pacman -U --noconfirm --overwrite '*' "$pkg_file" 2>&1 | tee -a "$LOG_FILE" || {
error "Failed to install $pkg_name"
return 1
}
success "$pkg_name installed"
}
install_metapackages() {
echo -e "\n${BOLD}${BLUE}══════ Installing Metapackages ══════${NC}\n"
install_yay
sudo pacman -S --needed --noconfirm base-devel &>/dev/null
info "Packages to install:"
for pkg in "${PACKAGES[@]}"; do
if [[ -d "$SCRIPT_DIR/arch-deps/$pkg" ]]; then
echo -e " ${GREEN}✓${NC} $pkg"
else
echo -e " ${RED}✗${NC} $pkg ${YELLOW}(missing)${NC}"
fi
done
local failed=()
for pkg in "${PACKAGES[@]}"; do
[[ -d "$SCRIPT_DIR/arch-deps/$pkg" ]] || { warning "Skipping $pkg"; continue; }
install_package "$pkg" || failed+=("$pkg")
done
if [[ ${#failed[@]} -gt 0 ]]; then
error "Failed packages: ${failed[*]}"
return 1
fi
success "All metapackages installed!"
}
# ============================================================================
# Backup & Dotfiles
# ============================================================================
backup_config() {
local timestamp backup_path
timestamp=$(date +%Y%m%d_%H%M%S)
backup_path="$BACKUP_DIR/config_$timestamp"
info "Creating backup at $backup_path..."
mkdir -p "$BACKUP_DIR"
if cp -r "$HOME/.config" "$backup_path"; then
ln -sfn "$backup_path" "$BACKUP_DIR/latest"
success "Backup completed"
BACKUP_DONE=true
else
error "Backup failed!"
return 1
fi
}
install_dotfiles() {
[[ -d "$SCRIPT_DIR/.config" ]] || { error "No .config in $SCRIPT_DIR"; return 1; }
info "Installing dotfiles..."
if [[ "$BACKUP_DONE" == false && -d "$HOME/.config" ]]; then
warning "No backup exists - creating one now..."
backup_config || return 1
fi
rm -rf "$HOME/.config"
cp -r "$SCRIPT_DIR/.config" "$HOME/"
success "Dotfiles installed to $HOME/.config"
}
# ============================================================================
# Color Generator Setup
# ============================================================================
setup_col_gen() {
local col_gen_dir="$HOME/.config/quickshell/col_gen"
[[ -d "$col_gen_dir" ]] || { warning "col_gen directory not found, skipping"; return 0; }
info "Setting up color generator (col_gen)..."
# Install uv if not present
if ! command_exists uv; then
info "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh || die "Failed to install uv"
export PATH="$HOME/.local/bin:$PATH"
command_exists uv || die "uv not found after installation"
fi
# Create venv and install dependencies
info "Creating Python virtual environment..."
(cd "$col_gen_dir" && uv sync) 2>&1 | tee -a "$LOG_FILE" || die "Failed to setup col_gen venv"
success "Color generator ready"
}
# ============================================================================
# Main
# ============================================================================
show_banner() {
echo -e "${CYAN}"
cat << 'EOF'
_ _ _ _ _
| |__ | |_ _____| |__ ___| | |
| '_ \| \ \/ / __| '_ \ / _ \ | |
| |_) | |> <\__ \ | | | __/ | |
|_.__/|_/_/\_\___/_| |_|\___|_|_|
EOF
echo -e "${NC}${BOLD}Installation Script${NC} | Log: ${BLUE}$LOG_FILE${NC}\n"
}
greet_user() {
echo -e "Hello ${BOLD}$USER${NC}!\n"
if [[ "$REMOTE_INSTALL" == true ]]; then
info "Remote install mode - dotfiles will be installed by default"
INSTALL_DOTFILES=true
if [[ -d "$HOME/.config" ]]; then
backup_config || { confirm "Continue without backup?" || exit 1; }
fi
return
fi
if confirm "Install dotfiles (will replace ~/.config)?" "n"; then
INSTALL_DOTFILES=true
if [[ -d "$HOME/.config" ]]; then
if confirm "Backup existing ~/.config first?" "y"; then
backup_config || { confirm "Continue without backup?" || exit 1; }
else
warning "Config will be overwritten without backup!"
confirm "Are you absolutely sure?" || exit 1
fi
fi
fi
}
cleanup() {
local exit_code=$?
# Clean up cloned repo if remote install
if [[ -n "$CLEANUP_DIR" ]] && [[ -d "$CLEANUP_DIR" ]]; then
info "Cleaning up temporary files..."
rm -rf "$CLEANUP_DIR"
fi
if [[ $exit_code -ne 0 ]]; then
echo -e "\n${RED}━━━ Installation Failed ━━━${NC}"
error "Check log: $LOG_FILE"
[[ "$BACKUP_DONE" == true ]] && info "Backup at: $BACKUP_DIR/latest"
fi
}
trap cleanup EXIT
main() {
show_banner
# Detect if running locally or from curl
detect_install_mode
# Clone if remote install
if [[ "$REMOTE_INSTALL" == true ]]; then
clone_repository
fi
cd "$SCRIPT_DIR"
# Verify directory structure
[[ -d "$SCRIPT_DIR/arch-deps" ]] || die "'arch-deps' directory not found!"
preflight_checks
greet_user
echo -e "\n${BOLD}${YELLOW}══════ Starting Installation ══════${NC}"
if [[ "$SKIP_PACKAGES" == true ]]; then
warning "Skipping package installation (unsupported system)"
INSTALL_DOTFILES=true
elif [[ "$IS_OPENSUSE" == true ]]; then
install_opensuse_packages || exit 1
else
install_metapackages || exit 1
fi
if [[ "$INSTALL_DOTFILES" == true ]]; then
echo -e "\n${BOLD}${BLUE}══════ Installing Dotfiles ══════${NC}\n"
install_dotfiles || exit 1
fi
echo -e "\n${BOLD}${BLUE}══════ Setting Up Color Generator ══════${NC}\n"
setup_col_gen || exit 1
echo -e "\n${BOLD}${BLUE}══════ Setting Default Shell ══════${NC}\n"
info "Setting fish as default shell..."
chsh -s /usr/bin/fish || warning "Failed to set fish as default shell (run: chsh -s /usr/bin/fish)"
echo -e "\n${BOLD}${BLUE}══════ Configuring Groups ══════${NC}\n"
info "Adding $USER to NetworkManager group..."
# Only Arch uses a 'network' group — openSUSE uses PolicyKit, no group needed
if getent group network &>/dev/null; then
sudo /usr/sbin/usermod -aG network "$USER" && success "Added $USER to network" \
|| warning "Failed to add $USER to network group"
else
success "NetworkManager managed via PolicyKit — no group needed"
fi
echo -e "\n${BOLD}${GREEN}══════ Installation Complete! ══════${NC}\n"
echo -e "\n${GREEN}Please reboot and login into Hyprland (NOT UWSM)${NC}\n"
}
main "$@"