diff --git a/README.md b/README.md index 1b46233..430ff5b 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,193 @@ # awk_linux_scripts -## My handy linux scripts -I wrote them to make it easier for me to update my linux (zorin OS) machine from the terminal. - -### Scripts: -- **showhardware.sh**: Displays detailed hardware information, including: - - System information - - Hardware details (bus info) - - BIOS and system enclosure information - - CPU information - - Memory usage -- **checkforupdates.sh**: Updates the system by: - - Running `apt update` and `apt upgrade` to update and upgrade packages - - Cleaning up unused packages with `apt autoclean` and `apt autoremove` - - Refreshing Snap packages (if Snap is installed) - - Upgrading Flatpak packages (if Flatpak is installed) - -### Setup: -1) Extract files from the zip file. -2) Open a terminal. -3) Create a directory for the scripts: + +[![Bash](https://img.shields.io/badge/Bash-5.1+-green?style=flat&logo=gnu-bash&logoColor=white)](https://www.gnu.org/software/bash/) +[![Linux](https://img.shields.io/badge/Linux-Ubuntu%20%26%20Debian-orange?style=flat&logo=linux&logoColor=white)](https://www.linux.org/) +[![Zorin OS](https://img.shields.io/badge/Zorin%20OS-Supported-blue?style=flat&logo=linux&logoColor=white)](https://zorinos.com/) +[![License](https://img.shields.io/badge/License-MIT-blue?style=flat)](LICENSE) + +Handy Linux maintenance scripts to make system administration easier from the terminal. Originally written for Zorin OS and other Debian-based distributions. + +## Table of Contents +- [Overview](#overview) +- [Prerequisites](#prerequisites) +- [Scripts](#scripts) +- [Installation](#installation) +- [Usage](#usage) +- [Troubleshooting](#troubleshooting) +- [Uninstallation](#uninstallation) + +## Overview + +This collection provides convenient terminal tools for: +- Quick access to detailed hardware information +- Automated system updates and cleanup + +## Compatibility + +These scripts are designed for **Ubuntu-based Linux distributions**, including: +- **Ubuntu** (20.04 LTS and later) +- **Zorin OS** +- **Linux Mint** +- **Elementary OS** +- **Pop!_OS** +- Any other Debian/Ubuntu-based distribution using `apt` package manager + +The scripts use `apt` for package management, so they are **not compatible** with distributions using `dnf` (Fedora, RHEL) or `pacman` (Arch). + +## Prerequisites + +These scripts require the following packages to be installed: + +```bash +sudo apt install lshw dmidecode +``` + +## Scripts + +### `showhardware.sh` + +Displays comprehensive hardware and system information in one command. + +**Displays:** +- System information (kernel version, OS, architecture) +- Hardware bus information +- BIOS and system enclosure details +- CPU information (cores, cache, frequency) +- Memory usage and availability +- Disk usage information +- Network interface information + +**Features:** +- Error handling: stops on first error +- Privilege verification: ensures it's run with sudo +- Clean formatted output with visual section separators + +**Usage:** +```bash +sudo showhardware.sh +``` + +> **Note:** The script must be run with `sudo` and will verify privileges before proceeding. + +### `checkforupdates.sh` + +Automated system update and maintenance script. Performs package updates, cleanup, and refreshes Snap/Flatpak packages if installed. + +**Performs:** +- Package list updates (`apt update`) +- System upgrades (`apt upgrade`) +- Unused package cleanup (`apt autoclean` and `apt autoremove`) +- Snap package refresh (if installed) +- Flatpak package upgrade (if installed) + +**Features:** +- Error handling: stops on first error +- Privilege verification: ensures it's run with sudo +- Detailed status messages +- Automated dependency cleanup (may override some APT safety checks; review changes carefully before proceeding) + +**Usage:** +```bash +sudo checkforupdates.sh +``` + +> **Note:** The script must be run with `sudo` and will verify privileges before proceeding. + +## Installation + +1. Clone or extract files into a directory: ```bash mkdir -p ~/scripts + cd ~/scripts + # Copy files here or git clone ``` -4) Move the extracted files into `~/scripts`: + +2. Make scripts executable: ```bash - mv /path/to/extracted/files/* ~/scripts + chmod +x ~/scripts/*.sh ``` -5) Make the scripts executable: + +3. Add directory to PATH (choose one method): + + **Option A: Bash (for ~/.bashrc)** ```bash - chmod og+x ~/scripts/*.sh + echo 'export PATH=~/scripts:$PATH' >> ~/.bashrc + source ~/.bashrc ``` -6) Add the scripts directory to your PATH: + + **Option B: Bash Profile (for ~/.bash_profile)** ```bash echo 'export PATH=~/scripts:$PATH' >> ~/.bash_profile + source ~/.bash_profile ``` -7) Reload your shell configuration: + + **Option C: System-wide (requires sudo)** ```bash - source ~/.bash_profile + for f in "$HOME"/scripts/*.sh; do + sudo ln -s "$f" "/usr/local/bin/$(basename "$f" .sh)" + done ``` + +4. Verify installation: + ```bash + sudo showhardware + ``` + +## Usage + +Run scripts from any terminal window: + +```bash +# Show hardware information (requires sudo) +sudo showhardware + +# Update the system (requires sudo) +sudo checkforupdates +``` + +## Troubleshooting + +**Scripts not found after installation:** +- Verify PATH was updated: `echo $PATH | grep scripts` +- Restart terminal for changes to take effect +- Try opening a new terminal window + +**"Permission denied" errors:** +- Ensure scripts are executable: `chmod +x ~/scripts/*.sh` +- For system-wide installation, you need sudo + +**"sudo: command not found":** +- Verify script is in a directory in your PATH: `which showhardware` +- Add the directory to PATH (see Installation section) + +**`lshw` or `dmidecode` commands not found:** +- Install required packages: `sudo apt install lshw dmidecode` + +**`checkforupdates` exits early:** +- The script uses error handling and stops on first error +- Check the output for which command failed +- Review system logs if needed: `journalctl -xe` + +## Uninstallation + +Remove installed scripts: + +```bash +rm ~/scripts/showhardware.sh ~/scripts/checkforupdates.sh +``` + +If symlinked to `/usr/local/bin/`: +```bash +sudo rm /usr/local/bin/showhardware /usr/local/bin/checkforupdates +``` + +Remove from PATH (if using ~/.bashrc or ~/.bash_profile): +```bash +# Edit ~/.bashrc or ~/.bash_profile and remove the PATH line +sudo vi ~/.bashrc +# Find and delete: export PATH=~/scripts:$PATH +``` + +## Credits + +These scripts were enhanced with assistance from [GitHub Copilot](https://github.com/features/copilot), an AI-powered code assistant. Improvements include error handling, security checks, better formatting, and additional functionality. diff --git a/checkforupdates.sh b/checkforupdates.sh index 56b6662..210b2e7 100644 --- a/checkforupdates.sh +++ b/checkforupdates.sh @@ -1,23 +1,38 @@ #!/usr/bin/bash -sudo apt update -sudo apt upgrade --assume-yes -sudo apt autoclean -sudo apt autoremove +set -e + +# Check if running with sudo privileges +if [[ $EUID -ne 0 ]]; then + echo "This script must be run with sudo privileges." + exit 1 +fi + +echo "=== System Update Started ===" + +echo "Updating package lists..." +apt update + +echo "Upgrading packages..." +apt upgrade -y + +echo "Cleaning apt cache..." +apt autoclean --yes +apt autoremove --yes # Check for Snap if command -v snap &> /dev/null; then - echo "Snap Refresh" - sudo snap refresh + echo "Refreshing Snap packages..." + snap refresh --stable else echo "Snap is not installed." fi # Check for Flatpak if command -v flatpak &> /dev/null; then - echo "FlatPak Refresh" - sudo flatpak upgrade + echo "Refreshing Flatpak packages..." + flatpak upgrade --assumeyes else echo "Flatpak is not installed." fi -exit +echo "=== System Update Completed Successfully ===" \ No newline at end of file diff --git a/showhardware.sh b/showhardware.sh index 52ec577..aae7999 100644 --- a/showhardware.sh +++ b/showhardware.sh @@ -1,20 +1,33 @@ #!/usr/bin/bash +set -e -echo "System Information:" +# Check if running with sudo privileges (required for lshw and dmidecode) +if [[ $EUID -ne 0 ]]; then + echo "This script must be run with sudo privileges." + exit 1 +fi + +# Section separators for better readability +HEADER="\n====================" +FOOTER="====================\n" + +printf "$HEADER System Information $FOOTER" uname -a -echo -echo "Hardware Details:" -sudo lshw -businfo -echo +printf "$HEADER Hardware Details $FOOTER" +lshw -businfo -echo "BIOS and System Enclosure Information:" -sudo dmidecode --type 0,1,3 -echo +printf "$HEADER BIOS and System Enclosure Information $FOOTER" +dmidecode --type 0,1,3 -echo "CPU Information:" +printf "$HEADER CPU Information $FOOTER" lscpu -echo -echo "Memory Information:" +printf "$HEADER Memory Information $FOOTER" free -h + +printf "$HEADER Disk Usage $FOOTER" +df -h / + +printf "$HEADER Network Interfaces $FOOTER" +ip -br addr