i3-layout-loader 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # This script loads saved layouts in i3.
  3. # This script hightly depends on personal preferences and
  4. # must be edited accordingly.
  5. # i3-layout-loader - Load i3 saved layouts
  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-layout-loader
  20. # to make it executable.
  21. version=2.0
  22. # This checks if the vm $0 exists. If it does, starts the update.
  23. # Otherwise aborts.
  24. netvmlist=( "sys-whonix" )
  25. vmlist=( "fedora-24-secure" "fedora-24-sys" "fedora-24-personal" "fedora-24-work" "fedora-24-untrusted" "whonix-ws" "whonix-gw" )
  26. # Display help message
  27. display_help()
  28. {
  29. echo " This script loads saved layouts in i3. It hightly depends on personal preferences and must be edited accordingly.
  30. - v, --version Display current version
  31. -h, --help Display this message
  32. personal Load personal layout
  33. work Load work layout
  34. browsing Load browsing layout
  35. update Load update layout"
  36. exit 0
  37. }
  38. # Check if a vm exists
  39. checker()
  40. {
  41. vmstate=`qvm-check $1 | grep "not"`
  42. if [ -z "$vmstate" ]; then
  43. echo "VM $1 exists."
  44. else
  45. echo "The VM $1 does not exist. aborting"
  46. exit 2
  47. fi
  48. }
  49. # Starts the update in a VM
  50. starter()
  51. {
  52. qvm-run -q --tray -a $1 -- 'bash /etc/qubes-rpc/qubes.InstallUpdatesGUI' &
  53. echo "Starting $1..."
  54. }
  55. # This waits until:
  56. # $1 = 0: The vm $0 is running
  57. # $1 = 1; The vm $0 is stopped
  58. delayer()
  59. {
  60. vmstate=`qvm-check --running $1 | grep "not"`
  61. if [ "$2" = 0 ]; then
  62. while [ ! -z "$vmstate" ]; do
  63. echo "Waiting for VM $1 to finish startup..."
  64. sleep 1
  65. vmstate=`qvm-check --running $1 | grep "not"`
  66. done
  67. elif [ "$2" = 1 ]; then
  68. while [ -z "$vmstate" ]; do
  69. echo "Waiting for VM $1 to close..."
  70. sleep 5
  71. vmstate=`qvm-check --running $1 | grep "not"`
  72. done
  73. fi
  74. sleep 2
  75. }
  76. if [[ "$#" -ge 2 ]]; then
  77. echo "Usage: $0 {-v, --version | -h --help}"
  78. exit 2
  79. elif [[ $# -le 1 ]]; then
  80. case $1 in
  81. -v | --version)
  82. echo "$0 - Version $version"
  83. exit 0
  84. ;;
  85. -h | --help)
  86. display_help
  87. ;;
  88. personal)
  89. i3-msg "workspace 1; append_layout ~/.config/i3/layouts/TildaFirefoxPersonal.json"
  90. qvm-run -q --tray -a personal -- 'qubes-desktop-run /usr/share/applications/firefox.desktop; qubes-desktop-run /usr/share/applications/tilda.desktop'
  91. ;;
  92. work)
  93. i3-msg "workspace 3; append_layout ~/.config/i3/layouts/FileManagerTerminalEditorWorkWorkPub.json"
  94. i3-msg "workspace 2; append_layout ~/.config/i3/layouts/TexstudioWorkWorkPub.json"
  95. qvm-run -q --tray -a work-pub -- 'qubes-desktop-run /usr/share/applications/org.gnome.Nautilus.desktop; qubes-desktop-run /usr/share/applications/org.gnome.Terminal.desktop; qubes-desktop-run /usr/share/applications/texstudio.desktop' &
  96. qvm-run -q --tray -a work -- 'qubes-desktop-run /usr/share/applications/org.gnome.Nautilus.desktop; qubes-desktop-run /usr/share/applications/org.gnome.Terminal.desktop; qubes-desktop-run /usr/share/applications/texstudio.desktop'
  97. ;;
  98. browsing)
  99. i3-msg "workspace 5; append_layout ~/.config/i3/layouts/Browsing.json"
  100. qvm-run -q --tray -a work-pub -- 'qubes-desktop-run /usr/share/applications/firefox.desktop' &
  101. qvm-run -q --tray -a untrusted -- 'qubes-desktop-run /usr/share/applications/firefox.desktop' &
  102. ;;
  103. update)
  104. i3-msg "workspace 10; append_layout ~/.config/i3/layouts/Update.json"
  105. for i in ${netvmlist[*]};
  106. do
  107. checker $i
  108. qvm-start -q $i &
  109. delayer $i 0
  110. done
  111. for i in ${vmlist[*]};
  112. do
  113. checker $i
  114. starter $i
  115. delayer $i 0
  116. done
  117. for i in ${vmlist[*]};
  118. do
  119. delayer $i 1
  120. done
  121. for i in ${netvmlist[*]};
  122. do
  123. echo "Shutting down VM $i..."
  124. qvm-shutdown -q $i
  125. done
  126. ;;
  127. *)
  128. echo "Usage: $0 {-v, --version|-h, --help|personal|work|browsing|update}"
  129. exit 2
  130. esac
  131. fi