#!/usr/bin/env bash
# killFirefox script
# c2007-2018 by Paul Sherman <psherman2001@gmail.com>
# does not just kill firefox-bin, but also removes lock file 
# from user home dir so that firefox can be restarted.
# uses the bash shell and xdialog
#  
# This program is free software; you can redistribute it and/or			
# modify it under the terms of the GNU General Public License	
# as published by the Free Software Foundation; either version 2	
# of the License, or (at your option) any later version.
#
DIALOG=Xdialog
# makes sure we get the correct browser, even if just changed by user
source ~/.bashrc

brow=$BROWSER

if [ "$brow" == "mozilla-firefox" ]
then
  bdir="$HOME/.mozilla/firefox"
  bname="Firefox"
  bexe="firefox"
elif [  "$brow" == "waterfox"  ]; then
  bdir="$HOME/.waterfox"
  bname="Waterfox"
  bexe="waterfox"
else
$DIALOG --title "Uh Oh..." \
        --msgbox "You don't seem to be using a Mozilla-based default browser." 0 0
		exit 0
fi

$DIALOG	--title "$bname Destroyer" \
      	--yesno "This script will close any running instances of the $bname browser.\nDo you wish to continue?" 0 0
	sel=$?
	case $sel in
		0) echo "$bname will be destroyed.";;
		1) echo "OK, never mind" ; 
		   exit ;;
		255) echo "OK, never mind" ;
		     exit ;;
	esac 
killall -9 $bexe 2>/dev/null
find "$bdir" -name ".parentlock" -exec rm {} \;
$DIALOG --title "Success..." \
        --msgbox "If any instances of $bname were open, \nthey are no more." 0 0
exit 0
