2022-03-25 09:19:34 -04:00
#!/usr/bin/env bash
2023-02-07 12:15:22 -05:00
2025-01-01 13:37:29 +01:00
# Copyright (c) 2021-2025 tteck
2023-02-07 12:15:22 -05:00
# Author: tteck (tteckster)
# License: MIT
2024-11-02 08:48:05 +01:00
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
2023-10-11 15:31:27 -04:00
set -e
2023-03-08 20:19:37 -05:00
header_info( ) {
2025-04-01 10:25:46 +02:00
clear
cat <<EOF
2023-10-11 14:39:33 -04:00
________ __ __ _____
/ ___/ _ \/ / / / / ___/__ _ _____ _______ ___ _______
/ /__/ ___/ /_/ / / ( _ / _ \ | / / -_) __/ _ \/ _ \/ __( _-<
\_ __/_/ \_ ___/ \_ __/\_ __/___/\_ _/_/ /_//_/\_ __/_/ /___/
2023-01-10 11:16:26 -05:00
EOF
}
2023-10-11 14:39:33 -04:00
header_info
2025-04-15 15:20:46 +02:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU Scaling Governors" --yesno "View/Change CPU Scaling Governors. Proceed?" 10 58
2023-10-11 14:39:33 -04:00
current_governor = $( cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
GOVERNORS_MENU = ( )
MSG_MAX_LENGTH = 0
while read -r TAG ITEM; do
OFFSET = 2
( ( ${# ITEM } + OFFSET > MSG_MAX_LENGTH) ) && MSG_MAX_LENGTH = ${# ITEM } +OFFSET
GOVERNORS_MENU += ( " $TAG " " $ITEM " "OFF" )
done < <( cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | tr ' ' '\n' | grep -v " $current_governor " )
2025-04-15 15:20:46 +02:00
scaling_governor = $( whiptail --backtitle "Proxmox VE Helper Scripts" --title " Current CPU Scaling Governor is set to $current_governor " --checklist "\nSelect the Scaling Governor to use:\n" 16 $(( MSG_MAX_LENGTH + 58 )) 6 " ${ GOVERNORS_MENU [@] } " 3>& 1 1>& 2 2>& 3 | tr -d '"' )
2023-10-11 15:31:27 -04:00
[ -z " $scaling_governor " ] && {
2025-04-01 10:25:46 +02:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "No CPU Scaling Governor Selected" --msgbox "It appears that no CPU Scaling Governor was selected" 10 68
clear
exit
2023-10-11 15:31:27 -04:00
}
2023-10-11 14:39:33 -04:00
echo " ${ scaling_governor } " | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
current_governor = $( cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Current CPU Scaling Governor" " \nCurrent CPU Scaling Governor has been set to $current_governor \n " 10 60
CHOICE = $( whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU Scaling Governor" --menu "This will establish a crontab to maintain the CPU Scaling Governor configuration across reboots.\n \nSetup a crontab?" 14 68 2 \
"yes" " " \
"no" " " 3>& 2 2>& 1 1>& 3)
case $CHOICE in
2025-04-01 10:25:46 +02:00
yes)
set +e
NEW_CRONTAB_COMMAND = " (sleep 60 && echo \" $current_governor \" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor) "
EXISTING_CRONTAB = $( crontab -l 2>/dev/null)
if [ [ -n " $EXISTING_CRONTAB " ] ] ; then
TEMP_CRONTAB_FILE = $( mktemp)
echo " $EXISTING_CRONTAB " | grep -v "@reboot (sleep 60 && echo*" >" $TEMP_CRONTAB_FILE "
crontab " $TEMP_CRONTAB_FILE "
rm " $TEMP_CRONTAB_FILE "
fi
(
crontab -l 2>/dev/null
echo " @reboot $NEW_CRONTAB_COMMAND "
) | crontab -
echo -e "\nCrontab Set (use 'crontab -e' to check)"
; ;
no)
echo -e "\n\033[31mNOTE: Settings return to default after reboot\033[m\n"
; ;
2023-10-11 14:39:33 -04:00
esac
echo -e " Current CPU Scaling Governor is set to \033[36m $current_governor \033[m\n "