#!/bin/sh #author coreplayer2 #Minor changes by CNK # version 2.10 #JUL 6 2023 ################################### # 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 " ${MAGENTA}Using alternative web address...${NORMAL}" wget --spider -q -T 20 ${address2} case $? in 0) echo " ${GREEN}connection ok${NORMAL}" ;; 1) echo " ${YELLOW}${message}${NORMAL}" sleep 5 exit ;; esac ;; 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 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='https://download.mozilla.org/?product=' product=firefox-latest addressY="https://dl.dropboxusercontent.com/u/35323031/TC_FIREFOX_VERSION/ffAltVersion" ffdownload="http://download.cdn.mozilla.net/pub/firefox/releases/34.0.5/linux-i686/en-US/firefox-34.0.5.tar.bz2" message1="check internet connection, then try again" message2="verify connection, perhaps a typo? then try again" lib=0 xy=0 mkdep=1 #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 clear 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="http://tinycorelinux.net/index.html" address2="http://forum.tinycorelinux.net/index.php" message=$message1 f_connchk #load dependencies #check for old versions of squashfs-tools toolsOld=squashfs-tools-4.x toolsNew=squashfs-tools 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 \ curl \ wget \ bzip2 \ file \ gtk3 \ libasound \ dbus-glib \ hicolor-icon-theme \ cairo \ gamin \ libGLESv2 \ gdk-pixbuf2 \ gcc_libs \ ca-certificates \ libXt \ libXtst" #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 do tce-load -w $Z 1>/dev/null tce-load -i $Z 1>/dev/null if [ ! -e /usr/local/tce.installed/$Z ]; then echo "${RED} Dependency install failed${NORMAL} " f_cleanup >/dev/null 2>&1 exit 5 fi done #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 cirtificates install [ -e /etc/ssl ] || sudo ln -s /usr/local/etc/ssl /etc/ssl #Check for pre-downloaded file [ -e /tmp/firefox.tar.bz2 ] && mode=4 ##discover firefox arch ARCH=$(uname -m) case $ARCH in x86_64) [ -f /lib/ld-linux-x86-64.so.2 ] && ffdownload=${ffdownload/linux-i686/linux-x86_64}; lib=x86_64 ;; esac #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 VER=$(expr "$(curl -s $addressX$product 2>/dev/null)" : ".*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 " /usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER} -O /tmp/firefox.tar.bz2 || exit 11 else if [ "$product" = "firefox-latest" ]; then echo -e "${YELLOW} Version not found, \n ${BLUE}attempting alternate method${NORMAL}.." f_cleanup >/dev/null 2>&1 wget $addressY >/dev/null 2>&1 VER=$(cat /tmp/ffAltVersion) if [ -n "$VER" ]; then echo -e "\n ${GREEN}The Latest version ${WHITE}is ${CYAN}${VER}${NORMAL} \n " echo -e " ${BLUE}Downloading Firefox${NORMAL}.. \n " /usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER} -O /tmp/firefox.tar.bz2 || exit 11 fi fi fi if [ ! -n "$VER" ]; then 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} message=$message2 f_connchk /usr/local/bin/wget -c -t 20 ${ffdownload//34.0.5/$VER} -O /tmp/firefox.tar.bz2 || exit 11 ;; 3 ) #modify download link (This feature to be completed soon) if [ ! -f "/tmp/ffdownload_link.txt" ]; then echo "$ffdownload" > /tmp/ffdownload_link.txt echo -e " The download link has been saved in /tmp/ffdownload_link.txt until next reboot. please edit the download path specifying version directoy, filename and language as desired. save the file and restart this update script selecting option ${WHITE}(${MAGENTA}3${WHITE})${NORMAL} again to use the modified address\n\n " sleep 30 exit 7 fi ffpath=$(cat /tmp/ffdownload_link.txt) if [ -f "/tmp/ffdownload_link.txt" ]; then unset address unset message address=${ffpath} address2=${ffpath} message=$message2 f_connchk /usr/local/bin/wget -c -t 20 ${ffpath} -O /tmp/firefox.tar.bz2 || exit 11 else echo " ${YELLOW} No path file found, please try again${NORMAL}" f_cleanup >/dev/null 2>&1 sleep 5 exit 8 fi ;; 4 ) echo " ${YELLOW}Using existing Firefox download at /tmp/firefox.tar.bz2${NORMAL}" ;; * ) 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}.asc -O /tmp/firefox.tar.bz2.asc || exit 12 fi if $gpgv_cmd /tmp/firefox.tar.bz2.asc /tmp/firefox.tar.bz2 ; 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 ##****************************************************************************************************************** #Creat 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 [ -f "${tczStore}/firefox.tcz" ] ; then installdir="$tczup" else installdir="$tczStore" fi ##Make support files [ $mkdep -gt 0 ] && echo "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 " > "${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 [ x"$lib" != xx86_64 ]; 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 elif [ x"$lib" == xx86_64 ]; then 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.bz2 ] ; then echo -e "\n ${BLUE}Unpacking Archive${NORMAL}.. " { tar jxvf firefox.tar.bz2 -C $ffdirpath 1>/dev/null if [ "x$?" != x0 ]; then echo "${RED} Corrupt archive, please re-start operation ${NORMAL} " f_cleanup >/dev/null 2>&1 sleep 5 exit 9 fi } & rotdash $! fi 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******************************************************** ##******************************************************************************************************************