-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
536 lines (456 loc) · 14.8 KB
/
install.sh
File metadata and controls
536 lines (456 loc) · 14.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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#!/bin/bash
# Interactive installation script for li
# Enhanced directory listing tool
#
# Copyright (c) 2025 Lotus-OS Core
# Licensed under MIT License
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Configuration variables
INSTALL_DIR="${DESTDIR:-/usr/local}"
BIN_DIR="${INSTALL_DIR}/bin"
MAN_DIR="${INSTALL_DIR}/share/man/man1"
BASH_COMPLETION_DIR="${INSTALL_DIR}/share/bash-completion/completions"
ZSH_COMPLETION_DIR="${INSTALL_DIR}/share/zsh/site-functions"
CONFIG_DIR="${HOME}/.config/li"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Global variables for selections
SELECTED_INSTALL_TYPE=""
SELECTED_THEME=""
SELECTED_ICONS=""
SELECTED_GIT=""
# Print functions
print_header() {
echo ""
echo -e "${CYAN}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}${BOLD}║ ║${NC}"
echo -e "${CYAN}${BOLD}║ Li Installation Script ║${NC}"
echo -e "${CYAN}${BOLD}║ ║${NC}"
echo -e "${CYAN}${BOLD}║ Enhanced Directory Listing Tool v2.0.0 ║${NC}"
echo -e "${CYAN}${BOLD}║ ║${NC}"
echo -e "${CYAN}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
print_step() {
echo -e "${BLUE}[*]${NC} $1"
}
print_success() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[✗]${NC} $1"
}
print_info() {
echo -e "${CYAN}[i]${NC} $1"
}
# Interactive prompt function
prompt_yes_no() {
local prompt="$1"
local default="${2:-n}"
if [ "$default" = "y" ]; then
local options="[Y/n]"
else
local options="[y/N]"
fi
while true; do
echo -ne "${YELLOW}${prompt} ${options}: ${NC}"
read -r response
response=${response:-${default}}
case "$response" in
[Yy])
return 0
;;
[Nn])
return 1
;;
*)
print_error "Please enter 'y' or 'n'"
;;
esac
done
}
# Check for root privileges
check_root() {
print_step "Checking for root privileges..."
if [ "$EUID" -ne 0 ]; then
if prompt_yes_no "This installation requires root privileges. Continue with sudo?" "y"; then
SUDO="sudo"
print_info "Using sudo for installation"
else
print_error "Installation cancelled. Root privileges are required."
exit 1
fi
else
SUDO=""
print_success "Running as root"
fi
}
# Check for dependencies
check_dependencies() {
print_step "Checking dependencies..."
local missing=()
# Check for C++ compiler
if ! command -v g++ &> /dev/null && ! command -v clang++ &> /dev/null; then
missing+=("C++ compiler (g++ or clang++)")
fi
# Check for make
if ! command -v make &> /dev/null; then
missing+=("make")
fi
# Check for git (optional)
if ! command -v git &> /dev/null; then
print_warning "git not found - some features may be limited"
fi
if [ ${#missing[@]} -gt 0 ]; then
print_error "Missing dependencies:"
for dep in "${missing[@]}"; do
echo " - $dep"
done
if prompt_yes_no "Install missing dependencies?" "y"; then
if command -v apt-get &> /dev/null; then
$SUDO apt-get update
$SUDO apt-get install -y build-essential
elif command -v yum &> /dev/null; then
$SUDO yum install -y gcc-c++ make
elif command -v dnf &> /dev/null; then
$SUDO dnf install -y gcc-c++ make
elif command -v pacman &> /dev/null; then
$SUDO pacman -Sy --noconfirm base-devel
elif command -v zypper &> /dev/null; then
$SUDO zypper install -y -t pattern devel_basis
else
print_error "Cannot install dependencies automatically. Please install manually."
exit 1
fi
else
print_error "Cannot proceed without required dependencies."
exit 1
fi
else
print_success "All dependencies satisfied"
fi
}
# Build the project
build_project() {
print_step "Building li..."
cd "$SCRIPT_DIR"
if [ ! -f "Makefile" ]; then
print_error "Makefile not found in $SCRIPT_DIR"
exit 1
fi
# Clean previous build
if [ -f "li" ] || [ -d "obj" ]; then
if prompt_yes_no "Clean previous build?" "y"; then
print_info "Cleaning previous build..."
make clean 2>/dev/null || true
fi
fi
# Compile
print_info "Compiling li..."
if make; then
print_success "Build completed successfully"
else
print_error "Build failed"
exit 1
fi
if [ ! -f "li" ]; then
print_error "Binary 'li' not found after build"
exit 1
fi
print_info "Binary size: $(du -h li | cut -f1)"
}
# Configure installation
configure_installation() {
print_step "Configuring installation options..."
echo ""
echo -e "${YELLOW}Installation Settings:${NC}"
echo ""
echo -e "${YELLOW}Select installation type:${NC}"
echo ""
echo " 1) System-wide (requires root)"
echo " 2) User only (no root required)"
echo ""
while true; do
echo -ne "${YELLOW}Enter choice [1-2]: ${NC}"
read -r response
case "$response" in
1)
SELECTED_INSTALL_TYPE="system"
print_info "System-wide installation"
break
;;
2)
SELECTED_INSTALL_TYPE="user"
INSTALL_DIR="${HOME}/.local"
SUDO=""
print_info "Installing to ${INSTALL_DIR}"
break
;;
*)
print_error "Invalid choice. Please enter 1 or 2"
;;
esac
done
# Update directories
BIN_DIR="${INSTALL_DIR}/bin"
MAN_DIR="${INSTALL_DIR}/share/man/man1"
BASH_COMPLETION_DIR="${INSTALL_DIR}/share/bash-completion/completions"
ZSH_COMPLETION_DIR="${INSTALL_DIR}/share/zsh/site-functions"
CONFIG_DIR="${HOME}/.config/li"
echo ""
# Icon support
if prompt_yes_no "Enable file type icons by default?" "y"; then
SELECTED_ICONS="true"
else
SELECTED_ICONS="false"
fi
# Git integration
if prompt_yes_no "Enable git integration by default?" "y"; then
SELECTED_GIT="true"
else
SELECTED_GIT="false"
fi
# Color scheme
echo ""
echo -e "${YELLOW}Select default color scheme:${NC}"
echo ""
echo " 1) Dark (for dark terminal backgrounds)"
echo " 2) Light (for light terminal backgrounds)"
echo " 3) Auto (detect from terminal)"
echo ""
while true; do
echo -ne "${YELLOW}Enter choice [1-3]: ${NC}"
read -r response
case "$response" in
1)
SELECTED_THEME="dark"
print_info "Theme: dark"
break
;;
2)
SELECTED_THEME="light"
print_info "Theme: light"
break
;;
3)
SELECTED_THEME="auto"
print_info "Theme: auto"
break
;;
*)
print_error "Invalid choice. Please enter 1, 2, or 3"
;;
esac
done
}
# Install binary
install_binary() {
print_step "Installing binary to ${BIN_DIR}..."
$SUDO mkdir -p "$BIN_DIR"
if $SUDO cp li "$BIN_DIR/" && $SUDO chmod 755 "$BIN_DIR/li"; then
print_success "Binary installed to ${BIN_DIR}/li"
else
print_error "Failed to install binary"
exit 1
fi
# Verify installation
if [ -x "$BIN_DIR/li" ]; then
print_success "Binary is executable"
print_info "Version: $("$BIN_DIR/li" --version 2>&1 | head -1)"
fi
}
# Install man page
install_manpage() {
print_step "Installing man page..."
if [ ! -f "doc/li.1" ]; then
print_warning "Man page not found, skipping..."
return
fi
$SUDO mkdir -p "$MAN_DIR"
if $SUDO cp doc/li.1 "$MAN_DIR/" 2>/dev/null; then
print_success "Man page installed to ${MAN_DIR}/li.1"
# Update man database
if command -v mandb &> /dev/null; then
print_info "Updating man database..."
$SUDO mandb -q 2>/dev/null || true
fi
else
print_warning "Could not install man page"
fi
}
# Install shell completions
install_completions() {
print_step "Installing shell completions..."
local bash_installed=false
local zsh_installed=false
# Bash completion
if [ -f "doc/completion/li.bash" ]; then
$SUDO mkdir -p "$BASH_COMPLETION_DIR"
if $SUDO cp doc/completion/li.bash "$BASH_COMPLETION_DIR/" 2>/dev/null; then
print_success "Bash completion installed"
bash_installed=true
fi
fi
# Zsh completion
if [ -f "doc/completion/li.zsh" ]; then
$SUDO mkdir -p "$ZSH_COMPLETION_DIR"
if $SUDO cp doc/completion/li.zsh "$ZSH_COMPLETION_DIR/_li" 2>/dev/null; then
print_success "Zsh completion installed"
zsh_installed=true
fi
fi
if [ "$bash_installed" = false ] && [ "$zsh_installed" = false ]; then
print_warning "No shell completions installed"
fi
}
# Create default configuration
create_config() {
print_step "Creating default configuration..."
mkdir -p "$CONFIG_DIR"
cat > "$CONFIG_DIR/config.ini" << EOF
# Li Configuration File
# Generated by install script
[general]
theme=${SELECTED_THEME}
show_hidden=false
show_inode=false
long_format=false
recursive=false
human_readable=true
dirs_first=true
show_icons=${SELECTED_ICONS}
show_colors=true
sort_by=name
reverse_sort=false
time_style=long-iso
enable_git=${SELECTED_GIT}
[colors]
dir_color=blue
file_color=white
exec_color=green
link_color=cyan
special_color=yellow
EOF
print_success "Configuration created at ${CONFIG_DIR}/config.ini"
}
# Update shell profile
update_shell_profile() {
print_step "Updating shell profile..."
local path_line='export PATH="$HOME/.local/bin:$PATH"'
local profile_updated=false
# Update .bashrc
if [ -f "$HOME/.bashrc" ]; then
if ! grep -q "$HOME/.local/bin" "$HOME/.bashrc" 2>/dev/null; then
echo "" >> "$HOME/.bashrc"
echo "# Li installation" >> "$HOME/.bashrc"
echo "$path_line" >> "$HOME/.bashrc"
print_success "Updated .bashrc"
profile_updated=true
fi
fi
# Update .zshrc
if [ -f "$HOME/.zshrc" ]; then
if ! grep -q "$HOME/.local/bin" "$HOME/.zshrc" 2>/dev/null; then
echo "" >> "$HOME/.zshrc"
echo "# Li installation" >> "$HOME/.zshrc"
echo "$path_line" >> "$HOME/.zshrc"
print_success "Updated .zshrc"
profile_updated=true
fi
fi
if [ "$profile_updated" = false ]; then
print_warning "No shell profile updated. You may need to manually add:"
echo " $path_line"
fi
}
# Final checks
final_checks() {
print_step "Performing final checks..."
# Check if li is accessible
if command -v li &> /dev/null; then
print_success "li is accessible in PATH"
elif [ -x "$BIN_DIR/li" ]; then
print_info "li is installed at ${BIN_DIR}/li"
print_info "You may need to restart your terminal or run:"
echo " source ~/.bashrc # or ~/.zshrc"
fi
# Verify man page
if command -v man &> /dev/null && [ -f "$MAN_DIR/li.1" ]; then
print_success "Man page available. View with: man li"
fi
}
# Print summary
print_summary() {
echo ""
echo -e "${GREEN}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${BOLD}║ Installation Complete! ║${NC}"
echo -e "${GREEN}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}Installed files:${NC}"
echo " Binary: ${BIN_DIR}/li"
echo " Man page: ${MAN_DIR}/li.1"
echo " Config: ${CONFIG_DIR}/config.ini"
echo ""
echo -e "${CYAN}Quick usage:${NC}"
echo " li # List current directory"
echo " li -l # Long format"
echo " li -k /usr # Tree view"
echo " li --help # Show help"
echo ""
echo -e "${CYAN}For more information:${NC}"
echo " man li # Read manual"
echo " li --help # Quick help"
echo ""
}
# Main function
main() {
print_header
# Welcome message
echo -e "${BOLD}Welcome to the interactive installation of li!${NC}"
echo ""
echo "Li is a modern, feature-rich replacement for ls with:"
echo " • Beautiful colorized output"
echo " • File type icons (Nerd Fonts support)"
echo " • Multiple display modes (grid, tree, zebra)"
echo " • Git integration"
echo " • Extensive customization options"
echo ""
if ! prompt_yes_no "Proceed with installation?" "y"; then
echo "Installation cancelled."
exit 0
fi
echo ""
# Run installation steps
check_root
check_dependencies
build_project
configure_installation
install_binary
install_manpage
install_completions
create_config
# Only update shell profile for user installation
if [ "$SELECTED_INSTALL_TYPE" = "user" ]; then
update_shell_profile
fi
final_checks
print_summary
# Restart prompt
if [ "$SELECTED_INSTALL_TYPE" = "user" ]; then
if prompt_yes_no "Restart your shell to apply PATH changes?" "y"; then
exec "$SHELL"
fi
fi
}
# Run main function
main "$@"