projects/aports·blob master · refs

52 lines · 898 B

1#!/sbin/openrc-run
2
3description="Save/Restore rfkill configuration"
4
5rfkillstatedir=/var/lib/rfkill
6
7extra_commands="save restore"
8
9depend() {
10 need localmount
11 after bootmisc modules isapnp coldplug hotplug
12}
13
14restore() {
15 ebegin "Restoring rfkill configuration"
16 if [ -d "$rfkillstatedir" ]; then
17 for type in "$rfkillstatedir"/*; do
18 status=$(cat "$type")
19 type=$(basename "$type")
20 rfkill "$status" "$type"
21 done
22 fi
23 eend 0
24}
25
26save() {
27 ebegin "Storing rfkill configuration"
28 mkdir -p "$rfkillstatedir"
29 OLDIFS="$IFS"
30 IFS=$'\n'
31 for line in $(rfkill -r -n); do
32 type=$(echo "$line" | cut -d' ' -f2)
33 status=$(echo "$line" | cut -d' ' -f4 | tr -d 'ed')
34 echo "$status" > "$rfkillstatedir"/"$type"
35 done
36 IFS="$OLDIFS"
37 eend 0
38}
39
40start() {
41 if [ "${RESTORE_ON_START}" = "yes" ]; then
42 restore
43 fi
44 return 0
45}
46
47stop() {
48 if [ "${SAVE_ON_STOP}" = "yes" ]; then
49 save
50 fi
51 return 0
52}