From 28c7202bd81715cbca40f8b8dc413bfb94a840cf Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Tue, 26 Oct 2021 15:26:11 -0500 Subject: [PATCH] etc/functions: Improve handling of battery charge/health calcs Some devices, like older Librem laptops, use BAT vs BAT0 for the primary battery. Accomodate this by using BAT* instead of BAT0. Could break on multi-battery devices, but none supported in tree currently so more of a theoretical problem. Signed-off-by: Matt DeVillier --- initrd/etc/functions | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/initrd/etc/functions b/initrd/etc/functions index 8683242d..ee1ec286 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -353,16 +353,16 @@ calc() print_battery_health() { - if [ -d /sys/class/power_supply/BAT0 ]; then - battery_health=$(calc $(cat /sys/class/power_supply/BAT0/charge_full)/$(cat /sys/class/power_supply/BAT0/charge_full_design)*100 | awk -F "." {'print $1'}) + if [ -d /sys/class/power_supply/BAT* ]; then + battery_health=$(calc $(cat /sys/class/power_supply/BAT*/charge_full)/$(cat /sys/class/power_supply/BAT*/charge_full_design)*100 | awk -F "." {'print $1'}) echo "$battery_health" fi } print_battery_charge() { - if [ -d /sys/class/power_supply/BAT0 ]; then - battery_charge=$(calc $(cat /sys/class/power_supply/BAT0/charge_now)/$(cat /sys/class/power_supply/BAT0/charge_full)*100 | awk -F "." {'print $1'}) + if [ -d /sys/class/power_supply/BAT* ]; then + battery_charge=$(calc $(cat /sys/class/power_supply/BAT*/charge_now)/$(cat /sys/class/power_supply/BAT*/charge_full)*100 | awk -F "." {'print $1'}) echo "$battery_charge" fi }