Advertisement
Guest User

/etc/acpi/handler.sh

a guest
Apr 27th, 2011
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. #!/bin/bash
  2. # /etc/acpi/handler.sh
  3.  
  4. DBUS=$(ps aux | grep 'dbus-launch' | grep -ve root -ve grep)
  5. if [[ ! -z $DBUS ]];then
  6. USER=$(echo $DBUS | awk '{print $1}')
  7. USERHOME=$(getent passwd $USER | cut -d: -f6)
  8. export XAUTHORITY="$USERHOME/.Xauthority"
  9. for x in /tmp/.X11-unix/*; do
  10. DISPLAYNUM=$(echo $x | sed s#/tmp/.X11-unix/X##)
  11. if [[ -f "$XAUTHORITY" ]]; then
  12. export DISPLAY=":$DISPLAYNUM"
  13. fi
  14. done
  15. else
  16. USER=demian
  17. USERHOME=/home/$USER
  18. export XAUTHORITY="$USERHOME/.Xauthority"
  19. export DISPLAY=":0"
  20. fi
  21. PATH=$USERHOME/.bin:/bin:/usr/bin:/sbin:/usr/sbin
  22. THEFT=$(pgrep theft)
  23. THEFTMODULE=$(lsmod | grep hdaps)
  24. DOCKED=$(cat /sys/devices/platform/dock.0/docked)
  25. WLAN=$(find /sys/class/net | grep -o 'wlan[0-9]')
  26. if [[ -z $WLAN ]] || [[ $(echo $WLAN | wc -l) -ge 2 ]];then
  27. export WLAN=wlan0
  28. fi
  29. WLANSTATE=$(ifconfig | grep -c $WLAN)
  30. NETPROFILE=$(netcfg current)
  31. BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
  32. BTCAT=$(cat $BT)
  33. BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
  34. LVDS1=$(xrandr | grep LVDS1)
  35. HDMI2=$(xrandr | grep HDMI2)
  36. VGA1=$(xrandr | grep VGA1)
  37. BAT=/sys/devices/platform/smapi/BAT0
  38. START=$(cat $BAT/start_charge_thresh)
  39. STOP=$(cat $BAT/stop_charge_thresh)
  40. BRIGHT=/sys/class/backlight/acpi_video0/brightness
  41. HARDBLOCKED=$(rfkill list | grep -c 'Hard blocked: yes')
  42. AC=$(grep -c on-line /proc/acpi/ac_adapter/AC/state)
  43. DISPON=$(xset q | grep -c 'Monitor is On')
  44. EVENT=$1\ $2\ $3\ $4
  45. #MINSPEED=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)
  46. #MAXSPEED=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
  47. #SETSPEED="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
  48.  
  49. case "$EVENT" in
  50. butt*lid*) if [[ $DOCKED = 0 ]];then
  51. pm-suspend
  52. # su -c slock $USER
  53. fi;;
  54. ac*0) # no ac attached
  55. #echo -n $MINSPEED >$SETSPEED
  56. [[ $(cat $BRIGHT) != 4 ]] && echo 4 > $BRIGHT
  57. [[ $(cpufreq-info | grep -c ondemand) != 4 ]] && cpufreq-set -rg ondemand;;
  58. ac*1) # ac attached
  59. #echo -n $MAXSPEED >$SETSPEED
  60. [[ $START != 85 ]] && echo 85 > $BAT/start_charge_thresh
  61. [[ $STOP != 95 ]] && echo 95 > $BAT/stop_charge_thresh
  62. [[ $(cat $BRIGHT) != 8 ]] && echo 8 > $BRIGHT
  63. [[ $(cpufreq-info | grep -c ondemand) != 4 ]] && cpufreq-set -rg ondemand;;
  64. bat*0);; # no battery
  65. bat*1) # battery
  66. [[ $(ethtool eth0 | grep -c ": d") = 0 ]] && ethtool -s eth0 wol d;;
  67. ibm*1001) # FN+F1
  68. [[ $DISPON = 1 ]] && vbetool dpms on && xrandr --auto;;
  69. ibm*1002) # FN+F2
  70. /etc/rc.d/acpid stop
  71. xset dpms force off
  72. [[ -z $THEFTMODULE ]] && modprobe hdaps && sleep 1
  73. theft &
  74. echo 7 blink >> /proc/acpi/ibm/led
  75. su -c slock $USER
  76. killall theft
  77. echo 7 off >> /proc/acpi/ibm/led
  78. /etc/rc.d/acpid start &;;
  79. ibm*1003) # FN+F3
  80. xset dpms force off;;
  81. ibm*1004) # FN+F4
  82. pm-suspend;;
  83. # su -c slock $USER;;
  84. ibm*1005) # FN+F5
  85. case "$WLANSTATE" in
  86. 1) ifconfig $WLAN down;;
  87. 0) ifconfig $WLAN up;;
  88. esac;;
  89. ibm*1006) # FN+F6
  90. case "$BTCAT" in
  91. 1) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
  92. echo 0 > $BT;;
  93. 0) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
  94. echo 1 > $BT;;
  95. esac;;
  96. ibm*1007) # FN+F7
  97. case "$LVDS1" in
  98. "LVDS1 connected"*)
  99. case "$HDMI2" in
  100. "HDMI2 connected 1"*) xrandr --output HDMI2 --off --output LVDS1 --auto;;
  101. "HDMI2 connected ("*) xrandr --output LVDS1 --off --output HDMI2 --auto
  102. [[ $(echo $VGA1 | grep -c 'VGA1 connected') = 1 ]] && xrandr --output VGA1 --right-of HDMI2
  103. sh $USERHOME/.wallpaper;;
  104. esac
  105. case "$VGA1" in
  106. "VGA1 connected 1"*) xrandr --output VGA1 --off --output LVDS1 --auto;;
  107. "VGA1 connected ("*) xrandr --output LVDS1 --off --output VGA1 --auto
  108. [[ $(echo $HDMI2 | grep -c 'HDMI2 connected') = 1 ]] && xrandr --output HDMI2 --left-of VGA1
  109. sh $USERHOME/.wallpaper;;
  110. esac;;
  111. "LVDS1 disconnected"*);;
  112. *);;
  113. esac;;
  114. ibm*1008) # FN+F8
  115. case "$LVDS1" in
  116. "LVDS1 connected 1"*)
  117. case "$HDMI2" in
  118. "HDMI2 connected 1"*) xrandr --output HDMI2 --off --output LVDS1 --auto;;
  119. "HDMI2 connected ("*) xrandr --output HDMI2 --auto --left-of LVDS1
  120. sh $USERHOME/.wallpaper;;
  121. *);;
  122. esac
  123. case "$VGA1" in
  124. "VGA1 connected 1"*) xrandr --output VGA1 --off --output LVDS1 --auto;;
  125. "VGA1 connected ("*) xrandr --output VGA1 --auto --left-of LVDS1
  126. sh $USERHOME/.wallpaper;;
  127. *);;
  128. esac;;
  129. "LVDS1 connected ("*)
  130. case "$HDMI2" in
  131. "HDMI2 connected 1"*) xrandr --output LVDS1 --auto --right-of HDMI2;;
  132. *);;
  133. esac
  134. case "$VGA1" in
  135. "VGA1 connected 1"*) xrandr --output LVDS1 --auto --right-of VGA1;;
  136. *);;
  137. esac;;
  138. "LVDS1 disconnected"*);;
  139. *);;
  140. esac;;
  141. ibm*1009) # FN+F9
  142. if [[ -z $THEFT ]];then
  143. [[ -z $THEFTMODULE ]] && modprobe hdaps && sleep 1
  144. theft &
  145. echo 7 blink >> /proc/acpi/ibm/led
  146. else
  147. kill $THEFT
  148. echo 7 off >> /proc/acpi/ibm/led
  149. fi;;
  150. ibm*100b) # FN+F11
  151. shutdown -r now;;
  152. ibm*100c) # FN+F12
  153. shutdown -h now;;
  154. ibm*1014) # FN+SPACE
  155. if [[ $(cat $BRIGHT) != 9 ]];then
  156. echo 9 > $BRIGHT
  157. else
  158. echo 4 > $BRIGHT
  159. fi;;
  160. ibm*1015);; # VOLUME UP
  161. ibm*1016);; # VOLUME DOWN
  162. ibm*1018) # ThinkVantage
  163. mute;;
  164. ibm*6030) # DOCK EVENT
  165. if [[ $DOCKED = 1 ]];then
  166. dock -v
  167. fi;;
  168. ibm*7000) # RFKILL
  169. if [[ $HARDBLOCKED = 0 ]];then
  170. rfkill block bluetooth
  171. case $NETPROFILE in
  172. home) ;;
  173. # '') netcfg bett;;
  174. *) netcfg all-resume;;
  175. esac
  176. else
  177. case $NETPROFILE in
  178. home) ;;
  179. *) netcfg all-suspend;;
  180. esac
  181. fi;;
  182. vid*86);; # FN+POS1
  183. vid*87);; # FN+END
  184. *) logger "$EVENT undefined";;
  185. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement