From 3884d3e2cf69212e11682e7c15d8421af003ab75 Mon Sep 17 00:00:00 2001 From: "b.waal" Date: Sat, 10 Aug 2024 00:31:05 +0200 Subject: [PATCH] Add Debian/CPU Governor/setup.sh --- Debian/CPU Governor/setup.sh | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Debian/CPU Governor/setup.sh diff --git a/Debian/CPU Governor/setup.sh b/Debian/CPU Governor/setup.sh new file mode 100644 index 0000000..0665bb8 --- /dev/null +++ b/Debian/CPU Governor/setup.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Precheck +if [ "$EUID" -ne 0 ] + TERM=ansi whiptail --title "Info" --infobox "Please run as root!" 7 23 + sleep 3 + exit +fi + + +# Check if file exists +if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then + # If file exists show 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 + TERM=ansi whiptail --title "Info" --infobox "This CPU/OS does not support a governor!" 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 +TERM=ansi whiptail --title "Info" --infobox "Enabling governor at startup.." 7 35 +systemctl enable cpu-governor +TERM=ansi whiptail --title "Info" --infobox "Enabling governor at startup..." 7 35 +systemctl start cpu-governor + +TERM=ansi whiptail --title "Info" --msgbox "Setup finished!" 8 19 +cls \ No newline at end of file