updated on Tue Jan 17 12:00:36 UTC 2012
[aur-mirror.git] / acpi-eeepc-generic-svn / acpi-eeepc-generic-bluetooth-toggle.sh
blobc49e0000c99842198d68fac6223e2064731bc8d3
1 #!/bin/bash
5 . /etc/conf.d/acpi-eeepc-generic.conf
6 . /etc/acpi/eeepc/acpi-eeepc-generic-functions.sh
8 eeepc_notify "Bluetooth toggle not implemented yet!!!" stop
9 exit 0
11 EEEPC_RADIO_SAVED_STATE_FILE=$EEEPC_VAR/bluetooth-saved
13 if [ -e $EEEPC_RADIO_SAVED_STATE_FILE ]; then
14 RADIO_SAVED_STATE=$(cat $EEEPC_RADIO_SAVED_STATE_FILE)
15 else
16 RADIO_SAVED_STATE=0
19 # Find the right rfkill switch, but default to the second one
20 rfkill="rfkill1"
21 lsrfkill=""
22 [ -e /sys/class/rfkill ] && lsrfkill=`/bin/ls /sys/class/rfkill/`
23 for r in $lsrfkill; do
24 echo "r = $r"
25 name=`cat /sys/class/rfkill/$r/name`
26 [ "$name" == "eeepc-bluetooth" ] && rfkill=$r
27 done
29 # Get rfkill switch state (0 = card off, 1 = card on)
30 RADIO_CONTROL="/sys/class/rfkill/${rfkill}/state"
31 RADIO_STATE=0
32 [ -e "$RADIO_CONTROL" ] && RADIO_STATE=$(cat $RADIO_CONTROL)
34 [ ! -d "$EEEPC_VAR" ] && mkdir -p $EEEPC_VAR 2>/dev/null
36 # Get bluetooth interface
37 #Bluetooth_IF=
39 logger "acpi-eeepc-generic-bluetooth-toggle.sh: Current state: $RADIO_STATE ($RADIO_CONTROL)"
41 function radio_on {
42 eeepc_notify "Turning Bluetooth Radio on..." gnome-dev-wavelan
44 # Execute pre-up commands just once
45 [ $1 -eq 1 ] && execute_commands "${COMMANDS_Bluetooth_PRE_UP[@]}"
47 # Enable radio
48 [ -e "$RADIO_CONTROL" ] && echo 1 > $RADIO_CONTROL
50 # Load module
51 ( /sbin/modprobe $BLUETOOTH_DRIVER 2>/dev/null && (
52 # If successful, enable card
53 echo 1 > $EEEPC_RADIO_SAVED_STATE_FILE
54 # Execute post-up commands
55 execute_commands "${COMMANDS_Bluetooth_POST_UP[@]}"
57 eeepc_notify "Bluetooth Radio is now on" gnome-dev-wavelan
58 ) || (
59 eeepc_notify "Could not enable Bluetooth radio" stop
60 # If module loading unsuccessful, try again
61 if [ $1 -lt $WIFI_TOGGLE_MAX_TRY ]; then
62 eeepc_notify "Trying again in 2 second ($(($1+1)) / $WIFI_TOGGLE_MAX_TRY)" gnome-dev-wavelan
63 sleep 2
64 radio_on $(($1+1))
66 ) )
69 function radio_off {
70 eeepc_notify "Turning Bluetooth Radio off..." gnome-dev-wavelan
72 # Execute pre-down commands just once
73 [ $1 -eq 1 ] && execute_commands "${COMMANDS_BLUETOOTH_PRE_DOWN[@]}"
75 # Put interface down and wait 1 second
76 #/sbin/ifconfig $Bluetooth_IF down 2>/dev/null
77 #sleep 1
79 # Unload module
80 ( /sbin/modprobe -r $BLUETOOTH_DRIVER 2>/dev/null && (
81 # If successful, disable card through rkfill and save the state
82 [ -e "$RADIO_CONTROL" ] && echo 0 > $RADIO_CONTROL
83 echo 0 > $EEEPC_RADIO_SAVED_STATE_FILE
85 # Execute post-down commands
86 execute_commands "${COMMANDS_BLUETOOTH_POST_DOWN[@]}"
88 eeepc_notify "Bluetooth Radio is now off" gnome-dev-wavelan
89 ) || (
90 # If module unloading unsuccessful, try again
91 eeepc_notify "Could not disable Bluetooth radio" stop
92 if [ $1 -lt $WIFI_TOGGLE_MAX_TRY ]; then
93 eeepc_notify "Trying again in 2 second ($(($1+1)) / $WIFI_TOGGLE_MAX_TRY)" gnome-dev-wavelan
94 sleep 2
95 radio_off $(($1+1))
97 ) )
100 function radio_toggle {
101 if [ "$RADIO_STATE" = "1" ]; then
102 radio_off 1
103 else
104 radio_on 1
108 function radio_restore {
109 if [ "$RADIO_SAVED_STATE" = "1" ]; then
110 radio_on 1
111 else
112 radio_off 1
116 case $1 in
117 "restore")
118 radio_restore
120 "off")
121 radio_off 1
123 "on")
124 radio_on 1
127 radio_toggle
129 esac