#!/bin/sh
#author coreplayer2
#Updated by CNK
# version 2.12
#JUN 28 2025

###################################
# firefox_getLatest is a script to
# download and install the latest
# version of Firefox with locale
# support
# May be run with options, eg:
# firefox_getLatest.sh -h
# firefox_getLatest.sh -m
###################################

. /etc/init.d/tc-functions
useBusybox

trap 'f_cleanup ; trap 2 ; kill -2 $$' 1 2 3 13 15

if [ "$USER" = root ] ; then
   echo "Don't run as root please, exiting."
   sleep 2
   exit 1
fi

OIFS=$IFS
IFS=' '

##******************************************************************************************************************
##***************************************************Functions******************************************************

##draw at full screen width a line in blue ( use xy=(line#) for row position )
f_line() {
wide=$(stty size | cut -d" " -f2)
printf "\033["$xy";0H${BLUE}"
printf '%*s\n' "$(( wide-1 ))" '' | tr ' ' =
printf "${NORMAL}"
}

f_cleanup (){
find /tmp/firefox* \( -type d -o -type f \) -exec sudo chown $(id -un):$(id -gn) {} +
clean1ist="/tmp/firefox.* /tmp/ff*"
for clean in ${clean1ist}; do
   rm -fr $clean
done

if [ -f ${tczStore}/test_file ]; then
  rm -f ${tczStore}/test_file
fi

IFS=$OIFS
}

f_location (){
getMirror
echo " ${MAGENTA}Repo ${WHITE}in use: ${CYAN}$MIRROR${NORMAL} "
echo " ${MAGENTA}TCE ${WHITE}directory in use: ${CYAN}${tczStore}${NORMAL} "
}

f_connchk (){
echo " ${MAGENTA}Verifying connection to server, please wait...${NORMAL}"
wget --spider -q -T 20 ${address}
case $? in
	0)
	   echo " ${GREEN}connection ok${NORMAL}"
	;;
	1)
           echo " ${YELLOW}${message}${NORMAL}"
           sleep 5
           exit
	;;
esac
}

f_freespace (){
free=$(df -m /dev/$tcz_partition | grep dev | awk '{ printf "%d\n",$4 }')
if [ ! -z $free ]; then
    if [ $free -lt $required ]; then
	echo -e " ${YELLOW}Caution, ${WHITE}$tcz_partition ${YELLOW}has less than ${WHITE}${required} MB ${YELLOW}free space remaining ${NORMAL}"
	xy=4
	f_line
	echo -e " Please free up space to continue\n exiting... "
	sleep 10
	exit 2
    fi
    if [ $free -gt 200 ]; then
	echo -e " ${MAGENTA}$tcz_partition ${WHITE}has: ${CYAN}${free} MB ${WHITE}free space remaining${NORMAL} "
	xy=4
	f_line
    fi
fi
if [ -z $free ]; then
	echo -e " ${YELLOW}Caution, unable to determine free space remaining ${NORMAL}"
	sleep 4
fi
}


##******************************************************************************************************************
##*****************************************************Main*********************************************************

unset l
unset free
unset ans
unset VER
unset VX
unset ffdownload
unset installdir
unset rebootToInstall
unset altver
unset verify
unset gpgv_cmd
unset MOZURL

