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