[dev] Remount rootfs sync on impending battery depletion.

From: Antoni Grzymala <antoni_AT_chopin.edu.pl>
Date: Sat, 4 Dec 2010 20:16:00 +0100

Hi,

just wanted to share a simple idea here – a little feature implemented
in my statusbar script: remount the rootfs sync, when the battery
level is below some predefined threshold and falling.

I somehow find it less distracting than warnings popping up and less
annoying then a forced poweroff upon reaching some level.

Here's my implementation (full of bash, gnu tools and other stuff you
love), feel free to pick ideas if you find any of it useful:

#!/bin/bash

while test 1; do

############################################################
# Battery charge.

DO_BATTERY=""
BATTERY=BAT0 ### <- Battery ID

grep ' charged' /proc/acpi/battery/${BATTERY}/state 2>&1 >/dev/null && TIME_LEFT="" || DO_BATTERY=1

if [[ -n ${DO_BATTERY} ]]; then
  TIME_LEFT=`acpi | head -n1 | sed -r \
  's/^.*Battery....//; s/discharging, /-/i; s/charging, /+/i; s/,//g; s/ ([0-9][0-9]:[0-9][0-9]):[0-9][0-9] .*$/ \1 /'`

  if [[ "${TIME_LEFT}" =~ ^-[0-5]% ]]; then
    TIME_LEFT="[fs SYNC] ${TIME_LEFT}"
    grep '^/dev/root.*sync,' /proc/mounts || sudo mount / -o remount -o sync
  else
    grep '^/dev/root.*sync,' /proc/mounts && sudo mount / -o remount
  fi

  TIME_LEFT="${TIME_LEFT} · "
fi

### [...much other code including some sleep...]

STATUS="${TKABBER}${UNREADMAIL}${TIME_LEFT}${PPPD}${WIRELESS}${FETCHMAIL}${UPTIME}${DATE}"
xsetroot -name "${STATUS}"

done

-- 
[a]
Received on Sat Dec 04 2010 - 20:16:00 CET

This archive was generated by hypermail 2.2.0 : Sat Dec 04 2010 - 20:24:02 CET