sysfsutils 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017 Rodolfo Giometti <[email protected]>
  3. #
  4. # Based on Debian's script /etc/init.d/sysfsutils by
  5. # Martin Pitt <[email protected]>
  6. load_conffile() {
  7. FILE="$1"
  8. sed 's/#.*$//; /^[[:space:]]*$/d;
  9. s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \
  10. $FILE | {
  11. while read f1 f2 f3; do
  12. if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then
  13. if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then
  14. chmod "$f3" "/sys/$f2"
  15. else
  16. echo "unknown attribute $f2"
  17. fi
  18. elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then
  19. if [ -f "/sys/$f2" ]; then
  20. chown "$f3" "/sys/$f2"
  21. else
  22. echo "unknown attribute $f2"
  23. fi
  24. elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
  25. if [ -f "/sys/$f1" ]; then
  26. # Some fields need a terminating newline, others
  27. # need the terminating newline to be absent :-(
  28. echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
  29. echo "$f2" > "/sys/$f1"
  30. else
  31. echo "unknown attribute $f1"
  32. fi
  33. else
  34. echo "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
  35. exit 1
  36. fi
  37. done
  38. }
  39. }
  40. START=11
  41. start() {
  42. for file in /etc/sysfs.conf /etc/sysfs.d/*.conf; do
  43. [ -r "$file" ] || continue
  44. load_conffile "$file"
  45. done
  46. }