summaryrefslogtreecommitdiff
path: root/scripts/pkg-update
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pkg-update')
-rwxr-xr-xscripts/pkg-update107
1 files changed, 107 insertions, 0 deletions
diff --git a/scripts/pkg-update b/scripts/pkg-update
new file mode 100755
index 0000000..bdf47f5
--- /dev/null
+++ b/scripts/pkg-update
@@ -0,0 +1,107 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# Colors for terminal output
+RED='\e[31m'
+GREEN='\e[32m'
+YELLOW='\e[33m'
+BLUE='\e[34m'
+BOLD='\e[1m'
+RESET='\e[0m'
+
+# Track if any errors occurred
+ERRORS=0
+
+# Function to print section headers
+print_header() {
+ echo -e "${BOLD}${BLUE}"
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+ echo -e "$1"
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+ echo -e "${RESET}"
+}
+
+print_success() {
+ echo -e "${GREEN}✓ $1${RESET}"
+}
+
+print_error() {
+ echo -e "${RED}✗ $1${RESET}"
+ ERRORS=$((ERRORS + 1))
+}
+
+print_info() {
+ echo -e "${YELLOW}ℹ $1${RESET}"
+}
+
+# Main update process
+print_header "System Package Update"
+
+# Update system packages
+echo -e "${GREEN}Updating system packages...${RESET}\n"
+if sudo pacman -Syu --noconfirm; then
+ print_success "System packages updated"
+else
+ print_error "Failed to update system packages"
+fi
+
+echo
+
+# Update AUR packages
+print_header "AUR Package Update"
+
+if ! command -v yay >/dev/null 2>&1; then
+ print_info "yay is not installed, skipping AUR updates"
+elif ! pacman -Qem >/dev/null 2>&1; then
+ print_info "No AUR packages installed, skipping AUR updates"
+else
+ echo -e "${GREEN}Updating AUR packages...${RESET}\n"
+ if yay -Sua --noconfirm; then
+ print_success "AUR packages updated"
+ else
+ print_error "Failed to update some AUR packages"
+ fi
+fi
+
+echo
+
+# Clean up orphans
+print_header "Cleanup Orphaned Packages"
+
+orphans=$(pacman -Qtdq 2>/dev/null || true)
+
+if [[ -z "$orphans" ]]; then
+ print_info "No orphaned packages found"
+else
+ echo -e "${YELLOW}Found orphaned packages:${RESET}"
+ echo "$orphans" | sed 's/^/ - /'
+ echo
+ echo -e "${GREEN}Removing orphaned packages...${RESET}\n"
+ if sudo pacman -Rns --noconfirm $orphans 2>/dev/null; then
+ print_success "Orphaned packages removed"
+ else
+ print_error "Failed to remove some orphaned packages"
+ fi
+fi
+
+echo
+
+# Final summary
+print_header "Update Summary"
+
+if [[ $ERRORS -eq 0 ]]; then
+ echo -e "${GREEN}${BOLD}✓ All operations completed successfully!${RESET}"
+else
+ echo -e "${YELLOW}${BOLD} Completed with $ERRORS error(s)${RESET}"
+fi
+
+echo
+
+# Keep window open until user dismisses
+if command -v gum >/dev/null 2>&1; then
+ gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s'
+else
+ echo -e "${BLUE}Press any key to close this window...${RESET}"
+ read -n 1 -s
+fi