Skip to content

Instantly share code, notes, and snippets.

@easyaspi314
Created May 8, 2017 01:45
Show Gist options
  • Save easyaspi314/efc9b9f83de799a46116ed68f52cb8b6 to your computer and use it in GitHub Desktop.
Save easyaspi314/efc9b9f83de799a46116ed68f52cb8b6 to your computer and use it in GitHub Desktop.
Hopefully functional Xbatalarm for nonfunctional ACPI. Copy to /usr/bin/xbatalarm and reboot. Original file by QuaLaPinna.
#!/bin/bash
# Copyright (C) QuaLaPinna team (Gius & Whitesnow, repository: http://qualapinna.dyndns.org/repo, blog: http://qualapinna.dyndns.org)
# April 2014, license: GPL3 and any later versions
# Credits: Puppy Linux forum user josejp2424 for input and collaboration in NLS development (see es_AR localized file).
# Xbatalarm version 2.0
export TEXTDOMAIN=xbatalarm
export OUTPUT_CHARSET=UTF-8
f_get_values() {
if [ -f /proc/acpi/battery/*/state ]; then
REAL_CHRG=$(grep remaining /proc/acpi/battery/*/state | awk '{print $3}')
LAST_F_CHRG=$(grep full /proc/acpi/battery/*/info | awk '{print $4}')
ALRM_MARK=$(echo "$LAST_F_CHRG * $ALRM_PERC / 100" | bc)
CHARG_STATUS=$(grep charging /proc/acpi/battery/*/state | awk '{print $3}')
elif [ -f /sys/class/power_supply/BAT*/uevent ]; then
if [ -f /sys/class/power_supply/BAT*/charge_now ]; then
REAL_CHRG=$(cat /sys/class/power_supply/BAT*/charge_now)
LAST_F_CHRG=$(cat /sys/class/power_supply/BAT*/charge_full)
else
REAL_CHRG=$(cat /sys/class/power_supply/BAT*/energy_now)
LAST_F_CHRG=$(cat /sys/class/power_supply/BAT*/energy_full)
fi
ALRM_MARK=$(echo "$LAST_F_CHRG * $ALRM_PERC / 100" | bc)
CHARG_STATUS=$(cat /sys/class/power_supply/BAT*/status)
fi
}
if [ -r /etc/xbatalarm/xbatalarm.conf ]; then
. /etc/xbatalarm/xbatalarm.conf
else
/usr/bin/xbatalarm-config
fi
while [ true ]
do
f_get_values
if [[ "$CHARG_STATUS" != "discharging" && "$CHARG_STATUS" != "Discharging" ]]; then
sleep $SLEEP_TIME
continue
fi
if (( $(bc <<< "$REAL_CHRG < $ALRM_MARK") )); then
Xdialog --title "Xbatalarm" --center --timeout 8 --msgbox "`gettext '## WARNING! ## \n \n YOUR BATTERY NEEDS TO BE CHARGED.\n PLEASE, CONNECT YOUR CHARGER.'`" 0 0 &
mplayer /usr/share/audio/error.wav &> /dev/null &
fi
sleep $SLEEP_TIME
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment