Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # /etc/acpi/handler.sh
- DBUS=$(ps aux | grep 'dbus-launch' | grep -ve root -ve grep)
- if [[ ! -z $DBUS ]];then
- USER=$(echo $DBUS | awk '{print $1}')
- USERHOME=$(getent passwd $USER | cut -d: -f6)
- export XAUTHORITY="$USERHOME/.Xauthority"
- for x in /tmp/.X11-unix/*; do
- DISPLAYNUM=$(echo $x | sed s#/tmp/.X11-unix/X##)
- if [[ -f "$XAUTHORITY" ]]; then
- export DISPLAY=":$DISPLAYNUM"
- fi
- done
- else
- USER=demian
- USERHOME=/home/$USER
- export XAUTHORITY="$USERHOME/.Xauthority"
- export DISPLAY=":0"
- fi
- PATH=$USERHOME/.bin:/bin:/usr/bin:/sbin:/usr/sbin
- THEFT=$(pgrep theft)
- THEFTMODULE=$(lsmod | grep hdaps)
- DOCKED=$(cat /sys/devices/platform/dock.0/docked)
- WLAN=$(find /sys/class/net | grep -o 'wlan[0-9]')
- if [[ -z $WLAN ]] || [[ $(echo $WLAN | wc -l) -ge 2 ]];then
- export WLAN=wlan0
- fi
- WLANSTATE=$(ifconfig | grep -c $WLAN)
- NETPROFILE=$(netcfg current)
- BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
- BTCAT=$(cat $BT)
- BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
- LVDS1=$(xrandr | grep LVDS1)
- HDMI2=$(xrandr | grep HDMI2)
- VGA1=$(xrandr | grep VGA1)
- BAT=/sys/devices/platform/smapi/BAT0
- START=$(cat $BAT/start_charge_thresh)
- STOP=$(cat $BAT/stop_charge_thresh)
- BRIGHT=/sys/class/backlight/acpi_video0/brightness
- HARDBLOCKED=$(rfkill list | grep -c 'Hard blocked: yes')
- AC=$(grep -c on-line /proc/acpi/ac_adapter/AC/state)
- DISPON=$(xset q | grep -c 'Monitor is On')
- EVENT=$1\ $2\ $3\ $4
- #MINSPEED=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)
- #MAXSPEED=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
- #SETSPEED="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
- case "$EVENT" in
- butt*lid*) if [[ $DOCKED = 0 ]];then
- pm-suspend
- # su -c slock $USER
- fi;;
- ac*0) # no ac attached
- #echo -n $MINSPEED >$SETSPEED
- [[ $(cat $BRIGHT) != 4 ]] && echo 4 > $BRIGHT
- [[ $(cpufreq-info | grep -c ondemand) != 4 ]] && cpufreq-set -rg ondemand;;
- ac*1) # ac attached
- #echo -n $MAXSPEED >$SETSPEED
- [[ $START != 85 ]] && echo 85 > $BAT/start_charge_thresh
- [[ $STOP != 95 ]] && echo 95 > $BAT/stop_charge_thresh
- [[ $(cat $BRIGHT) != 8 ]] && echo 8 > $BRIGHT
- [[ $(cpufreq-info | grep -c ondemand) != 4 ]] && cpufreq-set -rg ondemand;;
- bat*0);; # no battery
- bat*1) # battery
- [[ $(ethtool eth0 | grep -c ": d") = 0 ]] && ethtool -s eth0 wol d;;
- ibm*1001) # FN+F1
- [[ $DISPON = 1 ]] && vbetool dpms on && xrandr --auto;;
- ibm*1002) # FN+F2
- /etc/rc.d/acpid stop
- xset dpms force off
- [[ -z $THEFTMODULE ]] && modprobe hdaps && sleep 1
- theft &
- echo 7 blink >> /proc/acpi/ibm/led
- su -c slock $USER
- killall theft
- echo 7 off >> /proc/acpi/ibm/led
- /etc/rc.d/acpid start &;;
- ibm*1003) # FN+F3
- xset dpms force off;;
- ibm*1004) # FN+F4
- pm-suspend;;
- # su -c slock $USER;;
- ibm*1005) # FN+F5
- case "$WLANSTATE" in
- 1) ifconfig $WLAN down;;
- 0) ifconfig $WLAN up;;
- esac;;
- ibm*1006) # FN+F6
- case "$BTCAT" in
- 1) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
- echo 0 > $BT;;
- 0) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
- echo 1 > $BT;;
- esac;;
- ibm*1007) # FN+F7
- case "$LVDS1" in
- "LVDS1 connected"*)
- case "$HDMI2" in
- "HDMI2 connected 1"*) xrandr --output HDMI2 --off --output LVDS1 --auto;;
- "HDMI2 connected ("*) xrandr --output LVDS1 --off --output HDMI2 --auto
- [[ $(echo $VGA1 | grep -c 'VGA1 connected') = 1 ]] && xrandr --output VGA1 --right-of HDMI2
- sh $USERHOME/.wallpaper;;
- esac
- case "$VGA1" in
- "VGA1 connected 1"*) xrandr --output VGA1 --off --output LVDS1 --auto;;
- "VGA1 connected ("*) xrandr --output LVDS1 --off --output VGA1 --auto
- [[ $(echo $HDMI2 | grep -c 'HDMI2 connected') = 1 ]] && xrandr --output HDMI2 --left-of VGA1
- sh $USERHOME/.wallpaper;;
- esac;;
- "LVDS1 disconnected"*);;
- *);;
- esac;;
- ibm*1008) # FN+F8
- case "$LVDS1" in
- "LVDS1 connected 1"*)
- case "$HDMI2" in
- "HDMI2 connected 1"*) xrandr --output HDMI2 --off --output LVDS1 --auto;;
- "HDMI2 connected ("*) xrandr --output HDMI2 --auto --left-of LVDS1
- sh $USERHOME/.wallpaper;;
- *);;
- esac
- case "$VGA1" in
- "VGA1 connected 1"*) xrandr --output VGA1 --off --output LVDS1 --auto;;
- "VGA1 connected ("*) xrandr --output VGA1 --auto --left-of LVDS1
- sh $USERHOME/.wallpaper;;
- *);;
- esac;;
- "LVDS1 connected ("*)
- case "$HDMI2" in
- "HDMI2 connected 1"*) xrandr --output LVDS1 --auto --right-of HDMI2;;
- *);;
- esac
- case "$VGA1" in
- "VGA1 connected 1"*) xrandr --output LVDS1 --auto --right-of VGA1;;
- *);;
- esac;;
- "LVDS1 disconnected"*);;
- *);;
- esac;;
- ibm*1009) # FN+F9
- if [[ -z $THEFT ]];then
- [[ -z $THEFTMODULE ]] && modprobe hdaps && sleep 1
- theft &
- echo 7 blink >> /proc/acpi/ibm/led
- else
- kill $THEFT
- echo 7 off >> /proc/acpi/ibm/led
- fi;;
- ibm*100b) # FN+F11
- shutdown -r now;;
- ibm*100c) # FN+F12
- shutdown -h now;;
- ibm*1014) # FN+SPACE
- if [[ $(cat $BRIGHT) != 9 ]];then
- echo 9 > $BRIGHT
- else
- echo 4 > $BRIGHT
- fi;;
- ibm*1015);; # VOLUME UP
- ibm*1016);; # VOLUME DOWN
- ibm*1018) # ThinkVantage
- mute;;
- ibm*6030) # DOCK EVENT
- if [[ $DOCKED = 1 ]];then
- dock -v
- fi;;
- ibm*7000) # RFKILL
- if [[ $HARDBLOCKED = 0 ]];then
- rfkill block bluetooth
- case $NETPROFILE in
- home) ;;
- # '') netcfg bett;;
- *) netcfg all-resume;;
- esac
- else
- case $NETPROFILE in
- home) ;;
- *) netcfg all-suspend;;
- esac
- fi;;
- vid*86);; # FN+POS1
- vid*87);; # FN+END
- *) logger "$EVENT undefined";;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement