summaryrefslogtreecommitdiff
path: root/system/openrc/sysfsconf.initd
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2018-02-20 21:20:18 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2018-02-20 21:20:18 -0600
commit866f81aaa5e438537e6a4b30c1f0fcecc713a1a2 (patch)
tree4bce7ccd2a7603bdf638e250b8e30e54c1dea909 /system/openrc/sysfsconf.initd
parent31f3497a1ca9637ff42f3185a5924e0f4e61ab5d (diff)
downloadpackages-866f81aaa5e438537e6a4b30c1f0fcecc713a1a2.tar.gz
packages-866f81aaa5e438537e6a4b30c1f0fcecc713a1a2.tar.bz2
packages-866f81aaa5e438537e6a4b30c1f0fcecc713a1a2.tar.xz
packages-866f81aaa5e438537e6a4b30c1f0fcecc713a1a2.zip
system/openrc: migrate from aports fork
Diffstat (limited to 'system/openrc/sysfsconf.initd')
-rw-r--r--system/openrc/sysfsconf.initd66
1 files changed, 66 insertions, 0 deletions
diff --git a/system/openrc/sysfsconf.initd b/system/openrc/sysfsconf.initd
new file mode 100644
index 000000000..433e51d63
--- /dev/null
+++ b/system/openrc/sysfsconf.initd
@@ -0,0 +1,66 @@
+#!/sbin/openrc-run
+
+description="Set sysfs variables from /etc/sysfs.conf and /etc/sysfs.d/*.conf"
+conffile=/etc/sysfs.conf
+confdir=/etc/sysfs.d
+
+depend() {
+ need sysfs
+}
+
+setval() {
+ local value="$1" attrib="$2"
+ # Some fields need a terminating newline, others
+ # need the terminating newline to be absent :-(
+ echo -n "$value" > "$attrib" 2>/dev/null \
+ || echo "$value" > "$attrib"
+}
+
+load_conffile() {
+ local file="$1"
+ while read line; do
+ local line=${line%%#*}
+ local cmd= attrib= value=
+ set -- $line
+ if [ $# -eq 0 ]; then
+ continue
+ fi
+ case "$1$3" in
+ mode=) cmd=chmod
+ attrib="$2"
+ value="$4"
+ ;;
+ owner=) cmd=chown
+ attrib="$2"
+ value="$4"
+ ;;
+ *) if [ "$2" = "=" ]; then
+ cmd=setval
+ attrib="$1"
+ value="$3"
+ fi
+ ;;
+ esac
+ if ! [ -e "/sys/$attrib" ]; then
+ eerror "$attrib: unknown attribute"
+ continue
+ fi
+ if [ -z "$attrib" ] || [ -z "$value" ]; then
+ eerror "syntax error in $file: '$line'"
+ continue
+ fi
+ $cmd "$value" "/sys/$attrib"
+ done < "$file"
+}
+
+start() {
+ [ -r "$conffile" -o -d "$confdir" ] || return 0
+ ebegin "Setting sysfs variables"
+ for file in $confdir/*.conf $conffile; do
+ [ -r "$file" ] || continue
+ load_conffile "$file" || return 1
+ done
+ eend 0
+
+}
+