required=100
ff=firefox
tce_dir=/etc/sysconfig/tcedir
op=${tce_dir}/optional
tczStore=$(readlink -f $op)
part1=${tczStore#/mnt/}
tcz_partition=${part1%%/*}
tczup=${tczStore}/upgrade
ffBuild=firefox.${RANDOM}$RANDOM
ffBuildPath=/tmp/$ffBuild
ffdirpath=${ffBuildPath}/firefox/usr/local
addressX='http://download.mozilla.org/?os=linux&product='
product=firefox-latest
ffdownload="http://download.cdn.mozilla.net/pub/firefox/releases/34.0.5/linux-i686/en-US/firefox-34.0.5.tar"
message1="check internet connection, then try again"
xy=0
mkdep=1
COMPRESSION=bz2

#Options
while getopts aebmdhg option
do
	case "$option" in
		a ) mode=1 ; ;;
		e ) altver=esr ; product=firefox-esr-latest ; ;;
		b ) altver="b[[:digit:]]*" ; product=firefox-beta-latest ; ;;
		m ) mode=2 ; ;;
		d ) mkdep=0 ; ;;
		h ) help=1 ; ;;
		g ) verify=1 ; ;;
	esac
done
unset option

clear
f_location
[ -z "$tcz_partition" ] || f_freespace
xy=4
f_line

echo "mkdep: $mkdep"

##Help
if [ "x$help" == x1 ]; then
  cat <<-helpinfo
================================================================
 Default:       firefox_getLatest.sh -a  (auto detect mode)
================================================================
 Latest ESR:	firefox_getLatest.sh -e
================================================================
 Latest Beta:	firefox_getLatest.sh -b
================================================================
 Manual:        firefox_getLatest.sh -m  (manually enter version)

                Specify exact firefox version to install
                perhaps the latest or an earlier version
                eg: 38.0 || 39.0.3 || 40.0 || 40.0.2
                or 52.1.2esr (for ESR version)
                or 42.0b9 (sample for a beta version)

 note: you can find available valid versions from
 http://download.cdn.mozilla.net/pub/firefox/releases/
================================================================
 Help:          firefox_getLatest.sh -h  (this help menu)
 Disable regenerating .dep file:	firefox_getLatest.sh -d
 Verify OpenPGP signature:		firefox_getLatest.sh -g
================================================================
helpinfo
exit 3
fi

#f_cleanup >/dev/null 2>&1
IFS=' '
##test for writable tce dir
if [ ! -f "${tczStore}/test_file" ]; then
  touch ${tczStore}/test_file
  if [ "x$?" != x0 ]; then
      echo "${RED} tce directory not writable${NORMAL} "
      f_cleanup >/dev/null 2>&1
      exit 4
  fi
fi


echo -e "\n ${BLUE}Fetching dependencies${NORMAL}.. "
unset address
unset message
address="$(cat /opt/tcemirror)"
message=$message1
f_connchk

#load dependencies
#check for old versions of squashfs-tools
toolsOld=squashfs-tools-4.x.tcz
toolsNew=squashfs-tools.tcz
tcVer=$(version)
tcMajorVer=${tcVer%%.*}
case $tcMajorVer in
  [45]) [ -f /lib/ld-linux-x86-64.so.2 ] && sqfsTools=$toolsNew || sqfsTools=$toolsOld ;;
     *) sqfsTools=$toolsNew ;;
esac

deps1="$sqfsTools wget.tcz ca-certificates.tcz"

deps2="gtk3.tcz 
libasound.tcz 
dbus-glib.tcz 
hicolor-icon-theme.tcz 
cairo.tcz 
gamin.tcz 
libGLESv2.tcz 
gdk-pixbuf2.tcz 
gcc_libs.tcz 
libXt.tcz 
libXtst.tcz"

pideps="gtk3.tcz 
libasound.tcz 
dbus-glib.tcz 
hicolor-icon-theme.tcz 
cairo.tcz 
gamin.tcz 
libGLES.tcz 
gdk-pixbuf.tcz 
gcc_libs.tcz 
libXt.tcz 
libXtst.tcz"

##discover firefox arch
lib=$(uname -m)
case $lib in
  x86_64) [ -f /lib/ld-linux-x86-64.so.* ] && ffdownload=${ffdownload/linux-i686/linux-x86_64} ;;
  aarch64)
    if [ -f /lib/ld-linux-aarch64.so.* ]; then
      ffdownload=${ffdownload/linux-i686/linux-aarch64}
      deps2="$pideps"
    else
      lib=arm32
    fi
  ;;
  arm*) lib=arm32 ;;
  *) lib=x86 ;;
esac

if [ "$lib" == "arm32" ]; then
  echo "${RED}Sorry, Firefox builds are not available for 32-bit ARM/PiCore.${NORMAL}"
  f_cleanup >/dev/null 2>&1
  exit 7
fi

#GnuPG set-up
if [ "$verify" ]; then
 if [ -e ~/.gnupg/trustedkeys.kbx -o -e ~/.gnupg/trustedkeys.gpg ]; then
  deps1="$deps1 gnupg"
 else
  echo -e "${YELLOW}GnuPG trustedkeys file not found. Cannot verify signature:${NORMAL}\n\
 Save the latest GPG key published on the Mozilla Blog\n\
 ( https://blog.mozilla.org/security/ ) to \"/tmp/mozkey\", then run:\n\
    gpg --no-default-keyring --keyring ~/.gnupg/trustedkeys.kbx --import /tmp/mozkey\n\
    (use command \"gpg2\" on x86)"
  read -p " Press Enter to exit"
  f_cleanup >/dev/null 2>&1
  exit 14
 fi
fi

for Z in $deps1 $deps2
do
	Z="${Z#*$'\n'}"
	if [ ! -e $tczStore/$Z ]; then
	  if ! tce-load -w $Z >/dev/null; then
	      echo "${RED}  Dependency $Z download failed${NORMAL} "
	      f_cleanup >/dev/null 2>&1
	      exit 5
	  fi
        fi
done

if ! tce-load -i $deps1 >/dev/null; then
 echo "${RED}  Dependency install failed${NORMAL} "
 f_cleanup >/dev/null 2>&1
 exit 5
fi

#As of TC14, x86 gnupg.tcz has /usr/local/bin/gpgv2, x86_64 has /usr/local/bin/gpgv
if [ "$verify" ]; then
 if [ -f /usr/local/bin/gpgv ]; then
  gpgv_cmd=/usr/local/bin/gpgv
 else
  if [ -f /usr/local/bin/gpgv2 ]; then
   gpgv_cmd=/usr/local/bin/gpgv2
  else
   echo "${RED}  gnupg.tcz didn't install gpgv or gpgv2. Can't verify OpenPGP signature.${NORMAL} "
   f_cleanup >/dev/null 2>&1
   exit 15
  fi
 fi
fi

#check for certificates install
[ -e /etc/ssl ] || sudo ln -s /usr/local/etc/ssl /etc/ssl

#LANG=ew_ES.ISO-8859-15 #uncomment for testing
##firefox multilanguage support
for l in $(echo ${LANG%.*}); do
case $l in
	C) l=en-US ;;		#English
	en_GB*) l=en-GB ;;
	en_ZA*) l=en-ZA ;;
	en*) l=en-US ;;
	es_ES*) l=es-ES ;;	#Spanish
	es_MX*) l=es-MX ;;
	es_CL*) l=es-CL ;;
	es_AR*) l=es-AR ;;
	es*) l=es-ES ;;
	fr*) l=fr ;;		#French
	de*) l=de ;;		#German
	af*) l=af ;;		#Afrikaans
	sq*) l=sq ;;		#Albanian
	ar*) l=ar ;;		#Arabic
	an*) l=an ;;		#Aragonese
	hy_AM*) l=hy-AM ;;	#Armenian
	ast*) l=ast ;;		#Asturian
	as*) l=as ;;		#Assamese
	az*) l=az ;;		#Azerbaijani
	eu*) l=eu ;;		#Basque
	be*) l=be ;;		#Belarusian
	bn_BD*) l=bn-BD ;;	#Bengali (Bangladesh)
	bn_IN*) l=bn-IN ;;	#Bengali (India)
	bs*) l=bs ;;		#Bosnian
	br*) l=br ;;		#Breton
	bg*) l=bg ;;		#Bulgarian
	ca*) l=ca ;;		#Catalan
	zh_CN*) l=zh-CN ;;	#Chinese (Simplified)
	zh*) l=zh-TW ;;		#Chinese (Traditional)
	hr*) l=hr ;;		#Croatian
	cs*) l=cs ;;		#Czech
	da*) l=da ;;		#Danish
	nl*) l=nl ;;		#Dutch
	et*) l=et ;;		#Estonian
	fi*) l=fi ;;		#Finnish
	fy*) l=fy-NL ;;		#Frisian
	ff*) l=ff ;;		#Fulah
	gd*) l=gd ;;		#Gaelic (Scotland)
	gl*) l=gl ;;		#Galician
	el*) l=el ;;		#Greek
	gu*) l=gu-IN ;;		#Gujarati (India)
	he*) l=he ;;		#Hebrew
	hi_IN*) l=hi-IN ;;	#Hindi (India)
	hu*) l=hu ;;		#Hungarian
	is*) l=is ;;		#Icelandic
	id*) l=id ;;		#Indonesian
	ga_IE*) l=ga-IE ;;	#Irish
	it*) l=it ;;		#Italian
	ja*) l=ja ;;		#Japanese
	kn*) l=kn ;;		#Kannada
	kk*) l=kk ;;		#Kazakh
	km*) l=km ;;		#Khmer
	ko*) l=ko ;;		#Korean
	lv*) l=lv ;;		#Latvian
	lt*) l=lt ;;		#Lithuanian
	mk*) l=mk ;;		#Macedonian
	ms*) l=ms ;;		#Malay
	ml*) l=ml ;;		#Malayalam
	mr*) l=mr ;;		#Marathi
	nb_NO*) l=nb-NO ;;	#Norwegian (Bokmal)
	nn_NO*) l=nn-NO ;;	#Norwegian (Nynorsk)
	or*) l=or ;;		#Oriya
	fa*) l=fa ;;		#Persian
	pl*) l=pl ;;		#Polish
	pt_BR*) l=pt-BR ;;	#Portuguese (Brazilian)
	pt_PT*) l=pt-PT ;;	#Portuguese (Portugal)
	ro*) l=ro ;;		#Romanian
	ru*) l=ru ;;		#Russian
	sr*) l=sr ;;		#Serbian
	si*) l=si ;;		#Sinhala
	sk*) l=sk ;;		#Slovak
	sl*) l=sl ;;		#Slovenian
	sv_SE*) l=sv-SE ;;	#Swedish
	ta*) l=ta ;;		#Tamil
	te*) l=te ;;		#Telugu
	th*) l=th ;;		#Thai
	tr*) l=tr ;;		#Turkish
	uk*) l=uk ;;		#Ukrainian
	hsb*) l=hsb ;;		#Upper Sorbian
	uz*) l=uz ;;		#Uzbek
	vi*) l=vi ;;		#Vietnamese
	cy*) l=cy ;;		#Welsh
	xh*) l=xh ;;		#Xhosa
	*) l=en-US ; echo -e "\n ${YELLOW}Error. Check locale bootcode, \
using defualt${NORMAL}.\n " ;;	#fallback defualt
esac
done
ffdownload=${ffdownload/en-US/$l}


##**********************************************download selection**************************************************

case ${mode:=1} in
1 )
#auto discover version
echo -e "\n ${BLUE}Acquiring latest version${NORMAL}.. "
cd /tmp

MOZURL="$(/usr/local/bin/wget -q --max-redirect 0 -S --spider "$addressX$product" 2>&1 | grep '^[[:blank:]]*Location: ')"
COMPRESSION="${MOZURL##*.}"
VER=$(expr "$MOZURL" : ".*releases/\([[:digit:]]*\.[[:digit:].]*$altver\)/") #"

if [ -n "$VER" ]; then
  echo -e "\n ${GREEN}The Latest version ${WHITE}is ${CYAN}${VER}${NORMAL} \n "
echo -e " ${BLUE}Downloading Firefox${NORMAL}.. \n "
  if ! /usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER}.$COMPRESSION -O /tmp/firefox.tar.$COMPRESSION; then
    echo -e " ${RED}Downloading Firefox from alternate URL${NORMAL}.. \n "
    MOZURL=${MOZURL#*Location: }
    [ "$lib" != "x86" ] && MOZURL=${MOZURL/linux-i686/linux-$lib}
    /usr/local/bin/wget -c -t 20 ${MOZURL/en-US/$l} -O /tmp/firefox.tar.$COMPRESSION || exit 11
  fi
else
  echo -e "\n ${YELLOW}Error acquiring latest version${NORMAL},\n \
suggest using the manual option \n \
see \"firefox_getLatest.sh -h\" for more "
read -p " Press Enter to exit"
exit 6
fi
;;

2 )
#specify version
echo -e "\n Enter exact version requested. \n For example to download \
version 34.0.5 simply type \n\n  ${WHITE}34.0.5${NORMAL} \n"
echo -n " at the prompt, then select enter: "

read -t 300 VER

unset address
unset message
address=${ffdownload//34.0.5/$VER}
address2=${ffdownload//34.0.5/$VER}
[ ${VER%%.*} -gt 134 ] && COMPRESSION=xz

/usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER}.$COMPRESSION -O /tmp/firefox.tar.$COMPRESSION || exit 11
;;

* )
 echo -e "\n\n${YELLOW}Error key not supported\n\n${NORMAL}"
;;

esac

#End of Version selection
##******************************************************************************************************************
#Verify OpenPGP Signature

if [ "$verify" ]; then
 echo -e "\n ${BLUE}Verifying OpenPGP signature${NORMAL}.."
 if [ $mode -ne 4 ]; then
  /usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER}.$COMPRESSION.asc -O /tmp/firefox.tar.$COMPRESSION.asc || exit 12
 fi
 if $gpgv_cmd /tmp/firefox.tar.$COMPRESSION.asc /tmp/firefox.tar.$COMPRESSION ; then
  echo -e "\n ${GREEN}Signature verified${NORMAL}"
 else
  echo -e "\n ${YELLOW}Error verifying signature${NORMAL},"
  read -p " Press Enter to exit"
  f_cleanup >/dev/null 2>&1
  exit 13
 fi
fi

#End of verification
##******************************************************************************************************************
#Create new extension

if [ ! -d "$ffBuildPath" ]; then
dirlist="tce.installed \
share/applications \
share/doc/${ff} \
share/pixmaps "

for d in $dirlist
do 
  [ ! -f ${ffdirpath}/$d ] && mkdir -p ${ffdirpath}/$d
done
fi

if [ -e /usr/local/tce.installed/firefox ] ; then
installdir="$tczup"
else
installdir="$tczStore"
fi

##Make support files
[ $mkdep -gt 0 ] && echo "$deps2" > "${ffBuildPath}/${ff}.tcz.dep"

cat > ${ffdirpath}/share/applications/${ff}.desktop << "EOF1"
[Desktop Entry]
Name=firefox
Exec=firefox
Terminal=False
Comment=Firefox Web Browser
StartupNotify=True
Type=Application
Categories=Application;Network;
Icon=firefox.png
X-FullPathIcon=/usr/local/share/pixmaps/firefox.png

EOF1

cat > ${ffdirpath}/share/applications/${ff}~1.desktop << "EOF8"
[Desktop Entry]
Name=firefox_private
GenericName=Web Browser
Exec=firefox -private-window
Terminal=False
Comment=Firefox Web Browser
StartupNotify=True
Type=Application
Categories=Application;Network;
Icon=firefox.png
X-FullPathIcon=/usr/local/share/pixmaps/firefox.png

EOF8

cat > ${ffdirpath}/share/applications/${ff}~2.desktop << "EOF9"
[Desktop Entry]
Name=firefox_safe-mode
GenericName=Web Browser
Exec=firefox -safe-mode
Terminal=False
Comment=Firefox Web Browser
StartupNotify=True
Type=Application
Categories=Application;Network;
Icon=firefox.png
X-FullPathIcon=/usr/local/share/pixmaps/firefox.png

EOF9

if [ "$lib" == "x86" ]; then
cat > ${ffdirpath}/tce.installed/${ff} << "EOF2"
#!/bin/sh
[ -d /var/lib/dbus ] || mkdir -p /var/lib/dbus
[ -f /var/lib/dbus/machine-id ] || dbus-uuidgen --ensure=/var/lib/dbus/machine-id

if [ -f /usr/local/bin/firefox ] ; then
	rm -rf /usr/local/bin/firefox
	ln -s /usr/local/firefox/firefox /usr/local/bin/firefox
else
ln -s /usr/local/firefox/firefox /usr/local/bin/firefox
fi

EOF2

else
cat > ${ffdirpath}/tce.installed/firefox << "EOF3"
#!/bin/sh

# ln to binary on PATH
if [ ! -h /usr/local/bin/firefox ]; then
	ln -s /usr/local/firefox/firefox /usr/local/bin/firefox
fi

# ln lib64 to lib
if [ ! -e /lib64 ]; then
	ln -s /lib /lib64
fi

EOF3
fi


licensefile="${ffdirpath}/share/doc/${ff}/COPYING"
while [ ! -f "$licensefile" ]; do
cat > $licensefile << "EOF5"
License information may be obtained from
about:license

EOF5
done


cd /tmp
#updating build dir with archive contents

if [ -f /tmp/firefox.tar.$COMPRESSION ] ; then
echo -e "\n ${BLUE}Unpacking Archive${NORMAL}.. "
{
  if [ $COMPRESSION == "bz2" ]; then
      tar jxf firefox.tar.bz2 -C $ffdirpath
  else
      tar Jxf firefox.tar.xz -C $ffdirpath
  fi
  if [ "x$?" != x0 ]; then
      echo "${RED} Corrupt archive, please re-start operation ${NORMAL} "
      f_cleanup >/dev/null 2>&1
      sleep 5
  fi
} &
rotdash $!
fi

[ -d $ffdirpath/firefox ] || exit 9

if [ ! -f ${ffdirpath}/share/pixmaps/firefox.png ]; then
  cp ${ffdirpath}/${ff}/browser/chrome/icons/default/default48.png ${ffdirpath}/share/pixmaps/${ff}.png
fi


#set permissions
if [ "$PWD" != "$ffBuildPath/${ff}" ]; then
  cd $ffBuildPath/${ff}
fi

find . -type d -exec sudo chown root:root {} +
find . -type d -exec sudo chmod 755 {} +
find . -type f -exec sudo chown root:root {} +
cd ..
find $ffdirpath -iname tce.installed -exec sudo chown root:staff {} +
find $ffdirpath -iname tce.installed -exec sudo chmod 775 {} +
find ${ffdirpath}/tce.installed -type f -exec sudo chown tc:staff {} +
find ${ffdirpath}/tce.installed -type f -exec sudo chmod 755 {} +


echo -e "\n ${BLUE}Creating extension${NORMAL}.. "
mksquashfs ${ff}/ ${ff}.tcz 1>/dev/null
md5sum ${ff}.tcz > ${ff}.tcz.md5.txt

if [ ! -d ${tczup} ]; then
  mkdir -p ${tczup}
fi

if [ -f "${tczup}/${ff}.tcz" ]; then
  rm -f ${tczup}/${ff}.tcz
fi

echo -e "\n ${BLUE}Installing firefox${NORMAL}.. "
sleep 1
copylist="firefox.tcz \
firefox.tcz.md5.txt"

[ $mkdep -gt 0 ] && copylist="$copylist firefox.tcz.dep"

for c in $copylist
do 
  [ -f ${ffBuildPath}/$c ] && cp ${ffBuildPath}/$c ${installdir}/$c
done


cd "$tce_dir"
bootlist=$(getbootparam lst)
[ -n "$bootlist" ] || bootlist="onboot.lst"

#load latest firefox if no other firefox is already loaded
if [ x"$installdir" = x"$tczStore" ]; then
  if [ ! -f /usr/local/tce.installed/firefox ]; then
    if [ ! -f /usr/local/tce.installed/firefox-ESR ]; then
      if [ ! -f /usr/local/tce.installed/firefox-official ]; then
        tce-load -i -s ${tczStore}/firefox.tcz
        [ ! -f /usr/local/tce.installed/firefox ] || \
echo -e "\n ${BLUE}Firefox has been installed${NORMAL}.. "
        rebootToInstall=0
      fi
    fi
  fi
elif [ x"$installdir" = x"$tczup" ]; then
  echo -e "\n ${BLUE}Firefox has been scheduled to update an \n \
existing install on next reboot${NORMAL}.. \n"
  rebootToInstall=1
fi

#if firefox*(anyVersion) not in onboot.lst then speak out!
if [ x0 = x$(grep -c firefox-ESR.tcz ${tce_dir}/$bootlist) ]; then
  if [ x0 = x$(grep -c firefox-official.tcz ${tce_dir}/$bootlist) ]; then
    if [ x0 = x$(grep -c firefox.tcz ${tce_dir}/$bootlist) ]; then
      echo -e " ${MAGENTA}Note: ${CYAN}If you want firefox to load on each reboot, \n \
      remember to add "firefox.tcz" to your onboot.lst ${NORMAL}.. "
      rebootToInstall=2
    fi
  fi
fi

#if firefox*(oldVersion) is installed in onboot.lst then add new version to list
if [ x1 = x$(grep -c firefox-ESR.tcz ${tce_dir}/$bootlist) ] || \
[ x1 = x$(grep -c firefox-official.tcz ${tce_dir}/$bootlist) ]; then
  echo "firefox.tcz" >> ${tce_dir}/$bootlist
  rebootToInstall=1
fi

#uninstall old firefox extensions
if [ -f "${tczStore}/firefox-official.tcz" ]; then
	tce-audit builddb >/dev/null 2>&1
	echo -e "\n Preparing to uninstall deprecated firefox-official.tcz "
	tce-audit delete /etc/sysconfig/tcedir/optional/firefox-official.tcz
	rebootToInstall=1
fi
if [ -f "${tczStore}/firefox-ESR.tcz" ]; then
	tce-audit builddb >/dev/null 2>&1
	echo -e "\n Preparing to uninstall firefox-ESR.tcz "
	tce-audit delete /etc/sysconfig/tcedir/optional/firefox-ESR.tcz
	rebootToInstall=1
fi

[ ! -f "${tczup}/firefox.tcz" ] || rebootToInstall=1

f_cleanup >/dev/null 2>&1

IFS=$OIFS

case $rebootToInstall in
  0 )
     exit 0
  ;;
  1 )
     echo -e "\n${GREEN} Please reboot to complete install${NORMAL}\n"
     read -p " Press Enter to exit"
     exit 10
  ;;
  2 )
     read -p " Press Enter to exit"
     exit 0
  ;;
esac


##*******************************************************End********************************************************
##******************************************************************************************************************


