sysfsutils -- the script

arne anka openmoko at ginguppin.de
Wed Jul 23 20:03:21 CEST 2008


somebody with access to the wiki might put the following there ...

sysfsutils (at least on debian/unstable) contains a script, that reads a  
configfiole on startup and sets values in /sys/ accordingly.
i modified the script to run an the freerunner (basically removed the  
debian specific bits).
put it into /etc/init.d/ and link it to /etc/rcS.d/ so it runs on startup.
i did
cd /etc/rcS.d
ln -s ../init.d/sysfsutils S05sysfsutils

the config file is /etc/sysfs.conf  and has the format key=value
key is a path _below_ /sys/ and value the value to set.
mine looks like this:

class/leds/gta02-power:orange/trigger=bat-charging
class/leds/gta02-power:blue/trigger=bat-full
class/leds/gta02-aux:red/trigger=nand-disk

when chargin the orange led should shine, when full the blue.
not sure, what nand-disk is exactly :-), probably the memory, at least it  
flickers while booting ...

below the script:

#! /bin/sh -e

### BEGIN INIT INFO
# Provides:          sysfsconf
# Required-Start:    mountkernfs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Set sysfs variables from /etc/sysfs.conf
# Description:       Similarly to /etc/init.d/procps.sh, you can configure
#                    values for sysfs variables (such as power management
#                    defaults) and /sys file permissions in  
/etc/sysfs.conf.
### END INIT INFO

# /etc/init.d/sysfsutils:
#
# (c) 2005 Martin Pitt <mpitt at debian.org>

CONFFILE=/etc/sysfs.conf

[ -r "$CONFFILE" ] || exit 0

start(){
  	echo "Setting sysfs variables..."

	sed  's/#.*$//;  
/^[[:space:]]*$/d;s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1  
\2 \3/' \
               $CONFFILE | {
	    while read f1 f2 f3; do
                 if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then
                     if [ -f "/sys/$f2" ]; then
                         chmod "$f3" "/sys/$f2"
                     else
                         echo "1 unknown attribute $f2"
                     fi
                 elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then
                     if [ -f "/sys/$f2" ]; then
                         chown "$f3" "/sys/$f2"
                     else
                         echo "2 unknown attribute $f2"
                     fi
                 elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
                     if [ -f "/sys/$f1" ]; then
                         # Some fields need a terminating newline, others
                         # need the terminating newline to be absent :-(
                          echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
                             echo "$f2" > "/sys/$f1"
                     else
                         echo "3 unknown attribute $f1"
                     fi
                 else
                     echo "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
                     exit 1
                 fi
	    done
	}
}

stop(){}

# See how we were called.
case "$1" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   *)
         echo "Usage: $0 {start|stop}"
         exit 1
esac

exit $RETVAL




More information about the community mailing list