diff --git a/usr/local/bin/snigdhaos-cleanup.sh b/usr/local/bin/snigdhaos-cleanup.sh old mode 100644 new mode 100755 index 8a6016b..35563c5 --- a/usr/local/bin/snigdhaos-cleanup.sh +++ b/usr/local/bin/snigdhaos-cleanup.sh @@ -22,31 +22,63 @@ error_handler() { # Trap errors and call error_handler trap 'error_handler $LINENO' ERR +# Function to display help message +show_help() { + echo -e "${BLUE}Usage: ${RESET}snigdhaos-cleanup.sh [OPTIONS]" + echo -e "" + echo -e "${GREEN}This script will clean up your system by deleting unused package caches, crash reports, application logs, application caches, and trash.${RESET}" + echo -e "" + echo -e "${YELLOW}Options:${RESET}" + echo -e " ${GREEN}-h, --help${RESET} Show this help message." + echo -e " ${GREEN}-v, --version${RESET} Display the script version." + echo -e " ${GREEN}-f, --force${RESET} Skip confirmation prompt and force cleanup." + echo -e "" + echo -e "Example usage:" + echo -e " snigdhaos-cleanup.sh # Starts the cleanup process with a confirmation prompt." + echo -e " snigdhaos-cleanup.sh -f # Skips the confirmation and forces cleanup." +} + +# Function to display version information +show_version() { + echo -e "${BLUE}Version: 1.0.0${RESET}" +} + +# Parse command line options +FORCE_CLEAN=false +while [[ "$#" -gt 0 ]]; do + case "$1" in + -h|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -f|--force) + FORCE_CLEAN=true + shift + ;; + *) + echo -e "${RED}โŒ Unknown option: $1${RESET}" + show_help + exit 1 + ;; + esac +done + # Ensure the script is run as root for certain actions if [ "$EUID" -ne 0 ]; then echo -e "${RED}โŒ Please run this script as root or with sudo.${RESET}" exit 1 fi -echo -e "${YELLOW}โš ๏ธ WARNING: This script will permanently delete unnecessary files, logs, and caches to free up disk space.${RESET}" -echo -e "${BLUE}๐Ÿ‘‰ The following will be cleaned:${RESET}" -echo -e "${GREEN} - Package cache${RESET}" -echo -e "${GREEN} - Crash reports${RESET}" -echo -e "${GREEN} - Application logs${RESET}" -echo -e "${GREEN} - Application caches${RESET}" -echo -e "${GREEN} - Trash${RESET}" -read -p "$(echo -e "${YELLOW}โ“ Are you sure you want to proceed? [y/N]: ${RESET}")" CONFIRM -if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then - echo -e "${RED}โŒ Cleanup operation cancelled.${RESET}" - exit 0 -fi - # Function to calculate space freed calculate_space_freed() { local before_size local after_size - before_size=$(du -sh / | awk '{print $1}') + before_size=$(du -sh --exclude=/proc --exclude=/sys --exclude=/run --exclude=/tmp / | awk '{print $1}') # Running cleanup functions clean_package_cache @@ -55,11 +87,27 @@ calculate_space_freed() { clean_application_caches clean_trash - after_size=$(du -sh / | awk '{print $1}') + after_size=$(du -sh --exclude=/proc --exclude=/sys --exclude=/run --exclude=/tmp / | awk '{print $1}') echo -e "${GREEN}Space freed: $before_size -> $after_size${RESET}" } +# Prompt for confirmation if not forced +if ! $FORCE_CLEAN; then + echo -e "${YELLOW}โš ๏ธ WARNING: This script will permanently delete unnecessary files, logs, and caches to free up disk space.${RESET}" + echo -e "${BLUE}๐Ÿ‘‰ The following will be cleaned:${RESET}" + echo -e "${GREEN} - Package cache${RESET}" + echo -e "${GREEN} - Crash reports${RESET}" + echo -e "${GREEN} - Application logs${RESET}" + echo -e "${GREEN} - Application caches${RESET}" + echo -e "${GREEN} - Trash${RESET}" + read -p "$(echo -e "${YELLOW}โ“ Are you sure you want to proceed? [y/N]: ${RESET}")" CONFIRM + if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then + echo -e "${RED}โŒ Cleanup operation cancelled.${RESET}" + exit 0 + fi +fi + echo -e "${BLUE}๐Ÿงน Starting cleanup process...${RESET}" # Function to clean package cache diff --git a/usr/local/bin/snigdhaos-uninstall-package.sh b/usr/local/bin/snigdhaos-uninstall-package.sh new file mode 100755 index 0000000..36ef5d7 --- /dev/null +++ b/usr/local/bin/snigdhaos-uninstall-package.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# Author : Eshan Roy +# Author URL : https://eshanized.github.io/ + +set -e # Exit immediately if a command exits with a non-zero status + +# Colors +RED="\033[1;31m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +RESET="\033[0m" + +# Function to display error message and exit +error_handler() { + echo -e "\n${RED}๐Ÿšจ An error occurred during the uninstallation process.${RESET}" + echo -e "${RED}Error on line $1. Please check your system and try again.${RESET}" + exit 1 +} + +# Trap errors and call error_handler +trap 'error_handler $LINENO' ERR + +# Function to display help message +show_help() { + echo -e "${BLUE}Usage: ${RESET}$0 " + echo -e "" + echo -e "${GREEN}This script will uninstall the specified package, remove its cache, and clean up orphaned packages.${RESET}" + echo -e "" + echo -e "${YELLOW}Options:${RESET}" + echo -e " ${GREEN}-h, --help${RESET} Show this help message." + echo -e " ${GREEN}${RESET} The package to uninstall." + echo -e "" + echo -e "${YELLOW}Example usage:${RESET}" + echo -e " $0 firefox # Uninstalls the Firefox package and its cache." + echo -e " $0 -h # Displays this help message." +} + +# Parse command line options +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + show_help + exit 0 +fi + +# Ensure the script is run as root for certain actions +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}โŒ Please run this script as root or with sudo.${RESET}" + exit 1 +fi + +# Check if a package name is provided +if [ -z "$1" ]; then + echo -e "${RED}โŒ No package specified.${RESET}" + echo -e "Usage: $0 " + exit 1 +fi + +PACKAGE=$1 + +# Confirm with the user +echo -e "${YELLOW}โš ๏ธ WARNING: This script will uninstall the specified package and remove its cache.${RESET}" +read -p "$(echo -e "${BLUE}Are you sure you want to uninstall $PACKAGE and remove its cache? [y/N]: ${RESET}")" CONFIRM +if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then + echo -e "${RED}โŒ Operation cancelled.${RESET}" + exit 0 +fi + +# Uninstall the package and its dependencies +echo -e "${BLUE}๐Ÿ“ฆ Uninstalling $PACKAGE...${RESET}" +sudo pacman -Rns $PACKAGE --noconfirm || { echo -e "${RED}โŒ Failed to uninstall $PACKAGE.${RESET}"; exit 1; } + +# Remove the package's cache +echo -e "${BLUE}๐Ÿ—‘๏ธ Removing cache for $PACKAGE...${RESET}" +sudo pacman -Sc --noconfirm || echo -e "${YELLOW}โ— Cache removal skipped.${RESET}" + +# Clean up orphaned packages +echo -e "${BLUE}๐Ÿงน Cleaning up orphaned packages...${RESET}" +sudo pacman -Rns $(pacman -Qtdq) --noconfirm || echo -e "${YELLOW}No orphaned packages to remove.${RESET}" + +echo -e "\n${GREEN}โœ… Package $PACKAGE successfully uninstalled!${RESET}" +exit 0 diff --git a/usr/local/bin/snigdhaos-update.sh b/usr/local/bin/snigdhaos-update.sh new file mode 100755 index 0000000..cbf8393 --- /dev/null +++ b/usr/local/bin/snigdhaos-update.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Author : Eshan Roy +# Author URL : https://eshanized.github.io/ + +# Colors +RED="\033[1;31m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +RESET="\033[0m" + +# Function to display error message and exit +error_handler() { + echo -e "\n${RED}๐Ÿšจ An error occurred during the update process.${RESET}" + echo -e "${RED}Error on line $1. Please check your system and try again.${RESET}" + exit 1 +} + +# Trap errors and call error_handler +trap 'error_handler $LINENO' ERR + +# Function to display help message +show_help() { + echo -e "${BLUE}Usage: ${RESET}$0" + echo -e "" + echo -e "${GREEN}This script will update the package database, upgrade all installed packages, and clean up orphaned packages.${RESET}" + echo -e "" + echo -e "${YELLOW}Options:${RESET}" + echo -e " ${GREEN}-h, --help${RESET} Show this help message." + echo -e "" + echo -e "${YELLOW}Example usage:${RESET}" + echo -e " $0 # Updates the system and removes orphaned packages." + echo -e " $0 -h # Displays this help message." +} + +# Parse command line options +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + show_help + exit 0 +fi + +# Ensure the script is run as root for certain actions +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}โŒ Please run this script as root or with sudo.${RESET}" + exit 1 +fi + +# Warning before starting +echo -e "${YELLOW}โš ๏ธ WARNING: This script will update your system, upgrade installed packages, and clean up orphaned packages.${RESET}" +read -p "$(echo -e "${BLUE}Are you sure you want to proceed? [y/N]: ${RESET}")" CONFIRM +if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then + echo -e "${RED}โŒ Operation cancelled.${RESET}" + exit 0 +fi + +# Update the package database and upgrade packages +echo -e "${BLUE}๐Ÿ”„ Updating the package database...${RESET}" +sudo pacman -Sy || { echo -e "${RED}โŒ Failed to update the package database.${RESET}"; exit 1; } + +echo -e "${BLUE}๐Ÿ“ฆ Upgrading installed packages...${RESET}" +sudo pacman -Su --noconfirm || { echo -e "${RED}โŒ Failed to upgrade packages.${RESET}"; exit 1; } + +# Clean up orphaned packages +echo -e "${BLUE}๐Ÿงน Cleaning up orphaned packages...${RESET}" +sudo pacman -Rns $(pacman -Qtdq) --noconfirm || echo -e "${YELLOW}No orphaned packages to remove.${RESET}" + +echo -e "\n${GREEN}โœ… System successfully updated!${RESET}" +exit 0 diff --git a/usr/local/bin/uninstall-package.sh b/usr/local/bin/uninstall-package.sh deleted file mode 100644 index 6ca553f..0000000 --- a/usr/local/bin/uninstall-package.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# Author : Eshan Roy -# Author URL : https://eshanized.github.io/ - -set -e # Exit immediately if a command exits with a non-zero status - -# Function to display error message and exit -error_handler() { - echo -e "\n๐Ÿšจ An error occurred during the uninstallation process." - echo "Error on line $1. Please check your system and try again." - exit 1 -} - -# Trap errors and call error_handler -trap 'error_handler $LINENO' ERR - -# Ensure the script is run as root -if [ "$EUID" -ne 0 ]; then - echo "โŒ Please run this script as root or with sudo." - exit 1 -fi - -# Check if a package name is provided -if [ -z "$1" ]; then - echo "โŒ No package specified." - echo "Usage: $0 " - exit 1 -fi - -PACKAGE=$1 - -# Confirm with the user -read -p "Are you sure you want to uninstall $PACKAGE and remove its cache? [y/N]: " CONFIRM -if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then - echo "โŒ Operation cancelled." - exit 0 -fi - -# Uninstall the package and its dependencies -echo "๐Ÿ“ฆ Uninstalling $PACKAGE..." -sudo pacman -Rns $PACKAGE --noconfirm || { echo "โŒ Failed to uninstall $PACKAGE."; exit 1; } - -# Remove the package's cache -echo "๐Ÿ—‘๏ธ Removing cache for $PACKAGE..." -sudo pacman -Sc --noconfirm || echo "โ— Cache removal skipped." - -# Clean up orphaned packages -echo "๐Ÿงน Cleaning up orphaned packages..." -sudo pacman -Rns $(pacman -Qtdq) --noconfirm || echo "No orphaned packages to remove." - -echo -e "\nโœ… Package $PACKAGE successfully uninstalled!" -exit 0 diff --git a/usr/local/bin/update-snigdha-os.sh b/usr/local/bin/update-snigdha-os.sh deleted file mode 100644 index 245d373..0000000 --- a/usr/local/bin/update-snigdha-os.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# Author : Eshan Roy -# Author URL : https://eshanized.github.io/ - -# Shell script to update all Snigdha OS packages with error handling - -set -e # Exit immediately if a command exits with a non-zero status - -# Function to display error message and exit -error_handler() { - echo -e "\n๐Ÿšจ An error occurred during the update process." - echo "Error on line $1. Please check your system and try again." - exit 1 -} - -# Trap errors and call error_handler -trap 'error_handler $LINENO' ERR - -# Ensure the script is run as root -if [ "$EUID" -ne 0 ]; then - echo "โŒ Please run this script as root or with sudo." - exit 1 -fi - -# Update the package database and upgrade packages -echo "๐Ÿ”„ Updating the package database..." -sudo pacman -Sy || { echo "โŒ Failed to update the package database."; exit 1; } - -echo "๐Ÿ“ฆ Upgrading installed packages..." -sudo pacman -Su --noconfirm || { echo "โŒ Failed to upgrade packages."; exit 1; } - -# Clean up orphaned packages -echo "๐Ÿงน Cleaning up orphaned packages..." -sudo pacman -Rns $(pacman -Qtdq) --noconfirm || echo "No orphaned packages to remove." - -echo -e "\nโœ… System successfully updated!" -exit 0