#!/bin/sh # # template Set sysfs variables from /etc/sysfs.conf # # chkconfig: 2345 33 67 # description: Set sysfs variables from /etc/sysfs.conf # config: /etc/sysfs.conf # Do not load RH compatibility interface. WITHOUT_RC_COMPAT=1 # Source function library. . /etc/init.d/functions CONFIG=/etc/sysfs.conf LOCKFILE=/var/lock/subsys/sysfs RETVAL=0 [ -s "$CONFIG" -a -r "$CONFIG" ] || exit 0 config_error () { local lineno="$1" && shift echo "$CONFIG:$lineno: $*" >&2 } apply_sysfs_rules () { local lineno=0 ret=0 echo -n "Setting sysfs variables..." while read f1 f2 f3 f4; do lineno=$(( $lineno + 1 )) # Skip empty lines [ -z "$f1$f2$f3$f4" ] && continue # Skip comments [ -n "$f1" -a -z "${f1##\#*}" ] && continue case "$f1,$f2,$f3,$f4" in mode,?*,=,?*) if [ -f "/sys/$f2" ]; then chmod "$f4" "/sys/$f2" || ret=1 else echo "Unknown attribute: $f2" >&2 fi ;; owner,?*,=,?*) if [ -f "/sys/$f2" ]; then chown "$f4" "/sys/$f2" || ret=1 else echo "Unknown attribute: $f2" >&2 fi ;; ?*,=,?*,) if [ -f "/sys/$f1" ]; then # Some fields need a terminating newline, others # need the terminating newline to be absent :-( echo -n "$f3" > "/sys/$f1" || echo "$f3" > "/sys/$f1" || ret=1 else echo "Unknown attribute: $f1" >&2 fi ;; *,*,*,*) config_error $lineno "Synax error: $f1 $f2 $f3 $f4" return 1 ;; esac done < "$CONFIG" return $ret } # See how we were called. case "$1" in start|reload|restart) apply_sysfs_rules && echo_success || echo_failure echo RETVAL=$? ;; condrestart|condreload) if [ -e "$LOCKFILE" ]; then apply_sysfs_rules && echo_success || echo_failure echo RETVAL=$? fi ;; status) echo -n "Subsystem was " [ -f "$LOCKFILE" ] || echo -n "not " echo "activated." RETVAL=$? ;; stop|condstop) rm -f "$LOCKFILE" ;; *) msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}" RETVAL=1 esac exit $RETVAL