- Complete installation and uninstallation scripts - Optimized TLP configuration for maximum battery life - PowerTOP analysis and auto-tune functionality - Real-time battery monitoring with detailed stats - ThinkPad-specific optimizations and battery thresholds - Comprehensive documentation and usage guides - Tested on ThinkPad T14 Gen 1 with 13% power reduction
116 lines
2.7 KiB
Bash
Executable File
116 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Uninstall script for Battery Life Optimizer tools
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
log() {
|
|
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
|
}
|
|
|
|
success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Check if running as root
|
|
check_root() {
|
|
if [[ $EUID -eq 0 ]]; then
|
|
error "This script should not be run as root!"
|
|
error "It will use sudo when necessary."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Restore TLP configuration backup
|
|
restore_tlp_config() {
|
|
local backup_pattern="/etc/tlp.conf.backup.*"
|
|
local latest_backup=$(ls -t $backup_pattern 2>/dev/null | head -n1)
|
|
|
|
if [[ -n "$latest_backup" && -f "$latest_backup" ]]; then
|
|
log "Restoring TLP configuration from backup..."
|
|
sudo cp "$latest_backup" /etc/tlp.conf
|
|
success "TLP configuration restored from $latest_backup"
|
|
else
|
|
warning "No TLP configuration backup found"
|
|
fi
|
|
}
|
|
|
|
# Remove PowerTOP service
|
|
remove_powertop_service() {
|
|
log "Removing PowerTOP auto-tune service..."
|
|
|
|
if systemctl is-enabled powertop.service &>/dev/null; then
|
|
sudo systemctl disable powertop.service
|
|
sudo systemctl stop powertop.service
|
|
fi
|
|
|
|
if [[ -f /etc/systemd/system/powertop.service ]]; then
|
|
sudo rm /etc/systemd/system/powertop.service
|
|
sudo systemctl daemon-reload
|
|
fi
|
|
|
|
success "PowerTOP service removed"
|
|
}
|
|
|
|
# Uninstall packages
|
|
uninstall_packages() {
|
|
log "Removing installed packages..."
|
|
|
|
# Ask for confirmation
|
|
warning "This will remove TLP, PowerTOP, and related packages"
|
|
read -p "Are you sure? (y/N): " -n 1 -r
|
|
echo
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
sudo apt remove --purge -y \
|
|
tlp \
|
|
tlp-rdw \
|
|
powertop \
|
|
tp-smapi-dkms \
|
|
acpi-call-dkms \
|
|
laptop-mode-tools \
|
|
thermald \
|
|
cpufrequtils
|
|
|
|
sudo apt autoremove -y
|
|
success "Packages removed"
|
|
else
|
|
warning "Package removal cancelled"
|
|
fi
|
|
}
|
|
|
|
# Main uninstall function
|
|
main() {
|
|
log "Starting Battery Life Optimizer uninstallation..."
|
|
|
|
check_root
|
|
|
|
remove_powertop_service
|
|
restore_tlp_config
|
|
uninstall_packages
|
|
|
|
success "Uninstallation completed!"
|
|
echo
|
|
log "System restored to previous state"
|
|
warning "Reboot recommended to ensure all changes take effect"
|
|
}
|
|
|
|
# Run main function if script is executed directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi |