From 5c5e293d1c66d5ce8bbce2d9e8e02f921fa431e7 Mon Sep 17 00:00:00 2001 From: exu Date: Sat, 22 Jul 2023 16:35:07 +0200 Subject: [PATCH] Add check for running thunderbird and offer to stop it --- .../scripts/pieces/thunderbird-backup.sh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch-config/scripts/pieces/thunderbird-backup.sh b/arch-config/scripts/pieces/thunderbird-backup.sh index 34465803..6151a316 100755 --- a/arch-config/scripts/pieces/thunderbird-backup.sh +++ b/arch-config/scripts/pieces/thunderbird-backup.sh @@ -1,6 +1,41 @@ #!/usr/bin/env sh set -euo pipefail +# exit thunderbird +fn_killbird() { + # kill thunderbird + pkill thunderbird + # wait for a bit before checking again + sleep 5s +} + +# check if thunderbird is running +fn_checkbird() { + # check for thunderbird using pgrep + while [ $(pgrep thunderbird) ]; do + # get user input whether to shut down or exit + # default is exiting + read -p "Thunderbird is running. Do you want to shut it down now? [yN]: " yn + case $yn in + # handle closing thunderbird + [Yy]*) + fn_killbird + break + ;; + # explicit no, exit + [Nn]*) + echo "Please close Thunderbird and try again." + exit + ;; + # implicit no, exit + *) + echo "Please close Thunderbird and try again." + exit + ;; + esac + done +} + # prompt for password echo -n "Password: " read -s -r pass @@ -17,6 +52,9 @@ if [ ! "$pass" = "$pass2" ]; then exit fi +# check if thunderbird is running +fn_checkbird + # go to home dir cd "$HOME"