Update scaling-governor.sh

menu options dynamically based on the available scaling governors
This commit is contained in:
tteckster 2023-03-08 20:19:37 -05:00 committed by GitHub
parent 6b10aa922a
commit a153da3465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 84 deletions

View File

@ -5,21 +5,19 @@
# License: MIT # License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE # https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info { header_info() {
cat <<"EOF" clear
cat <<EOF
__________ __ __ __________ __ __
/ ____/ __ \/ / / / / ____/ __ \/ / / /
/ / / /_/ / / / / / / / /_/ / / / /
/ /___/ ____/ /_/ / / /___/ ____/ /_/ /
\____/_/ \____/ \____/_/ \____/
Scaling Governors Scaling Governors
EOF EOF
} }
clear
header_info
set -e
while true; do while true; do
header_info
read -p "View CPU Scaling Governors. Proceed(y/n)?" yn read -p "View CPU Scaling Governors. Proceed(y/n)?" yn
case $yn in case $yn in
[Yy]*) break ;; [Yy]*) break ;;
@ -27,89 +25,34 @@ while true; do
*) echo "Please answer yes or no." ;; *) echo "Please answer yes or no." ;;
esac esac
done done
clear
show_menu() { show_menu() {
CL=$(echo "\033[m")
GN=$(echo "\033[32m")
BL=$(echo "\033[36m")
YW=$(echo "\033[33m")
fgred=$(echo "\033[31m")
header_info header_info
CK=$(uname -r) echo -e "\nProxmox IP \033[36m$(hostname -I)\033[m"
IP=$(hostname -I) echo -e "Current Kernel \033[36m$(uname -r)\033[m\n"
# MAC=$(cat /sys/class/net/eno1/address) available_governors=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)
ACSG=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors) echo -e "Available CPU Scaling Governors\n\033[36m${available_governors}\033[m\n"
CCSG=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) echo -e "Current CPU Scaling Governor\n\033[36m$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)\033[m\n"
echo -e "${YW}Proxmox IP ${BL}${IP}${CL}" options=""
i=1
echo -e "${YW}MAC Address ${BL}${MAC}${CL}" for governor in $available_governors
do
echo -e "${YW}Current Kernel ${BL}${CK}${CL}" options+="** ${i}) \033[36m${governor}\033[m CPU Scaling Governor\n"
((i=i+1))
echo -e "\n${YW}Available CPU Scaling Governors done
${BL}${ACSG}${CL}" echo -e "${options}"
echo -e "\033[31mNOTE: Settings return to default after reboot\033[m\n"
echo -e "\n${YW}Current CPU Scaling Governor read -p "Please choose an option from the menu and press [ENTER] or x to exit." opt
${BL}${CCSG}${CL}"
printf "\n ${fgred}Only Select Available CPU Scaling Governors From Above${CL}\n \n"
printf "${BL}**${YW} 1)${GN} Switch to ${BL}conservative${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "${BL}**${YW} 2)${GN} Switch to ${BL}ondemand${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "${BL}**${YW} 3)${GN} Switch to ${BL}userspace${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "${BL}**${YW} 4)${GN} Switch to ${BL}powersave${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "${BL}**${YW} 5)${GN} Switch to ${BL}performance${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "${BL}**${YW} 6)${GN} Switch to ${BL}schedutil${CL}${GN} CPU Scaling Governor ${CL}\n"
printf "\n ${fgred}NOTE: Settings return to default after reboot${CL}\n"
printf "\n Please choose an option from the menu and press [ENTER] or ${fgred}x${CL} to exit."
read opt
} }
clear
show_menu show_menu
while [ "$opt" != "" ]; do while [[ "$opt" != "" ]]; do
if [ "$opt" = "" ]; then num_governors=$(echo "$available_governors" | wc -w)
if [[ $opt -gt 0 ]] && [[ $opt -le $num_governors ]]; then
governor=$(echo "$available_governors" | cut -d' ' -f $opt)
echo "${governor}" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
elif [[ $opt == "x" ]] || [[ $opt == "\n" ]]; then
exit exit
else else
case $opt in
1)
echo "conservative" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu show_menu
;;
2)
echo "ondemand" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu
;;
3)
echo "userspace" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu
;;
4)
echo "powersave" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu
;;
5)
echo "performance" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu
;;
6)
echo "schedutil" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clear
show_menu
;;
x)
exit
;;
\n)
exit
;;
*)
clear
show_menu
;;
esac
fi fi
show_menu
done done