Guest User

/etc/acpi/powerbtn.sh

a guest
Oct 21st, 2013
786
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # /etc/acpi/powerbtn.sh
  3. # Initiates a shutdown when the power putton has been
  4. # pressed.
  5.  
  6. [ -r /usr/share/acpi-support/power-funcs ] && . /usr/share/acpi-support/power-funcs
  7.  
  8. # getXuser gets the X user belonging to the display in $displaynum.
  9. # If you want the foreground X user, use getXconsole!
  10. getXuser() {
  11.         user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
  12.         if [ x"$user" = x"" ]; then
  13.                 startx=`pgrep -n startx`
  14.                 if [ x"$startx" != x"" ]; then
  15.                         user=`ps -o user --no-headers $startx`
  16.                 fi
  17.         fi
  18.         if [ x"$user" != x"" ]; then
  19.                 userhome=`getent passwd $user | cut -d: -f6`
  20.                 export XAUTHORITY=$userhome/.Xauthority
  21.         else
  22.                 export XAUTHORITY=""
  23.         fi
  24.         export XUSER=$user
  25. }
  26.  
  27. # Skip if we just in the middle of resuming.
  28. test -f /var/lock/acpisleep && exit 0
  29.  
  30. # If the current X console user is running a power management daemon that
  31. # handles suspend/resume requests, let them handle policy This is effectively
  32. # the same as 'acpi-support's '/usr/share/acpi-support/policy-funcs' file.
  33.  
  34. [ -r /usr/share/acpi-support/power-funcs ] && getXconsole
  35. PMS="gnome-settings-daemon kpowersave xfce4-power-manager"
  36. PMS="$PMS guidance-power-manager.py dalston-power-applet"
  37. PMS="$PMS mate-settings-daemon"
  38.  
  39. if pidof x $PMS > /dev/null; then
  40.         exit
  41. elif test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon; then
  42.         exit
  43. elif test "$XUSER" != "" && test -x /usr/bin/qdbus; then
  44.         kded4pid=$(pgrep -n -u $XUSER kded4)
  45.         if test "$kded4pid" != ""; then
  46.                 dbusaddr=$(su - $XUSER -c "grep -z DBUS_SESSION_BUS_ADDRESS /proc/$kded4pid/environ")
  47.                 if test "$dbusaddr" != "" && su - $XUSER -c "export $dbusaddr; qdbus org.kde.kded" | grep -q powerdevil; then
  48.                         exit
  49.                 fi
  50.         fi
  51. fi
  52.  
  53. # If all else failed, just initiate a plain shutdown.
  54. /sbin/shutdown -h now "Power button pressed"
RAW Paste Data