Linux, hacer que el botón de power (on/off) apague el computador solo si no hay nadie loggeado (Ubuntu 14.04)

From Wiki de Flat Estrategia Digital
Jump to: navigation, search

Para hacer que el botón de encendido y apagado del computador lo apague al hacer click se modifica el archivo /etc/acpi/powerbtn.sh. Solamente se apaga si no hay nadie loggeado al sistema.

Este archivo pertenece a Ubuntu Linux 12.04.

El resultado es el siguiente, las líneas amarillas muestran la modificación realizada.

 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 # If logind is running, it already handles power button presses; desktop
 9 # environments put inhibitors to logind if they want to handle the key
10 # themselves.
11 if pidof systemd-logind >/dev/null; then
12 	# Add next lines for power button shutdown if no user is logged
13         if [ -z "`who`" ]; then
14                 /sbin/shutdown -h now "Power button pressed"
15         fi
16     exit 0
17 fi
18 
19 # getXuser gets the X user belonging to the display in $displaynum.
20 # If you want the foreground X user, use getXconsole!
21 getXuser() {
22         user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
23         if [ x"$user" = x"" ]; then
24                 startx=`pgrep -n startx`
25                 if [ x"$startx" != x"" ]; then
26                         user=`ps -o user --no-headers $startx`
27                 fi
28         fi
29         if [ x"$user" != x"" ]; then
30                 userhome=`getent passwd $user | cut -d: -f6`
31                 export XAUTHORITY=$userhome/.Xauthority
32         else
33                 export XAUTHORITY=""
34         fi
35         export XUSER=$user
36 }
37 
38 # Skip if we just in the middle of resuming.
39 test -f /var/lock/acpisleep && exit 0
40 
41 # If the current X console user is running a power management daemon that
42 # handles suspend/resume requests, let them handle policy This is effectively
43 # the same as 'acpi-support's '/usr/share/acpi-support/policy-funcs' file.
44 
45 [ -r /usr/share/acpi-support/power-funcs ] && getXconsole
46 PMS="gnome-settings-daemon kpowersave xfce4-power-manager"
47 PMS="$PMS guidance-power-manager.py dalston-power-applet"
48 PMS="$PMS mate-settings-daemon"
49 PMS="$PMS unity-settings-daemon"
50 
51 if pidof x $PMS > /dev/null; then
52         exit
53 elif test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon; then
54         exit
55 elif test "$XUSER" != "" && test -x /usr/bin/qdbus; then
56         kded4pid=$(pgrep -n -u $XUSER kded4)
57         if test "$kded4pid" != ""; then
58                 dbusaddr=$(su - $XUSER -c "grep -z DBUS_SESSION_BUS_ADDRESS /proc/$kded4pid/environ")
59                 if test "$dbusaddr" != "" && su - $XUSER -c "export $dbusaddr; qdbus org.kde.kded" | grep -q powerdevil; then
60                         exit
61                 fi
62         fi
63 fi
64 
65 # If all else failed, just initiate a plain shutdown.
66 /sbin/shutdown -h now "Power button pressed"

Facebook Comments