瀏覽代碼

Update scaling-governor.sh

menu options dynamically based on the available scaling governors
tteckster 2 年之前
父節點
當前提交
a153da3465
共有 1 個文件被更改,包括 27 次插入84 次删除
  1. 27 84
      misc/scaling-governor.sh

+ 27 - 84
misc/scaling-governor.sh

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