mirror of
https://github.com/Snigdha-OS/snigdhaos-default-settings.git
synced 2025-09-21 00:54:55 +02:00
🛠 refactor(bump): rename and modify script
This commit is contained in:
78
usr/local/bin/snigdhaos-cleanup.sh
Normal file → Executable file
78
usr/local/bin/snigdhaos-cleanup.sh
Normal file → Executable file
@@ -22,31 +22,63 @@ error_handler() {
|
|||||||
# Trap errors and call error_handler
|
# Trap errors and call error_handler
|
||||||
trap 'error_handler $LINENO' ERR
|
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
|
# Ensure the script is run as root for certain actions
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo -e "${RED}❌ Please run this script as root or with sudo.${RESET}"
|
echo -e "${RED}❌ Please run this script as root or with sudo.${RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# Function to calculate space freed
|
||||||
calculate_space_freed() {
|
calculate_space_freed() {
|
||||||
local before_size
|
local before_size
|
||||||
local after_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
|
# Running cleanup functions
|
||||||
clean_package_cache
|
clean_package_cache
|
||||||
@@ -55,11 +87,27 @@ calculate_space_freed() {
|
|||||||
clean_application_caches
|
clean_application_caches
|
||||||
clean_trash
|
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}"
|
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}"
|
echo -e "${BLUE}🧹 Starting cleanup process...${RESET}"
|
||||||
|
|
||||||
# Function to clean package cache
|
# Function to clean package cache
|
||||||
|
82
usr/local/bin/snigdhaos-uninstall-package.sh
Executable file
82
usr/local/bin/snigdhaos-uninstall-package.sh
Executable file
@@ -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 <package_name>"
|
||||||
|
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}<package_name>${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 <package_name>"
|
||||||
|
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
|
69
usr/local/bin/snigdhaos-update.sh
Executable file
69
usr/local/bin/snigdhaos-update.sh
Executable file
@@ -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
|
@@ -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 <package_name>"
|
|
||||||
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
|
|
@@ -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
|
|
Reference in New Issue
Block a user