aboutsummaryrefslogtreecommitdiffstats
path: root/main/util-linux/rfkill.initd
diff options
context:
space:
mode:
Diffstat (limited to 'main/util-linux/rfkill.initd')
-rw-r--r--main/util-linux/rfkill.initd50
1 files changed, 50 insertions, 0 deletions
diff --git a/main/util-linux/rfkill.initd b/main/util-linux/rfkill.initd
new file mode 100644
index 0000000000..1cc0335e45
--- /dev/null
+++ b/main/util-linux/rfkill.initd
@@ -0,0 +1,50 @@
+#!/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
+}