83 lines
3.1 KiB
Bash

#!/bin/bash
#Static Var
file=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Precheck
if [ $UID != 0 ]; then
TERM=ansi whiptail --title "Info" --infobox "Please run as root!" 7 23
sleep 3
clear
exit
fi
# Check if file exists
if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
if grep -Fxq "powersave" $file
then
# If file exists on performance settings autoselect powersave in menu
Governor=$(whiptail --title "Choose a power plan" --radiolist \
"Choose user's permissions" 9 61 3 \
"Performance" "Run the CPU at the maximum frequency" ON \
"Ondemand" "Scales the frequency according to load" OFF \
"Powersave" "Run the CPU at the minimum frequency" OFF 3>&1 1>&2 2>&3)
elif grep -Fxq "performance" $file
then
# If file exists on performance settings autoselect powersave in menu
Governor=$(whiptail --title "Choose a power plan" --radiolist \
"Choose user's permissions" 9 61 3 \
"Performance" "Run the CPU at the maximum frequency" OFF \
"Ondemand" "Scales the frequency according to load" OFF \
"Powersave" "Run the CPU at the minimum frequency" ON 3>&1 1>&2 2>&3)
else
# If file exists on ondemand settings autoselect powersave in menu
Governor=$(whiptail --title "Choose a power plan" --radiolist \
"Choose user's permissions" 9 61 3 \
"Performance" "Run the CPU at the maximum frequency" OFF \
"Ondemand" "Scales the frequency according to load" OFF \
"Powersave" "Run the CPU at the minimum frequency" ON 3>&1 1>&2 2>&3)
fi
else
TERM=ansi whiptail --title "Info" --infobox "This CPU/OS does not support a governor! (yet)" 7 44
sleep 3
exit
fi
if [ -n "$Governor" ]; then
# If var is NOT empty then set var to lowercase
Governor="${Governor,,}"
# Download service file
wget https://git.ictcorpnet.com/b.waal/Snippets/raw/branch/main/Debian/CPU%20Governor/governor.service -O /etc/systemd/system/cpu-governor.service
# Change CHOSEN_POWERPLAN to selected Governor var
sed -i "s/CHOSEN_POWERPLAN/$Governor/g" /etc/systemd/system/cpu-governor.service
fi
TERM=ansi whiptail --title "Info" --infobox "Enabling governor at startup." 7 35
systemctl daemon-reload
sleep 1
TERM=ansi whiptail --title "Info" --infobox "Enabling governor at startup.." 7 35
systemctl enable cpu-governor
sleep 1
TERM=ansi whiptail --title "Info" --infobox "Enabling governor at startup..." 7 35
systemctl start cpu-governor
sleep 1
# Check if package exists
which powertop > /dev/null 2>&1
if [ $? != 0 ]; then
# If package does not exist ask the user to install and configure powertop
if whiptail --title "Info" --yesno "Also install and configure powertop? \n\nPowertop is a tool to enable various powersaving modes." 11 59; then
TERM=ansi whiptail --title "Info" --infobox "Please stand by while this script downloads the next installer" 7 66
wget https://git.ictcorpnet.com/b.waal/Snippets/raw/branch/main/Debian/Powertop/setup.sh -O /tmp/powertop-setup.sh
bash /tmp/powertop-setup.sh
else
TERM=ansi whiptail --title "Info" --msgbox "Setup finished! \n\nThe new settings are automaticly applied.\nNo need to reboot!" 11 45
clear
fi
fi