diff --git a/debian.sh b/debian.sh index 25336e59..1b13798c 100755 --- a/debian.sh +++ b/debian.sh @@ -9,7 +9,7 @@ PURPLE='\033[0;35m' CYAN='\033[0;36m' NC='\033[0m' # No Color -trap "echo -e '${RED}install.sh interrupted.${NC}'; exit 1" SIGINT SIGTERM +trap "echo -e '${RED}debian.sh interrupted.${NC}'; exit 1" SIGINT SIGTERM PS3="Debian Sources: " options=("Stable" "Testing") diff --git a/install.sh b/install.sh index fcb7b1dc..844bd939 100755 --- a/install.sh +++ b/install.sh @@ -74,7 +74,6 @@ else fi mkdir -p "$HOME/dotfiles/logs" -source scripts/fetch printf "${CYAN}\n" printf "####################\n" diff --git a/scripts/battery b/scripts/battery index 3a4d5d33..91ef79dc 100755 --- a/scripts/battery +++ b/scripts/battery @@ -6,7 +6,7 @@ YELLOW="\e[33m" MAGENTA="\e[35m" CYAN="\e[36m" BOLD="\e[1m" -ENDCOLOR="\e[0m" +NC="\e[0m" BATTERY_INFO=$(upower -i $(upower -e | grep 'BAT')) BATTERY_PERCENT=$(echo "$BATTERY_INFO" | grep -oP 'percentage:\s+\K\d+') @@ -24,10 +24,10 @@ else COLOR=$RED fi -echo -e "${BOLD}Battery: ${COLOR}$BATTERY_PERCENT% ($BATTERY_STATUS)${ENDCOLOR}" +echo -e "${BOLD}Battery: ${COLOR}$BATTERY_PERCENT% ($BATTERY_STATUS)${NC}" if [ -n "$CHARGE_CYCLES" ]; then - echo -e "${BOLD}Charge Cycles: ${MAGENTA}$CHARGE_CYCLES${ENDCOLOR}" + echo -e "${BOLD}Charge Cycles: ${MAGENTA}$CHARGE_CYCLES${NC}" fi if [ "$WARNING_LEVEL" != "none" ]; then - echo -e "${BOLD}Warning Level: ${RED}$WARNING_LEVEL${ENDCOLOR}" + echo -e "${BOLD}Warning Level: ${RED}$WARNING_LEVEL${NC}" fi diff --git a/scripts/build-new-kernel b/scripts/build-new-kernel index 4b8f277f..bea971d2 100755 --- a/scripts/build-new-kernel +++ b/scripts/build-new-kernel @@ -1,13 +1,13 @@ #! /bin/bash YELLOW="\e[33m" -ENDCOLOR="\e[0m" +NC="\e[0m" -echo -e "\n${YELLOW}Downloading APT dependencies...${ENDCOLOR}\n" +echo -e "\n${YELLOW}Downloading APT dependencies...${NC}\n" sudo apt install build-essential git -y sudo apt build-dep linux -y -echo -e "\n${YELLOW}Downloading kernel source...${ENDCOLOR}\n" +echo -e "\n${YELLOW}Downloading kernel source...${NC}\n" mkdir linux-parent && cd linux-parent git clone --depth 1 https://github.com/torvalds/linux cd linux @@ -26,14 +26,14 @@ scripts/config --set-val DEBUG_INFO_NONE y scripts/config --set-val DEBUG_INFO_DWARF5 n scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -echo -e "\n${YELLOW}Compiling the kernel...${ENDCOLOR}\n" +echo -e "\n${YELLOW}Compiling the kernel...${NC}\n" make -j$(nproc) deb-pkg LOCALVERSION=-custom -echo -e "\n${YELLOW}Installing the generated dpkg packages...${ENDCOLOR}\n" +echo -e "\n${YELLOW}Installing the generated dpkg packages...${NC}\n" sudo dpkg -i ../linux-headers*-custom*.deb sudo dpkg -i ../linux-image*-custom*.deb -echo -e "\n${YELLOW}Cleaning up...${ENDCOLOR}\n" +echo -e "\n${YELLOW}Cleaning up...${NC}\n" cd ../.. rm -rf linux-parent diff --git a/scripts/cpu b/scripts/cpu deleted file mode 100755 index 585ad514..00000000 --- a/scripts/cpu +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# Script to display CPU usage - -RED="\e[31m" -GREEN="\e[32m" -YELLOW="\e[33m" -CYAN="\e[36m" -ENDCOLOR="\e[0m" - -# Cache in tmpfs to improve speed and reduce SSD load -cache=/tmp/cpu-script-cache -rm /tmp/cpu-script-cache 2>/dev/null -while true; do - sleep 1 - cpu_stats=$(awk '/^cpu / {print $2 + $3 + $4 + $5, $5}' /proc/stat) - if [ ! -f "$cache" ]; then - echo -n "  ${CYAN}--%${ENDCOLOR} \r" - echo "$cpu_stats" >"$cache" - continue - fi - prev_stats=$(cat "$cache") - total=$(echo "$prev_stats" | awk '{print $1}') - prev_idle=$(echo "$prev_stats" | awk '{print $2}') - curr_total=$(echo "$cpu_stats" | awk '{print $1}') - curr_idle=$(echo "$cpu_stats" | awk '{print $2}') - total_diff=$((curr_total - total)) - idle_diff=$((curr_idle - prev_idle)) - - if [ "$total_diff" -eq 0 ]; then - usage=0 # Avoid division by zero - else - usage=$((100 * (total_diff - idle_diff) / total_diff)) - fi - - if [ "$usage" -lt 50 ]; then - echo -n "  ${GREEN}${usage}%${ENDCOLOR} \r" - elif [ "$usage" -lt 70 ]; then - echo -n "  ${YELLOW}${usage}%${ENDCOLOR} \r" - else - echo -n "  ${RED}${usage}%${ENDCOLOR} \r" - fi - echo "$cpu_stats" >"$cache" -done diff --git a/scripts/fetch b/scripts/fetch index a3aea8db..b67d18bc 100755 --- a/scripts/fetch +++ b/scripts/fetch @@ -7,49 +7,49 @@ YELLOW="\e[33m" MAGENTA="\e[35m" CYAN="\e[36m" BOLD="\e[1m" -ENDCOLOR="\e[0m" +NC="\e[0m" # User and host info -echo -e "${BOLD}${MAGENTA}${USER}@$(hostname)${ENDCOLOR}" +echo -e "${BOLD}${MAGENTA}${USER}@$(hostname)${NC}" echo "---------" # OS and architecture OS=$(grep '^PRETTY_NAME=' /etc/os-release | cut -d= -f2 | tr -d '"') ARCH=$(uname -m) -echo -e "${CYAN}OS:${ENDCOLOR} $OS $ARCH" +echo -e "${CYAN}OS:${NC} $OS $ARCH" # Host Model HOST_MODEL=$(cat /sys/class/dmi/id/product_name 2>/dev/null) HOST_VERSION=$(cat /sys/class/dmi/id/product_version 2>/dev/null) -echo -e "${CYAN}Host:${ENDCOLOR} ${HOST_VERSION} (${HOST_MODEL})" +echo -e "${CYAN}Host:${NC} ${HOST_VERSION} (${HOST_MODEL})" # Kernel version -echo -e "${CYAN}Kernel:${ENDCOLOR} Linux $(uname -r)" +echo -e "${CYAN}Kernel:${NC} Linux $(uname -r)" # Uptime UPTIME=$(uptime -p | sed 's/up //') -echo -e "${CYAN}Uptime:${ENDCOLOR} $UPTIME" +echo -e "${CYAN}Uptime:${NC} $UPTIME" # Package counts: dpkg and flatpak PKG_COUNT=$(dpkg-query -f '${binary:Package}\n' -W 2>/dev/null | wc -l) FLAT_COUNT=$(flatpak list 2>/dev/null | wc -l) -echo -e "${CYAN}Packages:${ENDCOLOR} ${PKG_COUNT} (dpkg), ${FLAT_COUNT} (flatpak)" +echo -e "${CYAN}Packages:${NC} ${PKG_COUNT} (dpkg), ${FLAT_COUNT} (flatpak)" # Shell and version BASH_VER=$(bash --version | head -n1 | awk '{print $4}' | cut -d'(' -f1) -echo -e "${CYAN}Shell:${ENDCOLOR} bash ${BASH_VER}" +echo -e "${CYAN}Shell:${NC} bash ${BASH_VER}" # Desktop Environment DE=${XDG_CURRENT_DESKTOP:-"Unknown"} -echo -e "${CYAN}DE:${ENDCOLOR} $DE" +echo -e "${CYAN}DE:${NC} $DE" # CPU model from /proc/cpuinfo CPU=$(awk -F: '/model name/ {print $2; exit}' /proc/cpuinfo | sed 's/^[ \t]*//') -echo -e "${CYAN}CPU:${ENDCOLOR} $CPU" +echo -e "${CYAN}CPU:${NC} $CPU" # GPU info GPU=$(lspci | grep -i 'vga\|3d' | head -n1 | cut -d: -f3 | sed 's/^[ \t]*//') -echo -e "${CYAN}GPU:${ENDCOLOR} $GPU" +echo -e "${CYAN}GPU:${NC} $GPU" # Memory usage mem_info=$(free | awk '/Mem:/ {print $2, $3}') @@ -66,7 +66,7 @@ fi mem_total=$(free -h | awk '/Mem:/ {print $2}') mem_used=$(free -h | awk '/Mem:/ {print $3}') -echo -e "${CYAN}Memory:${ENDCOLOR} ${mem_used} / ${mem_total} (${percent_color}${percent}%${ENDCOLOR})" +echo -e "${CYAN}Memory:${NC} ${mem_used} / ${mem_total} (${percent_color}${percent}%${NC})" # Swap usage swap_used=$(free -h | awk '/Swap/ {print $3}') @@ -81,7 +81,7 @@ else swap_perc_color=$RED fi -echo -e "${CYAN}Swap:${ENDCOLOR} ${swap_used} / ${swap_total} (${swap_perc_color}${swap_perc}%${ENDCOLOR})" +echo -e "${CYAN}Swap:${NC} ${swap_used} / ${swap_total} (${swap_perc_color}${swap_perc}%${NC})" # Root disk usage root_line=$(df -h / | awk 'NR==2') @@ -95,7 +95,7 @@ elif [ "$root_percent" -le 80 ]; then else root_color=$RED fi -echo -e "${CYAN}Disk (/):${ENDCOLOR} ${root_used} / ${root_total} (${root_color}${root_percent}%${ENDCOLOR})" +echo -e "${CYAN}Disk (/):${NC} ${root_used} / ${root_total} (${root_color}${root_percent}%${NC})" # /home disk usage home_line=$(df -h /home 2>/dev/null | awk 'NR==2') @@ -110,7 +110,7 @@ if [ -n "$home_line" ]; then else home_color=$RED fi - echo -e "${CYAN}Disk (/home):${ENDCOLOR} ${home_used} / ${home_total} (${home_color}${home_percent}%${ENDCOLOR})" + echo -e "${CYAN}Disk (/home):${NC} ${home_used} / ${home_total} (${home_color}${home_percent}%${NC})" fi # Determine the primary network interface used for internet access @@ -118,11 +118,11 @@ PRIMARY_IFACE=$(ip route get 8.8.8.8 2>/dev/null | awk '{print $5; exit}') if [ -n "$PRIMARY_IFACE" ]; then LOCAL_IP=$(ip addr show "$PRIMARY_IFACE" | awk '/inet / {print $2}' | cut -d'/' -f1) - echo -e "${CYAN}Local IP ($PRIMARY_IFACE):${ENDCOLOR} ${LOCAL_IP}" + echo -e "${CYAN}Local IP ($PRIMARY_IFACE):${NC} ${LOCAL_IP}" else - echo -e "${RED}Local IP:${ENDCOLOR} Unable to determine primary network interface." + echo -e "${RED}Local IP:${NC} Unable to determine primary network interface." fi # Current locale setting LOCALE=$(locale | awk -F= '/^LANG=/{print $2; exit}') -echo -e "${CYAN}Locale:${ENDCOLOR} $LOCALE" +echo -e "${CYAN}Locale:${NC} $LOCALE" diff --git a/scripts/mem b/scripts/mem index 59e431fa..4430667e 100755 --- a/scripts/mem +++ b/scripts/mem @@ -3,20 +3,23 @@ RED="\e[31m" GREEN="\e[32m" YELLOW="\e[33m" -ENDCOLOR="\e[0m" +NC="\e[0m" mem_info=$(free | awk '/Mem:/ {print $2, $3}') read total used <<<"$mem_info" percent=$(awk "BEGIN {printf \"%.0f\", ($used/$total)*100}") -if [ "$percent" -le 60 ]; then - percent_color=$GREEN -elif [ "$percent" -le 80 ]; then - percent_color=$YELLOW -else - percent_color=$RED -fi - mem_total=$(free -h | awk '/Mem:/ {print $2}') mem_used=$(free -h | awk '/Mem:/ {print $3}') -echo -e " ${mem_used} / ${mem_total} (${percent_color}${percent}%${ENDCOLOR})" +if [[ -t 1 ]]; then + if [ "$percent" -le 60 ]; then + percent_color=$GREEN + elif [ "$percent" -le 80 ]; then + percent_color=$YELLOW + else + percent_color=$RED + fi + echo -e " ${mem_used} / ${mem_total} (${percent_color}${percent}%${NC})" +else + echo "${mem_used} ${mem_total} ${percent}" +fi diff --git a/scripts/mon b/scripts/mon new file mode 100755 index 00000000..9c9d0a2e --- /dev/null +++ b/scripts/mon @@ -0,0 +1,73 @@ +#! /bin/bash + +RED="\e[31m" +GREEN="\e[32m" +YELLOW="\e[33m" +CYAN="\e[36m" +NC="\e[0m" + +trap "echo -e '${CYAN}System Monitor interrupted.${NC}'; exit 1" SIGINT SIGTERM + +for i in {0..3}; do + echo +done + +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpu-script-cache +rm /tmp/cpu-script-cache 2>/dev/null +while true; do + # CPU + cpu_stats=$(awk '/^cpu / {print $2 + $3 + $4 + $5, $5}' /proc/stat) + if [ ! -f "$cache" ]; then + echo "$cpu_stats" >"$cache" + cpu_color=$CYAN + usage="--" + else + prev_stats=$(cat "$cache") + total=$(echo "$prev_stats" | awk '{print $1}') + prev_idle=$(echo "$prev_stats" | awk '{print $2}') + curr_total=$(echo "$cpu_stats" | awk '{print $1}') + curr_idle=$(echo "$cpu_stats" | awk '{print $2}') + total_diff=$((curr_total - total)) + idle_diff=$((curr_idle - prev_idle)) + + if [ "$total_diff" -eq 0 ]; then + usage=0 # Avoid division by zero + else + usage=$((100 * (total_diff - idle_diff) / total_diff)) + fi + + if [ "$usage" -lt 50 ]; then + cpu_color=$GREEN + elif [ "$usage" -lt 70 ]; then + cpu_color=$YELLOW + else + cpu_color=$RED + fi + fi + + # MEMORY + mem_info=$(free | awk '/Mem:/ {print $2, $3}') + read total used <<<"$mem_info" + percent=$(awk "BEGIN {printf \"%.0f\", ($used/$total)*100}") + + mem_total=$(free -h | awk '/Mem:/ {print $2}') + mem_used=$(free -h | awk '/Mem:/ {print $3}') + + if [ "$percent" -le 60 ]; then + mem_color=$GREEN + elif [ "$percent" -le 80 ]; then + mem_color=$YELLOW + else + mem_color=$RED + fi + + echo -ne "\033[4A" + echo -e "=============================" + echo -e " ${cpu_color}${usage}%${NC} " + echo -e " ${mem_used} / ${mem_total} (${mem_color}${percent}%${NC}) " + echo -e "=============================" + + echo "$cpu_stats" >"$cache" + sleep 2 +done diff --git a/scripts/p.sh b/scripts/p.sh index f3d50b23..bf204d90 100755 --- a/scripts/p.sh +++ b/scripts/p.sh @@ -14,7 +14,7 @@ FAINT="\e[2m" ITALIC="\e[3m" UNDERLINE="\e[4m" -ENDCOLOR="\e[0m" +NC="\e[0m" pcheck() { local pms=() @@ -46,12 +46,12 @@ p() ( updateP() { if [[ ${packageManagers[@]} =~ "flatpak" ]]; then - printf "%b\n" "${YELLOW}Updating flatpak...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating flatpak...${NC}" flatpak update flatpak uninstall --unused --delete-data fi if [[ ${packageManagers[@]} =~ "nix" ]]; then - printf "%b\n" "${YELLOW}Updating nix...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating nix...${NC}" nix-channel --update nix-collect-garbage --delete-older-than 7d &>/dev/null if command -v nixos-rebuild >/dev/null 2>&1; then @@ -63,20 +63,20 @@ p() ( fi fi if [[ ${packageManagers[@]} =~ "brew" ]]; then - printf "%b\n" "${YELLOW}Updating brew...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating brew...${NC}" brew update brew doctor brew upgrade fi if [[ ${packageManagers[@]} =~ "apt" ]]; then - printf "%b\n" "${YELLOW}Updating apt...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating apt...${NC}" sudo apt update sudo apt upgrade sudo apt dist-upgrade sudo apt autoremove sudo apt autoclean elif [[ ${packageManagers[@]} =~ "pacman" ]]; then - printf "%b\n" "${YELLOW}Updating pacman...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating pacman...${NC}" sudo sed -i 's/^#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf if [[ ${packageManagers[@]} =~ "paru" ]]; then paru -Syu @@ -85,7 +85,7 @@ p() ( fi sudo pacman -Rsn $(pacman -Qdtq) if [ ! "$(command -v reflector)" ]; then - printf "%b\n" "${YELLOW}Selecting fastest pacman mirrors...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Selecting fastest pacman mirrors...${NC}" sudo pacman -Sy --noconfirm reflector rsync curl iso=$(curl -4 ifconfig.co/country-iso) extra="FR" @@ -96,7 +96,7 @@ p() ( fi paccache -rk1 elif [[ ${packageManagers[@]} =~ "dnf" ]]; then - printf "%b\n" "${YELLOW}Updating dnf...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating dnf...${NC}" sudo dnf upgrade --refresh sudo dnf autoremove fi @@ -104,7 +104,7 @@ p() ( installP() { for pm in "${packageManagers[@]}"; do - printf "%b\n" "${YELLOW}Attempting ${pm} install...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Attempting ${pm} install...${NC}" case "$pm" in flatpak) flatpak install "$1" @@ -132,13 +132,13 @@ p() ( return 0 fi done - printf "%b\n" "${RED}ERROR: $1 not found.${ENDCOLOR}" + printf "%b\n" "${RED}ERROR: $1 not found.${NC}" return 1 } removeP() { for pm in "${packageManagers[@]}"; do - printf "%b\n" "${YELLOW}Attempting ${pm} uninstall...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Attempting ${pm} uninstall...${NC}" case "$pm" in flatpak) flatpak uninstall "$1" @@ -166,13 +166,13 @@ p() ( return 0 fi done - printf "%b\n" "${RED}ERROR: $1 not found.${ENDCOLOR}" + printf "%b\n" "${RED}ERROR: $1 not found.${NC}" return 1 } shellP() { if [[ ${packageManagers[@]} =~ "nix" ]]; then - printf "%b\n" "${YELLOW}Attempting to create nix shell...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Attempting to create nix shell...${NC}" nix-shell -p $1 if [[ $? == 0 ]]; then return 0 @@ -181,7 +181,7 @@ p() ( } # If no parameter or u - printf "%b\n" "${CYAN}Detected package managers: ${MAGENTA}${packageManagers[*]}${ENDCOLOR}" + printf "%b\n" "${CYAN}Detected package managers: ${MAGENTA}${packageManagers[*]}${NC}" if [ -z $1 ] || [ $1 = "u" ]; then updateP return 0 @@ -204,12 +204,12 @@ p() ( shift shellP $@ else - printf "%b\n" "${YELLOW}${UNDERLINE}[i] Usage:${ENDCOLOR}" - printf "%b\n" "p (u) ${FAINT}- update os${ENDCOLOR}" - printf "%b\n" "p i package ${FAINT}- install package${ENDCOLOR}" - printf "%b\n" "p r package ${FAINT}- remove package${ENDCOLOR}" - printf "%b\n" "p s packages ${FAINT}- launch a nix shell with the specified packages${ENDCOLOR}" - printf "%b\n" "${FAINT}Supported package managers: flatpak, nix, brew, apt, paru, pacman, dnf${ENDCOLOR}" + printf "%b\n" "${YELLOW}${UNDERLINE}[i] Usage:${NC}" + printf "%b\n" "p (u) ${FAINT}- update os${NC}" + printf "%b\n" "p i package ${FAINT}- install package${NC}" + printf "%b\n" "p r package ${FAINT}- remove package${NC}" + printf "%b\n" "p s packages ${FAINT}- launch a nix shell with the specified packages${NC}" + printf "%b\n" "${FAINT}Supported package managers: flatpak, nix, brew, apt, paru, pacman, dnf${NC}" return 1 fi ) diff --git a/scripts/update b/scripts/update index 4e94e2fb..4720ee35 100755 --- a/scripts/update +++ b/scripts/update @@ -1,9 +1,9 @@ #! /bin/bash YELLOW="\e[33m" -ENDCOLOR="\e[0m" +NC="\e[0m" -printf "%b\n" "${YELLOW}Updating apt...${ENDCOLOR}" +printf "%b\n" "${YELLOW}Updating apt...${NC}" sudo apt update sudo apt upgrade sudo apt dist-upgrade @@ -11,8 +11,7 @@ sudo apt autoremove sudo apt autoclean if command -v flatpak >/dev/null 2>&1; then - printf "%b\n" "${YELLOW}Updating flatpak...${ENDCOLOR}" + printf "%b\n" "${YELLOW}Updating flatpak...${NC}" flatpak update flatpak uninstall --unused --delete-data fi -