From 3c3e2cc571c1a4310244877cc923add4dfe2d3ee Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 26 Jan 2016 12:55:31 +1100 Subject: [PATCH] Use cpufreq if available instead of hardcoding it to specific distros --- fetch | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/fetch b/fetch index a1723bb5..22aaf5fd 100755 --- a/fetch +++ b/fetch @@ -590,27 +590,24 @@ getcpu () { cpu=${cpu/@*/} # Get cpu speed - case "$distro" in - *"buntu"* | "CentOS"*) - speed=$(awk -F ': ' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo) - speed=${speed/\./} - ;; + if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then + case "$speed_type" in + current) speed_type="scaling_cur_freq" ;; + min) speed_type="scaling_min_freq" ;; + max) speed_type="scaling_max_freq" ;; + bios) speed_type="bios_limit" ;; + scaling_current) speed_type="scaling_cur_freq" ;; + scaling_min) speed_type="scaling_min_freq" ;; + scaling_max) speed_type="scaling_max_freq" ;; + esac - *) - case "$speed_type" in - current) speed_type="scaling_cur_freq" ;; - min) speed_type="scaling_min_freq" ;; - max) speed_type="scaling_max_freq" ;; - bios) speed_type="bios_limit" ;; - scaling_current) speed_type="scaling_cur_freq" ;; - scaling_min) speed_type="scaling_min_freq" ;; - scaling_max) speed_type="scaling_max_freq" ;; - esac + read -r speed < \ + /sys/devices/system/cpu/cpu0/cpufreq/${speed_type} - read -r speed < \ - /sys/devices/system/cpu/cpu0/cpufreq/${speed_type} - ;; - esac + else + speed=$(awk -F ': ' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo) + speed=${speed/\./} + fi # Convert mhz to ghz without bc speed=$((speed / 100000))