nirish

config files for niri window manager
Log | Files | Refs | README | LICENSE

pkg-update (2607B)


      1 #!/usr/bin/env bash
      2 
      3 set -euo pipefail
      4 
      5 # Colors for terminal output
      6 RED='\e[31m'
      7 GREEN='\e[32m'
      8 YELLOW='\e[33m'
      9 BLUE='\e[34m'
     10 BOLD='\e[1m'
     11 RESET='\e[0m'
     12 
     13 # Track if any errors occurred
     14 ERRORS=0
     15 
     16 # Function to print section headers
     17 print_header() {
     18 	echo -e "${BOLD}${BLUE}"
     19 	echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
     20 	echo -e "$1"
     21 	echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
     22 	echo -e "${RESET}"
     23 }
     24 
     25 print_success() {
     26 	echo -e "${GREEN}✓ $1${RESET}"
     27 }
     28 
     29 print_error() {
     30 	echo -e "${RED}✗ $1${RESET}"
     31 	ERRORS=$((ERRORS + 1))
     32 }
     33 
     34 print_info() {
     35 	echo -e "${YELLOW}ℹ $1${RESET}"
     36 }
     37 
     38 # Main update process
     39 print_header "System Package Update"
     40 
     41 # Update system packages
     42 echo -e "${GREEN}Updating system packages...${RESET}\n"
     43 if sudo pacman -Syu --noconfirm; then
     44 	print_success "System packages updated"
     45 else
     46 	print_error "Failed to update system packages"
     47 fi
     48 
     49 echo
     50 
     51 # Update AUR packages
     52 print_header "AUR Package Update"
     53 
     54 if ! command -v {yay,paru} >/dev/null 2>&1; then
     55 	print_info "Both yay and paru are not installed, skipping AUR updates"
     56 elif ! pacman -Qem >/dev/null 2>&1; then
     57 	print_info "No AUR packages installed, skipping AUR updates"
     58 else
     59 	echo -e "${GREEN}Updating AUR packages...${RESET}\n"
     60 	if yay -Sua --noconfirm; then
     61 		print_success "AUR packages updated"
     62 	elif paru -Sua --noconfirm; then
     63 		print_success "AUR packages updated"
     64 	else
     65 		print_error "Failed to update some AUR packages"
     66 	fi
     67 fi
     68 
     69 echo
     70 
     71 # Clean up orphans
     72 print_header "Cleanup Orphaned Packages"
     73 
     74 orphans=$(pacman -Qtdq 2>/dev/null || true)
     75 
     76 if [[ -z "$orphans" ]]; then
     77 	print_info "No orphaned packages found"
     78 else
     79 	echo -e "${YELLOW}Found orphaned packages:${RESET}"
     80 	echo "$orphans" | sed 's/^/  - /'
     81 	echo
     82 	echo -e "${GREEN}Removing orphaned packages...${RESET}\n"
     83 	if sudo pacman -Rns --noconfirm "$orphans" 2>/dev/null; then
     84 		print_success "Orphaned packages removed"
     85 	else
     86 		print_error "Failed to remove some orphaned packages"
     87 	fi
     88 fi
     89 
     90 echo
     91 
     92 # Final summary
     93 print_header "Update Summary"
     94 
     95 if [[ $ERRORS -eq 0 ]]; then
     96 	echo -e "${GREEN}${BOLD}✓ All operations completed successfully!${RESET}"
     97 else
     98 	echo -e "${YELLOW}${BOLD} Completed with $ERRORS error(s)${RESET}"
     99 fi
    100 
    101 echo
    102 
    103 # Keep window open until user dismisses
    104 if command -v gum >/dev/null 2>&1; then
    105 	gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s'
    106 else
    107 	echo -e "${BLUE}Press any key to close this window...${RESET}"
    108 	read -n 1 -s
    109 fi