#!/bin/sh
#set -x
#
# automagic download of latest firefox/thunderbird
#
# Copyright (C) 2015 by Window Maker Live <wmlive@sf.net>
# 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 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ ! -x /usr/bin/links ]
then
echo This script requires /usr/bin/curl to be installed
echo Install it first with \'apt-get -u -m install curl\'.
exit 0
elif [ ! -x /usr/bin/wget ]
then
echo This script requires /usr/bin/wget to be installed.
echo Install it first with \'apt-get -u -m install wget\'.
exit 0
fi
SYSENVLANG=$(echo $LANG | cut -d. -f1)
if [ "$SYSENVLANG" = "de_DE" ]
then
MOZLANG=de
else
MOZLANG=en-US
fi
MOZWORKDIR=/opt
if [ "$MOZARCH" = "" ]
then
MOZARCH="linux-$(uname -m)"
fi
MOZTARGETDIR=$MOZWORKDIR/$MOZARCH/$MOZLANG
if [ ! -d $MOZTARGETDIR ]
then
mkdir -p $MOZTARGETDIR
fi
moz_cleanup ()
{
if [ -d $MOZTARGETDIR ]
then
cd $MOZTARGETDIR && \
if [ "$(echo "$MOZPROG"*.tar.bz2 | wc -w)" -gt "1" ]
then
echo Clean up from obsolete $1 download archives:
for BZMOZTAR in $(ls "$MOZPROG"*.tar.bz2)
do
if [ "$BZMOZTAR" != "$LATESTVER" ]
then
rm -vf $(basename "$BZMOZTAR" .bz2).*
fi
done
echo ""
fi
fi
}
opt_moz_replace ()
{
cd $MOZWORKDIR && \
for MOZREPLACE in "$1"
do
echo Replacing "$MOZWORKDIR"/"$MOZREPLACE" with new version
echo ""
[ -d "$MOZREPLACE"_old ] && rm -rf "$MOZREPLACE"_old
[ -d "$MOZREPLACE" ] && mv "$MOZREPLACE" "$MOZREPLACE"_old
tar xjf $MOZTARGETDIR/$LATESTVER
done
}
moz_version_check ()
{
cd $MOZWORKDIR && \
for MOZVARIANT in "$1"
do
export LATESTVER=$MOZVARIANT-"$(curl -sl ftp://ftp.mozilla.org/pub/mozilla.org/$MOZPROG/releases/ | grep -v [a-zA-Z] | sort -n | tail -n 1)".tar.bz2
export LATESTMOZ=$(basename $(echo "$LATESTVER" | cut -d\- -f2) .tar.bz2)
if [ -s $MOZWORKDIR/$MOZVARIANT/application.ini ]
then
export CURRENTMOZ=$(grep ^Version $MOZWORKDIR/$MOZVARIANT/application.ini | cut -d= -f2)
else
export CURRENTMOZ=""
fi
if [ "$CURRENTMOZ" = "" ]
then
echo "No valid $MOZVARIANT installation found."
elif [ "$LATESTMOZ" = "$CURRENTMOZ" ]
then
echo "Installed $MOZVARIANT $LATESTMOZ is already up to date."
else
echo "Currently installed $MOZVARIANT version is $CURRENTMOZ."
fi
done
}
check_integrity ()
{
echo Verifying integrity of existing $LATESTVER file
cd $MOZTARGETDIR && \
BZINTEGRITY="$(tar tjf $LATESTVER > /dev/null 2>&1; echo $?)"
if [ "$BZINTEGRITY" != "0" ]
then
echo File $LATESTVER was not fully downloaded.
echo Continuing download of $MOZPROG update:
echo ""
cd $MOZTARGETDIR && \
wget -c --no-http-keep-alive --no-remove-listing --progress=dot ftp://ftp.mozilla.org/pub/mozilla.org/$MOZPROG/releases/$LATESTVER/$MOZARCH/$MOZLANG/$LATESTVER
fi
}
mozfetch ()
{
if [ -d $MOZTARGETDIR ]
then
cd $MOZTARGETDIR && \
for MOZPROG in firefox thunderbird
do
moz_version_check $MOZPROG
if [ "$LATESTMOZ" != "$CURRENTMOZ" ]
then
cd $MOZTARGETDIR && \
if [ -s $LATESTVER ]
then
check_integrity
else
echo Downloading $MOZLANG language $MOZPROG update $LATESTMOZ
cd $MOZTARGETDIR && \
wget -c --no-http-keep-alive --no-remove-listing --progress=dot ftp://ftp.mozilla.org/pub/mozilla.org/$MOZPROG/releases/latest/$MOZARCH/$MOZLANG/$LATESTVER
check_integrity
fi
opt_moz_replace $MOZPROG
fi
moz_cleanup $MOZPROG
done
fi
}
mozfetch