#!/sbin/runscript depend() { need localmount before logger } start() { ebegin "Setting sysfs values" # check if configuration files exists if ! [ -f /etc/conf.d/sysfs ] ; then eerror " Configuration file /etc/conf.d/sysfs not found!" eend -1 "Failed to set syfs values" return -1 fi # check if configuration file is empty if [[ `cat /etc/conf.d/sysfs | grep -v "^#"` == "" ]]; then eerror " Configuration file /etc/conf.d/sysfs empty!" eend -1 "Failed to set syfs values" return -1 fi # check if the SYSFS array is empty if [ ${#SYSFS[*]} == 0 ] ; then ewarn " Nothing to do!" eend 0 return -1 fi # set sysfs values for i in `seq 1 ${#SYSFS[*]}` ; do # check if the string is empty if [[ `echo ${SYSFS[$i-1]}` == "" ]] ; then let p=$i-1 eend -1 " Empty string at position $p in array SYSFS!" continue fi # check if the string is an assignment if ! [[ `echo ${SYSFS[$i-1]} | grep =` ]] ; then let p=$i-1 eend -1 " String must be an assignment at position $p in array SYSFS!" continue fi FILE=`echo ${SYSFS[$i-1]} | cut -d'=' -f1` VALUE=`echo ${SYSFS[$i-1]} | cut -d'=' -f2` # check if $FILE is an empty string if [[ $FILE == "" ]] ; then let p=$i-1 eend -1 " Field empty at position $p in array SYSFS!" continue fi # check if $FILE contains spaces if [[ `echo $FILE | grep " "` ]] ; then let p=$i-1 eend -1 " Field can't contain spaces at position $p in array SYSFS!" continue fi # check if $VALUE is an empty string if [[ $VALUE == "" ]] ; then let p=$i-1 eend -1 " Field empty at position $p in array SYSFS" continue fi # check if the file to be modified is in the /sys tree if [[ `echo $FILE | cut -d"/" -f2` != "sys" ]] ; then eend -1 " Cannot modify files not in the sysfs!" continue fi # check if the file exists in sysfs if ! [ -f $FILE ] ; then eend -1 " File $FILE not found in sysfs!" continue fi ebegin " Setting `echo $VALUE` in $FILE" echo -n "$VALUE" > $FILE eend $? done }