i3-exit 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # This is a simple program that makes shutdown easier for QubesOS.
  3. # May not work out of the box, you will have to specify in the script
  4. # your net-vm and usb-vm names.
  5. # i3-exit - A simple QubesOS shutdown script
  6. # Copyright (C) 2017 Fabrizio Romano Genovese <egonigredo@gmail.com>
  7. # This copyrighted material is made available to anyone wishing to use,
  8. # modify, copy, or redistribute it subject to the terms and conditions of
  9. # the GNU General Public License v.2, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY expressed or implied, including the implied warranties of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  14. # Public License for more details.
  15. # You should have received a copy of the
  16. # GNU General Public License along with this program; if not,
  17. # see <http://www.gnu.org/licenses/>
  18. # Put this file in /bin/ or in /usr/bin. Do not forget to give
  19. # sudo chmod +x i3-exit
  20. # to make it executable.
  21. version=1.0
  22. qubesnetvm=sys-net
  23. qubesusbvm=sys-usb
  24. # Shuts down all the virtual machines in a wise way
  25. vm_shutdown()
  26. {
  27. echo "Shutting down everything"
  28. qvm-shutdown --wait --all --exclude=$qubesnetvm --exclude=$qubesusbvm
  29. echo "Killing sys-usb"
  30. qvm-kill sys-usb
  31. echo "Killing sys-net"
  32. qvm-kill sys-net
  33. sleep 3
  34. }
  35. # Checks which screensaver is installed and tries to use it
  36. screen_lock()
  37. {
  38. if [ -a /bin/i3-blur ]; then
  39. i3-blur
  40. elif [ -a /bin/i3lock ]; then
  41. i3lock
  42. else
  43. echo "What screensaver are you using? I cannot find it."
  44. exit 2
  45. fi
  46. }
  47. if [[ "$#" -ge 2 ]]; then
  48. echo "0 {-v, --version|-h, --help|lock|logout|suspend|hibernate|reboot|shutdown}"
  49. exit 2
  50. elif [[ "$#" -eq 1 ]]; then
  51. case "$1" in
  52. -v | --version)
  53. echo "$0 - Version $version"
  54. exit 0;;
  55. -h | --help)
  56. echo "This is a simple program that makes shutdown/hibernate/reboot etc. easier for QubesOS users having i3. May not work out of the box, you will have to specify in the script your net-vm and usb-vm names."
  57. echo "- v, --version Display current version"
  58. echo "-h, --help Display this message"
  59. echo "lock Lock the screen"
  60. echo "logout Logout current user"
  61. echo "suspend Suspend system"
  62. echo "hibernate Hibernate system"
  63. echo "reboot Reboot system"
  64. echo "shutdown Power off system"
  65. exit 0
  66. ;;
  67. lock)
  68. screen_lock
  69. ;;
  70. logout)
  71. i3-msg exit
  72. ;;
  73. suspend)
  74. screen_lock && systemctl suspend
  75. ;;
  76. hibernate)
  77. screen_lock && systemctl hibernate
  78. ;;
  79. reboot)
  80. vm_shutdown; reboot
  81. ;;
  82. shutdown)
  83. vm_shutdown; shutdown now
  84. ;;
  85. *)
  86. echo "Usage: $0 {-v, --version|-h, --help|lock|logout|suspend|hibernate|reboot|shutdown}"
  87. exit 2
  88. esac
  89. fi
  90. exit 0