forked from linrunner/TLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlp-rdw-udev.in
102 lines (80 loc) · 2.78 KB
/
tlp-rdw-udev.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
# tlp-rdw - handle dock/undock events
#
# Copyright (c) 2016 Thomas Koch <linrunner at gmx.net>
# This software is licensed under the GPL v2 or later.
# --- Constants
readonly LIBDIR="@TLP_TLIB@"
readonly LIBS="tlp-functions tlp-rf-func"
# --- Source libraries
for lib in $LIBS; do
if [ ! -f $LIBDIR/$lib ]; then
echo "Error: missing function library \'$LIBDIR/$lib\'." 1>&2
exit 1
fi
. $LIBDIR/$lib
done
# --- MAIN
read_defaults
check_tlp_enabled || exit 0
add_sbin2path
# get power state
get_power_state; onbat=$?
# get device/type
ddev=/sys$1
devtype=$2
case $devtype in
dock)
# check if type is "dock_station", exit if not
type=$(cat $ddev/type)
[ "$type" = "dock_station" ] || exit 0
docked=$(cat $ddev/docked)
action=$EVENT
echo_debug "udev" "+++ rdw_udev($devtype).$action dev=$ddev type=$type docked=$docked onbat=$onbat"
;;
usb_dock)
case $ACTION in
add) action="dock" ;;
remove) action="undock" ;;
esac
echo_debug "udev" "+++ rdw_udev($devtype).$action dev=$ddev onbat=$onbat"
;;
*) exit 0 ;; # unknown device type
esac
# quit if timed lock in progress
if check_timed_lock $RDW_DOCK_LOCK ; then
echo_debug "udev" "rdw_udev.locked"
exit 0
fi
case $action in
dock) # laptop was docked
# lock for 2 seconds in case dock has multiple devices
set_timed_lock $RDW_DOCK_LOCK $RDW_LOCKTIME
# enable configured radios (obey rdw nm locks too)
for dev in $DEVICES_TO_ENABLE_ON_DOCK; do
[ -n "$dev" ] && ! check_timed_lock "${RDW_NM_LOCK}_${dev}" \
&& device_switch $dev on "${RDW_NM_LOCK}_${dev}" $RDW_LOCKTIME
done
# disable configured radios (obey rdw nm locks too)
for dev in $DEVICES_TO_DISABLE_ON_DOCK; do
[ -n "$dev" ] && ! check_timed_lock "${RDW_NM_LOCK}_${dev}" \
&& device_switch $dev off "${RDW_NM_LOCK}_${dev}" $RDW_LOCKTIME
done
;;
undock) # laptop was undocked
# lock for 2 seconds in case dock has multiple devices
set_timed_lock $RDW_DOCK_LOCK $RDW_LOCKTIME
# enable configured radios (obey rdw nm locks too)
for dev in $DEVICES_TO_ENABLE_ON_UNDOCK; do
[ -n "$dev" ] && ! check_timed_lock "${RDW_NM_LOCK}_${dev}" \
&& device_switch $dev on "${RDW_NM_LOCK}_${dev}" $RDW_LOCKTIME
done
# disable configured radios (obey rdw nm locks too)
for dev in $DEVICES_TO_DISABLE_ON_UNDOCK; do
[ -n "$dev" ] && ! check_timed_lock "${RDW_NM_LOCK}_${dev}" \
&& device_switch $dev off "${RDW_NM_LOCK}_${dev}" $RDW_LOCKTIME
done
;;
*) ;; # unknown action -> do nothing
esac
exit 0