123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #!/bin/bash
- # This script loads saved layouts in i3.
- # This script hightly depends on personal preferences and
- # must be edited accordingly.
- # i3-layout-loader - Load i3 saved layouts
- # Copyright (C) 2017 Fabrizio Romano Genovese <egonigredo@gmail.com>
- # This copyrighted material is made available to anyone wishing to use,
- # modify, copy, or redistribute it subject to the terms and conditions of
- # the GNU General Public License v.2, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful, but WITHOUT
- # ANY WARRANTY expressed or implied, including the implied warranties of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- # Public License for more details.
- # You should have received a copy of the
- # GNU General Public License along with this program; if not,
- # see <http://www.gnu.org/licenses/>
- # Put this file in /bin/ or in /usr/bin. Do not forget to give
- # sudo chmod +x i3-layout-loader
- # to make it executable.
- version=2.0
- # This checks if the vm $0 exists. If it does, starts the update.
- # Otherwise aborts.
- netvmlist=( "sys-whonix" )
- vmlist=( "fedora-24-secure" "fedora-24-sys" "fedora-24-personal" "fedora-24-work" "fedora-24-untrusted" "whonix-ws" "whonix-gw" )
- # Display help message
- display_help()
- {
- echo " This script loads saved layouts in i3. It hightly depends on personal preferences and must be edited accordingly.
- - v, --version Display current version
- -h, --help Display this message
- personal Load personal layout
- work Load work layout
- browsing Load browsing layout
- update Load update layout"
- exit 0
- }
- # Check if a vm exists
- checker()
- {
- vmstate=`qvm-check $1 | grep "not"`
- if [ -z "$vmstate" ]; then
- echo "VM $1 exists."
- else
- echo "The VM $1 does not exist. aborting"
- exit 2
- fi
- }
- # Starts the update in a VM
- starter()
- {
- qvm-run -q --tray -a $1 -- 'bash /etc/qubes-rpc/qubes.InstallUpdatesGUI' &
- echo "Starting $1..."
- }
- # This waits until:
- # $1 = 0: The vm $0 is running
- # $1 = 1; The vm $0 is stopped
- delayer()
- {
- vmstate=`qvm-check --running $1 | grep "not"`
- if [ "$2" = 0 ]; then
- while [ ! -z "$vmstate" ]; do
- echo "Waiting for VM $1 to finish startup..."
- sleep 1
- vmstate=`qvm-check --running $1 | grep "not"`
- done
- elif [ "$2" = 1 ]; then
- while [ -z "$vmstate" ]; do
- echo "Waiting for VM $1 to close..."
- sleep 5
- vmstate=`qvm-check --running $1 | grep "not"`
- done
- fi
- sleep 2
- }
- if [[ "$#" -ge 2 ]]; then
- echo "Usage: $0 {-v, --version | -h --help}"
- exit 2
- elif [[ $# -le 1 ]]; then
- case $1 in
- -v | --version)
- echo "$0 - Version $version"
- exit 0
- ;;
- -h | --help)
- display_help
- ;;
- personal)
- i3-msg "workspace 1; append_layout ~/.config/i3/layouts/TildaFirefoxPersonal.json"
- qvm-run -q --tray -a personal -- 'qubes-desktop-run /usr/share/applications/firefox.desktop; qubes-desktop-run /usr/share/applications/tilda.desktop'
- ;;
- work)
- i3-msg "workspace 3; append_layout ~/.config/i3/layouts/FileManagerTerminalEditorWorkWorkPub.json"
- i3-msg "workspace 2; append_layout ~/.config/i3/layouts/TexstudioWorkWorkPub.json"
- 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' &
- 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'
- ;;
- browsing)
- i3-msg "workspace 5; append_layout ~/.config/i3/layouts/Browsing.json"
- qvm-run -q --tray -a work-pub -- 'qubes-desktop-run /usr/share/applications/firefox.desktop' &
- qvm-run -q --tray -a untrusted -- 'qubes-desktop-run /usr/share/applications/firefox.desktop' &
- ;;
- update)
- i3-msg "workspace 10; append_layout ~/.config/i3/layouts/Update.json"
-
- for i in ${netvmlist[*]};
- do
- checker $i
- qvm-start -q $i &
- delayer $i 0
- done
- for i in ${vmlist[*]};
- do
- checker $i
- starter $i
- delayer $i 0
- done
- for i in ${vmlist[*]};
- do
- delayer $i 1
- done
- for i in ${netvmlist[*]};
- do
- echo "Shutting down VM $i..."
- qvm-shutdown -q $i
- done
- ;;
- *)
- echo "Usage: $0 {-v, --version|-h, --help|personal|work|browsing|update}"
- exit 2
- esac
- fi
|