diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb3c83c --- /dev/null +++ b/README.md @@ -0,0 +1,179 @@ +# Simplify and Beautify Your Linux Terminal Experience ✨ + +> [!TIP] +> Having issues? Please open an issue here: [https://github.com/StianNOR/Homelab/issues](https://github.com/StianNOR/Homelab/issues) +> Or join the community on Discord: [https://discord.gg/eHEHCzGCAE](https://discord.gg/eHEHCzGCAE) + +--- + +## Supported Package Managers ✅ + +| Package Manager | Distros | +|-----------------|-------------------------------------------| +| **APT** | Debian, Ubuntu, Linux Mint, Pop!_OS, Deepin, etc | +| **DNF** | Fedora, CentOS 8+, RHEL 8+, Rocky Linux, AlmaLinux, etc | +| **YUM** | CentOS 7, older RHEL versions, Oracle Linux, etc | +| **Pacman** | Arch Linux, Manjaro, EndeavourOS, Artix Linux, etc | +| **Zypper** | openSUSE, SUSE Linux Enterprise, etc | + +--- + +## Clone, Verify, and Install Homelab ✅ + +### Script Authenticity ⚠️ + +All scripts in this repository are digitally signed with my Keybase-managed PGP key. +This ensures the scripts you download are authentic and haven’t been tampered with. + +### Clone and Prepare +``` +cd ~ # Go to your home directory (check with 'pwd') +git clone https://github.com/StianNOR/Homelab.git +cd Homelab +sudo chmod +x *.sh +``` + +### Import My Public Key + +PGP fingerprint: +`52FE58C1C8BDA54D68E09C143E305BD749B795A3` + +``` +curl https://keybase.io/sarttech7/pgp_keys.asc | gpg --import + +``` + + +### Verify Scripts + + +``` +gpg --verify signatures/setup_zsh.sh.asc setup_zsh.sh +gpg --verify signatures/up.sh.asc up.sh +gpg --verify signatures/portainerup.sh.asc portainerup.sh +gpg --verify signatures/portainer_docker_uninstall.sh.asc portainer_docker_uninstall.sh +gpg --verify signatures/uninstall_zsh_setup.sh.asc uninstall_zsh_setup.sh +gpg --verify signatures/font_nerd_hack.sh.sig font_nerd_hack.sh +``` + + +Expected output: + +`Good signature from "StianNOR stiannor@duck.com"` + + + +> [!IMPORTANT] +> You may see this warning: +> `WARNING: This key is not certified with a trusted signature!` +> +> This simply means GPG does not yet fully trust the key. +> To mark it as trusted locally: +> ``` +> gpg --edit-key 3E305BD749B795A3 +> trust +> # Select option 5 (ultimate trust) +> y +> quit +> ``` +> Only assign ultimate trust to keys you have personally verified. + +--- + +## Installation Steps + +1. **Install the Nerd Hack Font** + +``` +./font_nerd_hack.sh +``` + +Configure the font in your system settings and terminal preferences. +A reboot is usually required. + +2. **Run the Main Setup Script** +``` +./setup_zsh.sh +``` + +After installation, reboot or log out/in to apply the changes. + +--- + +## Portainer and Docker Installation ✅ + +If you want to install Docker and Portainer, simply run `pup` in the terminal and follow the prompts. + +- When asked to reboot or relog, do so. +- If prompted, also run: +``` +newgrp docker +``` + +- Successful setup will display a confirmation message in the terminal. + +Later, you can also update Portainer by running: + + + +--- + +## Uninstall Options 😦 + +**Remove Portainer and Docker:** +``` +./portainer_docker_uninstall.sh +``` + + +**Uninstall the Zsh Setup (restart terminal afterward):** +``` +./uninstall_zsh_setup.sh +``` + + +--- + +## Helpful Shortcuts 🤓 + +**Show active Zsh aliases:** +``` +ali +``` + + +**Directory listing shortcuts:** + +| Command | Expands to | Description | +|---------|-----------------|------------------------------------------| +| `ls` | `ls` | List files and directories | +| `ll` | `ls -l` | Detailed long format | +| `la` | `ls -a` / `ls -la` | Show all files, including hidden ones | +| `sls` | `ls -ls` | Show listings with file sizes and details | + +--- + +## Author + +Best regards, +**StianNOR** +(Known as *sarttech7* on Keybase) +[https://keybase.io/sarttech7](https://keybase.io/sarttech7) + +--- + +## Disclaimer ⚠️ + +This script is provided *as-is* for supported Linux distributions. +While tested on common setups, it may not work for all configurations. + +- Always back up important data before running these scripts. +- The author accepts no responsibility for data loss or damage. +- If unsure, test first in a virtual machine or safe environment. +- This project is fully open and free to use, intended only for educational and community purposes — never for harmful activities. + + +| Before | After | +| :---: | :---: | +| ![Before Image]() | ![After Image]() | + diff --git a/Standard Terminal.png b/Standard Terminal.png new file mode 100644 index 0000000..b2c9634 Binary files /dev/null and b/Standard Terminal.png differ diff --git a/setup_zsh.sh b/setup_zsh.sh new file mode 100644 index 0000000..cd6c454 --- /dev/null +++ b/setup_zsh.sh @@ -0,0 +1,257 @@ +#!/bin/bash +set -e +set -o pipefail + +# --- Colors and Formatting --- +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +BOLD='\033[1m' +RESET='\033[0m' + +info() { echo -e "${CYAN}ℹ️ $*${RESET}"; } +success() { echo -e "${GREEN}✅ $*${RESET}"; } +warn() { echo -e "${YELLOW}⚠️ $*${RESET}"; } +error() { echo -e "${RED}❌ $*${RESET}"; } +step() { echo -e "${BOLD}${BLUE}➤ $*${RESET}"; } + +# --- Global error trap for fail-safe --- +trap '{ + error "Script failed at line $LINENO. Last command: $BASH_COMMAND" + warn "Try running the failed command manually, or check your package manager and sudo configuration." + warn "If on Arch/Manjaro, check pacman locks and mirrors. If on Ubuntu/Debian, check apt sources and network." + exit 1 +}' ERR + +# ----- 1. Detect package manager ----- +step "Detecting package manager..." +if command -v apt >/dev/null 2>&1; then + PM="apt" + UPDATE="sudo apt update" + INSTALL="sudo apt install -y" + CLEAN="sudo apt clean" + AUTOREMOVE="sudo apt autoremove -y" +elif command -v dnf >/dev/null 2>&1; then + PM="dnf" + UPDATE="sudo dnf check-update || true" + INSTALL="sudo dnf install -y" + CLEAN="sudo dnf clean all" + AUTOREMOVE="sudo dnf autoremove -y" +elif command -v yum >/dev/null 2>&1; then + PM="yum" + UPDATE="sudo yum check-update || true" + INSTALL="sudo yum install -y" + CLEAN="sudo yum clean all" + AUTOREMOVE="sudo yum autoremove -y" +elif command -v pacman >/dev/null 2>&1; then + PM="pacman" + UPDATE="sudo pacman -Syu --noconfirm" + INSTALL="sudo pacman -S --noconfirm" + CLEAN="sudo pacman -Sc --noconfirm" + ORPHANS="$(pacman -Qtdq 2>/dev/null || true)" + if [[ -n "$ORPHANS" ]]; then + AUTOREMOVE="sudo pacman -Rns $ORPHANS --noconfirm" + else + AUTOREMOVE="echo 'No orphaned packages to remove.'" + fi +elif command -v zypper >/dev/null 2>&1; then + PM="zypper" + UPDATE="sudo zypper refresh" + INSTALL="sudo zypper install -y" + CLEAN="sudo zypper clean" + AUTOREMOVE="sudo zypper rm -u" +else + error "No supported package manager found." + exit 1 +fi +success "Detected package manager: $PM" + +# ----- 2. Install zsh if missing ----- +step "Ensuring zsh is installed..." +if ! command -v zsh >/dev/null 2>&1; then + info "zsh not found, installing..." + if ! $INSTALL zsh; then + error "Failed to install zsh." + exit 1 + fi + success "zsh installed." +else + success "zsh is already installed." +fi + +# ----- 3. Install dependencies ----- +step "Updating package lists and installing dependencies..." +if ! $UPDATE; then + error "Package manager update failed. Check your network, mirrors, and sudo permissions." + exit 1 +fi +success "Package manager updated." + +if [[ "$PM" == "pacman" ]]; then + if ! $INSTALL curl git ruby gcc make; then + error "Dependency install failed. Check pacman output." + exit 1 + fi +else + if ! $INSTALL curl git ruby ruby-devel gcc make && ! $INSTALL ruby ruby-dev gcc make; then + error "Dependency install failed. Check package manager output." + exit 1 + fi +fi +success "Dependencies installed." + +# ----- 4. Update RubyGems and all gems ----- +step "Updating RubyGems and all installed gems..." +if [[ "$PM" == "apt" ]]; then + warn "RubyGems system update is disabled on Debian/Ubuntu. Use apt to update rubygems if needed." +else + if gem update --system; then + success "RubyGems system updated." + else + warn "RubyGems system update failed or is not supported on this distribution." + fi +fi + +if gem update; then + success "All installed gems updated." +else + warn "Gem update failed. Some gems may not have been updated." +fi + +# ----- 5. Install colorls (user install, not sudo) ----- +step "Checking for colorls Ruby gem..." +export GEM_HOME="$HOME/.gem" +export PATH="$PATH:$GEM_HOME/bin" + +if ! gem list -i colorls >/dev/null 2>&1; then + info "Installing colorls Ruby gem for your user..." + if ! gem install --user-install colorls; then + error "colorls install failed. Check Ruby/gem output." + exit 1 + fi + success "colorls installed." +else + success "colorls is already installed." +fi + +USER_GEM_BIN="$(ruby -e 'puts Gem.user_dir')/bin" +if ! grep -q "$USER_GEM_BIN" "$HOME/.zshrc"; then + echo "export PATH=\"\$PATH:$USER_GEM_BIN\"" >> "$HOME/.zshrc" + info "Added $USER_GEM_BIN to your PATH in .zshrc" +fi + +if ! command -v colorls >/dev/null 2>&1; then + warn "colorls binary not found in PATH. You may need to restart your shell or source your .zshrc." +fi + +# ----- 6. Install fastfetch ----- +step "Checking for fastfetch..." +if ! command -v fastfetch >/dev/null 2>&1; then + info "fastfetch not found in PATH. Trying to install via package manager..." + if $INSTALL fastfetch; then + success "fastfetch installed via package manager." + else + warn "Fastfetch package install failed or not available in your repo." + echo -e "${YELLOW}Please install fastfetch manually and then re-run this script.${RESET}" + exit 1 + fi +else + success "fastfetch is already installed." +fi + +# ----- 7. Install Oh My Zsh ----- +step "Checking for Oh My Zsh..." +if [ ! -f "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]; then + info "Installing Oh My Zsh..." + rm -rf "$HOME/.oh-my-zsh" + if ! RUNZSH=no KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"; then + error "Oh My Zsh install failed." + exit 1 + fi + success "Oh My Zsh installed." +else + success "Oh My Zsh is already installed." +fi + +ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" + +# ----- 8. Install Powerlevel10k theme ----- +step "Checking for Powerlevel10k theme..." +if [ ! -d "$ZSH_CUSTOM/themes/powerlevel10k" ]; then + info "Installing Powerlevel10k theme..." + if ! git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM/themes/powerlevel10k"; then + error "Powerlevel10k install failed." + exit 1 + fi + success "Powerlevel10k installed." +else + success "Powerlevel10k theme is already installed." +fi + +# ----- 9. Install plugins ----- +step "Checking for Zsh plugins..." +declare -A plugins +plugins=( + [zsh-autosuggestions]="https://github.com/zsh-users/zsh-autosuggestions" + [zsh-syntax-highlighting]="https://github.com/zsh-users/zsh-syntax-highlighting" + [zsh-completions]="https://github.com/zsh-users/zsh-completions" +) + +for plugin in "${!plugins[@]}"; do + if [ ! -d "$ZSH_CUSTOM/plugins/$plugin" ]; then + info "Installing plugin: $plugin" + if ! git clone "${plugins[$plugin]}" "$ZSH_CUSTOM/plugins/$plugin"; then + error "Plugin $plugin install failed." + exit 1 + fi + success "Plugin $plugin installed." + else + success "Plugin $plugin is already installed." + fi +done + +# ----- 10. Copy .zshrc and .p10k.zsh from repo with error checking ----- +step "Copying .zshrc and .p10k.zsh from repo..." +SCRIPT_DIR="$HOME/Homelab" +REPO_ZSHRC="$SCRIPT_DIR/.zshrc" +DEST_ZSHRC="$HOME/.zshrc" +REPO_P10K="$SCRIPT_DIR/.p10k.zsh" +DEST_P10K="$HOME/.p10k.zsh" + +if [ -f "$REPO_ZSHRC" ]; then + cp "$REPO_ZSHRC" "$DEST_ZSHRC" + success ".zshrc copied to $DEST_ZSHRC" +else + warn "$REPO_ZSHRC not found. .zshrc was NOT copied." + ls -l "$SCRIPT_DIR" +fi + +if [ -f "$REPO_P10K" ]; then + cp "$REPO_P10K" "$DEST_P10K" + success ".p10k.zsh copied to $DEST_P10K" +else + warn "No .p10k.zsh found in $SCRIPT_DIR. Skipping." +fi + +# ----- 11. Change default shell to zsh if not already ----- +step "Checking default shell..." +if [ "$SHELL" != "$(which zsh)" ]; then + if chsh -s "$(which zsh)"; then + info "Default shell changed to zsh. Please log out and log in again for changes to take effect." + else + warn "Could not change default shell. You may need to do it manually." + fi +else + success "zsh is already the default shell." +fi + +echo -e "${GREEN}${BOLD} +🎉 All Zsh plugins, Powerlevel10k, colorls, fastfetch, and up.sh are installed and configured! 🎉 +${RESET}" + +echo -e "${CYAN}The up.sh script is now located in: ~/Homelab/up.sh${RESET}" +echo -e "${CYAN}Refreshing your shell in 3 seconds...${RESET}" +sleep 3 +exec zsh diff --git a/uninstall_zsh_setup.sh b/uninstall_zsh_setup.sh new file mode 100644 index 0000000..dd143c7 --- /dev/null +++ b/uninstall_zsh_setup.sh @@ -0,0 +1,94 @@ +#!/bin/bash +set -e # Exit immediately if a command exits with a non-zero status + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BOLD='\033[1m' +NC='\033[0m' # No Color + +info() { echo -e "${YELLOW}ℹ️ $*${NC}"; } +success() { echo -e "${GREEN}✅ $*${NC}"; } +warn() { echo -e "${YELLOW}⚠️ $*${NC}"; } +error() { echo -e "${RED}❌ $*${NC}"; } +step() { echo -e "${BOLD}${YELLOW}--- $* ---${NC}"; } + +step "Uninstalling Zsh/Powerlevel10k setup and related tools" + +# 1. Remove Oh My Zsh directory +info "Removing Oh My Zsh directory..." +if [ -d "$HOME/.oh-my-zsh" ]; then + rm -rf "$HOME/.oh-my-zsh" + success "Oh My Zsh directory removed." +else + warn "Oh My Zsh directory not found." +fi + +# 2. Remove Zsh configuration files +info "Removing Zsh configuration files..." +ZSH_CONFIG_FILES=("$HOME/.zshrc" "$HOME/.zshenv" "$HOME/.zprofile" "$HOME/.zlogin" "$HOME/.p10k.zsh") +for file in "${ZSH_CONFIG_FILES[@]}"; do + if [ -f "$file" ]; then + rm -f "$file" + success "Removed $file" + else + warn "$file not found." + fi +done + +# 3. Remove up.sh maintenance script +info "Removing up.sh maintenance script..." +if [ -f "$HOME/Documents/up.sh" ]; then + rm -f "$HOME/Documents/up.sh" + success "up.sh maintenance script removed." +else + warn "up.sh maintenance script not found." +fi + +# 4. Uninstall colorls (user gem) +info "Uninstalling colorls Ruby gem..." +# Ensure GEM_HOME and PATH are set correctly for user gems +export GEM_HOME="$HOME/.gem" +export PATH="$PATH:$GEM_HOME/bin" +if gem list -i colorls >/dev/null 2>&1; then + if gem uninstall colorls; then # Removed -x and sudo + success "colorls uninstalled." + else + error "Failed to uninstall colorls." + fi +else + warn "colorls gem not found." +fi + +# 5. Uninstall fastfetch +info "Uninstalling fastfetch..." +if command -v fastfetch >/dev/null 2>&1; then + # Assume it was installed via the curl installer which puts files in /usr/local + if sudo rm -f /usr/local/bin/fastfetch && sudo rm -rf /usr/local/share/fastfetch; then + success "fastfetch uninstalled." + else + error "Failed to remove fastfetch binaries. Manual removal may be needed." + fi +else + warn "fastfetch not found." +fi + + +# 6. Optionally restore default shell to bash +# Check if zsh is the current default shell before attempting to change +CURRENT_DEFAULT_SHELL=$(getent passwd "$USER" | awk -F: '{print $NF}') +if [ "$CURRENT_DEFAULT_SHELL" != "/bin/bash" ] && [ -f "/bin/bash" ]; then + info "Restoring default shell to /bin/bash..." + if chsh -s /bin/bash "$USER"; then # Specify user for chsh + success "Default shell changed to /bin/bash." + echo -e "${GREEN}Please log out and log in again for shell changes to take effect.${NC}" + else + error "Failed to change default shell to /bin/bash. You may need to do it manually." + fi +else + success "Default shell is already /bin/bash or /bin/bash not found." +fi + +echo -e "${BOLD}${GREEN}✅ Uninstallation complete.${NC}" +echo -e "${BOLD}${GREEN}Note: Log out and log back in for shell changes to fully apply.${NC}" diff --git a/up.sh b/up.sh new file mode 100644 index 0000000..3a691dc --- /dev/null +++ b/up.sh @@ -0,0 +1,188 @@ +#!/bin/bash +set -e + +# --- Colors and Formatting --- +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +BOLD='\033[1m' +RESET='\033[0m' + +info() { echo -e "${BLUE}ℹ $*${RESET}"; } +success() { echo -e "${GREEN}✅ $*${RESET}"; } +warn() { echo -e "${YELLOW}⚠ $*${RESET}"; } +error() { echo -e "${RED}❌ $*${RESET}"; } + +# --- Detect Package Manager --- +info "Detecting package manager..." +if command -v nala &>/dev/null; then + PM="nala" +elif command -v apt &>/dev/null; then + PM="apt" +elif command -v dnf &>/dev/null; then + PM="dnf" +elif command -v yum &>/dev/null; then + PM="yum" +elif command -v pacman &>/dev/null; then + PM="pacman" +elif command -v zypper &>/dev/null; then + PM="zypper" +else + error "No supported package manager found (apt/nala/dnf/yum/pacman/zypper)." + exit 1 +fi +success "Detected: $PM" + +# --- System Update and Cleanup --- +info "Starting system update and maintenance..." + +# Update and upgrade system +case "$PM" in + nala) + info "Updating package list and upgrading system (nala)..." + sudo nala update + sudo nala upgrade -y + sudo nala autoremove -y --purge + sudo nala clean + ;; + apt) + info "Updating package list and upgrading system (apt)..." + sudo apt update + sudo apt upgrade -y + sudo apt autoremove -y --purge + sudo apt clean + ;; + dnf) + info "Updating and cleaning system (dnf)..." + sudo dnf upgrade --refresh -y + sudo dnf autoremove -y + sudo dnf clean all + ;; + yum) + info "Updating and cleaning system (yum)..." + sudo yum update -y + sudo yum autoremove -y + sudo yum clean all + ;; + pacman) + info "Updating and cleaning system (pacman)..." + sudo pacman -Syu --noconfirm + sudo pacman -Rns $(pacman -Qtdq) --noconfirm 2>/dev/null || true + sudo pacman -Sc --noconfirm + ;; + zypper) + info "Updating and cleaning system (zypper)..." + sudo zypper refresh + sudo zypper update -y + sudo zypper clean --all + ;; +esac + +# --- Docker System Prune --- +if command -v docker &>/dev/null; then + info "Pruning Docker system..." + sudo docker system prune -a -f --volumes + success "Docker system pruned." +else + warn "Docker not installed. Skipping Docker prune." +fi + +# --- Flatpak Update --- +if command -v flatpak &>/dev/null; then + info "Updating Flatpak packages..." + flatpak update -y + success "Flatpak packages updated." +else + warn "Flatpak not installed. Skipping Flatpak update." +fi + +# --- Snap Update --- +if command -v snap &>/dev/null; then + info "Updating Snap packages..." + sudo snap refresh + success "Snap packages updated." +else + warn "Snap not installed. Skipping Snap update." +fi + +# --- Clean Journal Logs --- +info "Cleaning journal logs (older than 7 days)..." +sudo journalctl --vacuum-time=7d +success "Journal logs cleaned." + +# --- Clean Thumbnails Cache --- +info "Cleaning thumbnails cache..." +rm -rf ~/.cache/thumbnails/* +success "Thumbnails cache cleaned." + +# --- Clean Temporary Files --- +info "Cleaning /tmp and user cache..." +sudo rm -rf /tmp/* ~/.cache/* +success "Temporary files and cache cleaned." + +# --- Update Locate Database --- +info "Updating locate database..." +if command -v updatedb &>/dev/null; then + sudo updatedb +else + info "Installing mlocate/plocate for 'updatedb'..." + case "$PM" in + apt|nala) + sudo apt install -y plocate || sudo apt install -y mlocate + ;; + dnf) + sudo dnf install -y plocate || sudo dnf install -y mlocate + ;; + yum) + sudo yum install -y mlocate + ;; + pacman) + sudo pacman -S --noconfirm mlocate + ;; + zypper) + sudo zypper install -y mlocate + ;; + esac + sudo updatedb +fi +success "Locate database updated." + +# --- Remove Orphaned Packages (Pacman/DNF) --- +case "$PM" in + pacman) + info "Removing orphaned packages (pacman)..." + sudo pacman -Rns $(pacman -Qtdq) --noconfirm 2>/dev/null || true + ;; + dnf) + info "Removing orphaned packages (dnf)..." + sudo dnf remove --unused -y + ;; +esac + +# --- Check if Restart is Recommended --- +REBOOT_REQUIRED=false + +# Check for kernel updates (Debian/Ubuntu) +if [ -f /var/run/reboot-required ]; then + REBOOT_REQUIRED=true +fi + +# Check for pending Docker daemon restart +if sudo systemctl is-active docker >/dev/null 2>&1 && [ -n "$(sudo docker info 2>/dev/null | grep 'Pending updates')" ]; then + REBOOT_REQUIRED=true +fi + +# Check for other common restart triggers (e.g., glibc, systemd) +if [ -f /var/run/reboot-required.pkgs ]; then + REBOOT_REQUIRED=true +fi + +# --- Final Message --- +echo -e "${GREEN}${BOLD}✅ System update and maintenance completed!${RESET}" +if [ "$REBOOT_REQUIRED" = true ]; then + warn "⚠ A system restart is recommended to apply all updates (e.g., kernel, Docker, or critical libraries)." + warn " This is especially important for cryptocurrency nodes, Proxmox, and UniFi services." +else + echo -e "${GREEN}✅ No restart required.${RESET}" +fi