sysfsutils 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. START=11
  7. load_conffile() {
  8. FILE="$1"
  9. sed 's/#.*$//; /^[[:space:]]*$/d;
  10. s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \
  11. $FILE | {
  12. while read f1 f2 f3; do
  13. if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then
  14. if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then
  15. chmod "$f3" "/sys/$f2"
  16. else
  17. echo "unknown attribute $f2"
  18. fi
  19. elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then
  20. if [ -f "/sys/$f2" ]; then
  21. chown "$f3" "/sys/$f2"
  22. else
  23. echo "unknown attribute $f2"
  24. fi
  25. elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
  26. if [ -f "/sys/$f1" ]; then
  27. # Some fields need a terminating newline, others
  28. # need the terminating newline to be absent :-(
  29. echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
  30. echo "$f2" > "/sys/$f1"
  31. else
  32. echo "unknown attribute $f1"
  33. fi
  34. else
  35. echo "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
  36. exit 1
  37. fi
  38. done
  39. }
  40. }
  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. }