#!/bin/bash # WiFi Power Save Disable Script # Supports Arch Linux and Fedora # Author: Asher Payn :) set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Colour # Function to print coloured output print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if running as root check_root() { if [[ $EUID -eq 0 ]]; then print_error "This script should not be run as root. Please run as a regular user." print_status "The script will use sudo when needed." exit 1 fi } # Detect the Linux distribution detect_distro() { if [[ -f /etc/os-release ]]; then . /etc/os-release DISTRO=$ID else print_error "Cannot detect Linux distribution" exit 1 fi case $DISTRO in arch|manjaro|cachyos|artix|endeavouros) DISTRO_TYPE="arch" print_status "Detected Arch-based distribution: $NAME" ;; fedora|centos|rhel|rocky|almalinux) DISTRO_TYPE="fedora" print_status "Detected Red Hat-based distribution: $NAME" ;; *) print_error "Unsupported distribution: $DISTRO" print_status "This script supports Arch Linux and Fedora-based distributions only." exit 1 ;; esac } # Check if NetworkManager is running check_networkmanager() { if systemctl is-active --quiet NetworkManager; then print_status "NetworkManager is running" return 0 else print_warning "NetworkManager is not running" return 1 fi } # Get WiFi interface name get_wifi_interface() { WIFI_INTERFACE=$(iw dev | grep Interface | head -n1 | awk '{print $2}') if [[ -z "$WIFI_INTERFACE" ]]; then print_error "No WiFi interface found" exit 1 fi print_status "Found WiFi interface: $WIFI_INTERFACE" } # Install required packages install_packages() { case $DISTRO_TYPE in arch) if ! command -v iw &> /dev/null; then print_status "Installing iw..." sudo pacman -S --needed --noconfirm iw fi ;; fedora) if ! command -v iw &> /dev/null; then print_status "Installing iw..." sudo dnf install -y iw fi ;; esac } # Method 1: NetworkManager configuration configure_networkmanager() { print_status "Configuring NetworkManager to disable WiFi power save..." # Create NetworkManager conf.d directory if it doesn't exist sudo mkdir -p /etc/NetworkManager/conf.d/ # Create the configuration file sudo tee /etc/NetworkManager/conf.d/wifi-powersave-off.conf > /dev/null < /dev/null < /dev/null < /dev/null; then POWER_STATUS=$(iw dev "$WIFI_INTERFACE" get power_save 2>/dev/null || echo "") if [[ $POWER_STATUS == *"off"* ]]; then print_success "WiFi power save is DISABLED" echo "Current status: $POWER_STATUS" elif [[ $POWER_STATUS == *"on"* ]]; then print_warning "WiFi power save is still ENABLED" echo "Current status: $POWER_STATUS" print_status "You may need to reboot or reconnect to WiFi for changes to take full effect" else print_warning "Could not determine power save status" fi else print_warning "iw not available, cannot verify status" fi } # Create a script to manually disable power save create_manual_script() { print_status "Creating manual disable script..." sudo tee /usr/local/bin/disable-wifi-powersave > /dev/null <