General TC > Programming & Scripting - Unofficial

Firefox - Extension to install the latest version

<< < (14/17) > >>

coreplayer2:
Your welcome

It should work from a cd as I've tested the script from many scenarios.  Maybe it is related to the file system, however now that I'm looking at the startup file I see where this needs work and will fix it ASAP


Sent from my iPhone using Tapatalk

coreplayer2:
Updated "firefox_getLatest.tcz" extension submitted to x86 and x86_64 repo's.

Updates dep files for for addition of GTK3 and contains "lib64" fix for corepure64.



Script v2.2 is attached for your perusal or if preferred to update firefox.tcz (rather than wait for extension submission process)

coreplayer2:
Updated "firefox_getLatest" extension submitted to x86 and x86_64 repo's

To comply with latest busybox changes.


In case anyone has difficulty with the current extension no longer completing the connection check, an updated script has been attached to this post

coreplayer2:
Updated "firefox_getLatest.tcz" extension posted to x86 and x86_64 repo's.

Updates include addition of run time dependencies (one is critical for firefox v64.0)

gcc_libs.tcz
gdk-pixbuf2.tcz
 

xor:

--- Quote from: coreplayer2 on December 18, 2018, 12:07:24 PM ---Updated "firefox_getLatest.tcz" extension posted to x86 and x86_64 repo's.

Updates include addition of run time dependencies (one is critical for firefox v64.0)

gcc_libs.tcz
gdk-pixbuf2.tcz

--- End quote ---

can you add the current code to the forum!?


--- Code: ---#!/bin/sh
#author coreplayer2
# version 2.4
#Aug 03 2017

###################################
# 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 -exec sudo chown tc:staff {} +
find /tmp/firefox* -type f -exec sudo chown tc:staff {} +

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

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=firefox-latest'
addressY="https://dl.dropboxusercontent.com/u/35323031/TC_FIREFOX_VERSION/ffAltVersion"
ffdownload="http://download.cdn.mozilla.net/pub/mozilla.org/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


#Options
while getopts amh option
do
case "$option" in
a ) mode=1 ; break;;
m ) mode=2 ; break;;
h ) help=1 ; break;;
esac
done
unset option


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


##Help
if [ "x$help" == x1 ]; then
  clear
  cat <<-helpinfo
================================================================
 Default:       firefox_getLatest.sh -a  (auto detect mode)

================================================================
 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/mozilla.org/firefox/releases/
================================================================
 help:          firefox_getLatest.sh -h  (this help menu)

================================================================
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 \
ca-certificates"

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


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


##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

curl -s $addressX 2>/dev/null | grep -o '[[:digit:]]*\.[[:digit:]]' 2>/dev/null | sort -u | tail -1 >/tmp/ffversion
curl -s $addressX 2>/dev/null | grep -o '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]' 2>/dev/null | sort -u | tail -1 >>/tmp/ffversion
VER=$(cat /tmp/ffversion | sort -u | tail -1)

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
else
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
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
;;

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
else
echo " ${YELLOW} No path file found, please try again${NORMAL}"
f_cleanup >/dev/null 2>&1
sleep 5
exit 8
fi
;;

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

esac

#End of Version selection
##******************************************************************************************************************
#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
echo "gtk3.tcz
libasound.tcz
dbus-glib.tcz
hicolor-icon-theme.tcz
cairo.tcz
gamin.tcz
libGLESv2.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 \
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 depreciated 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********************************************************
##******************************************************************************************************************

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version