snips/leave_session.laptop.sh

42 lines
907 B
Bash
Raw Normal View History

2019-05-05 03:18:08 +00:00
#!/bin/bash
#
# For this to work, something along the following lines needs to be
# in a file in /etc/sudoers.d/. The file must have 0440 permissions
#
# username ALL=(ALL:ALL) NOPASSWD:/usr/sbin/pm-suspend,/usr/sbin/pm-hibernate,/sbin/reboot,/sbin/shutdown
#
confirm() {
2019-08-17 03:06:22 +00:00
ans=$(echo -e "Yes\nNo" | dmenu -p "$1 - Confirm?")
2019-05-05 03:18:08 +00:00
echo $ans
if [ "$ans" = "Yes" ]; then
echo "Leaving..."
else
echo "Abort!"
exit 1
fi
}
cmd=$(echo -e "hibernate\nsuspend\nreboot\nshutdown" | dmenu -p "Leave session:")
echo $cmd
case "$cmd" in
suspend)
confirm "Suspend"
2020-12-25 06:05:18 +00:00
sudo /usr/sbin/pm-suspend-hybrid
2019-05-05 03:18:08 +00:00
;;
hibernate)
confirm "Hibernate"
2020-12-25 06:05:18 +00:00
sudo /usr/sbin/pm-hibernate
2019-05-05 03:18:08 +00:00
;;
reboot)
confirm "Reboot"
sudo /sbin/reboot
;;
shutdown)
confirm "Shutdown"
sudo /sbin/shutdown
;;
esac