aports/main/util-linux/rfkill.initd
Clayton Craft 8343f3ae31 main/util-linux: add openrc subpackage for saving/restoring rfkill state
This adds an openrc init script for saving and restoring rfkill state
for devices on stop/start. It is based on a similar init script for
alsa-utils.
2020-11-09 05:44:45 +00:00

51 lines
854 B
Bash

#!/sbin/openrc-run
description="Save/Restore rfkill configuration"
rfkillstatedir=/var/lib/rfkill
extra_commands="save restore"
depend() {
need localmount
after bootmisc modules isapnp coldplug hotplug
}
restore() {
ebegin "Restoring rfkill configuration"
for type in "$rfkillstatedir"/*; do
status=$(cat "$type")
type=$(basename "$type")
rfkill "$status" "$type"
done
eend 0
}
save() {
ebegin "Storing rfkill configuration"
mkdir -p "$rfkillstatedir"
OLDIFS="$IFS"
IFS=$'\n'
for line in $(rfkill -r -n); do
type=$(echo "$line" | cut -d' ' -f2)
status=$(echo "$line" | cut -d' ' -f4 | tr -d 'ed')
echo "$status" > "$rfkillstatedir"/"$type"
done
IFS="$OLDIFS"
eend 0
}
start() {
if [ "${RESTORE_ON_START}" = "yes" ]; then
restore
fi
return 0
}
stop() {
if [ "${SAVE_ON_STOP}" = "yes" ]; then
save
fi
return 0
}