/
bin
/
Upload File
HOME
#!/bin/bash CONFFILE=/etc/sysfs.conf CONFDIR=/etc/sysfs.d load_conffile() { local FILE="$1" ( cat "$FILE"; echo ) | sed 's/#.*$//; /^[[:space:]]*$/d; s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' | while read -r f1 f2 f3; do if [ "$f1" = "mode" ] && [ -n "$f2" ] && [ -n "$f3" ]; then if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then chmod "$f3" "/sys/$f2" else echo "unknown attribute $f2" fi elif [ "$f1" = "owner" ] && [ -n "$f2" ] && [ -n "$f3" ]; then if [ -f "/sys/$f2" ]; then chown "$f3" "/sys/$f2" else echo "unknown attribute $f2" fi elif [ "$f1" ] && [ -n "$f2" ] && [ -z "$f3" ]; then for path in /sys/$f1; do if [ -f "$path" ]; then # Some fields need a terminating newline, others need the # terminating newline to be absent. :-( printf "%s" "$f2" >"$path" 2>/dev/null || echo "$f2" >"$path" 2>/dev/null || echo "cannot write value for attribute $f1" else echo "unknown attribute $f1" fi done else echo "syntax error in $FILE: '$f1' '$f2' '$f3'" exit 1 fi done } for file in $CONFFILE "$CONFDIR"/*.conf; do [ -r "$file" ] || continue load_conffile "$file" done