-
-
Save ruario/9672798 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# latest-firefox Version 1.6.3 | |
# Contributer: drgibbon (thanks!) | |
# This script will find the latest Firefox binary package, download it | |
# and repackage it into Slackware format. | |
# I don't use Firefox for regular browsing but it is handy for | |
# comparative tests against Vivaldi. :P | |
# Copyright 2018 Ruari Oedegaard, Oslo, Norway | |
# All rights reserved. | |
# | |
# Redistribution and use of this script, with or without modification, is | |
# permitted provided that the following conditions are met: | |
# | |
# 1. Redistributions of this script must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
# HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# Check if the user asked for auto-install | |
if [ "$1" = "-i" -o "$1" = "--install" ]; then | |
if [ "$UID" = "0" ]; then | |
AUTO_INSTALL=Y | |
else | |
echo "You must be root to auto-install, $1 ignored!" >&2 | |
AUTO_INSTALL=N | |
fi | |
else | |
AUTO_INSTALL=N | |
fi | |
# Use the architecture of the current machine or whatever the user has | |
# set externally | |
ARCH=${ARCH:-$(uname -m)} | |
if [ "$ARCH" = "x86_64" ]; then | |
LIBDIRSUFFIX="64" | |
elif [[ "$ARCH" = i?86 ]]; then | |
ARCH=i686 | |
LIBDIRSUFFIX="" | |
else | |
echo "The architecture $ARCH is not supported." >&2 | |
exit 1 | |
fi | |
# Set to esr or beta to track ESR and beta channels instead of regular Firefox | |
FFESR=${FFESR:-N} | |
if [ "$FFESR" = "Y" ]; then | |
FFCHANNEL=esr-latest | |
fi | |
FFCHANNEL=${FFCHANNEL:-latest} | |
if [ "$FFCHANNEL" = "esr" ]; then | |
FFCHANNEL=esr-latest | |
elif [ "$FFCHANNEL" = "beta" ]; then | |
FFCHANNEL=beta-latest | |
fi | |
# This defines the language of the downloaded package | |
FFLANG=${FFLANG:-en-US} | |
# Work out the latest stable Firefox if VERSION is unset | |
VERSION=${VERSION:-$(wget --spider -S --max-redirect 0 "https://download.mozilla.org/?product=firefox-${FFCHANNEL}&os=linux${LIBDIRSUFFIX}&lang=${FFLANG}" 2>&1 | sed -n '/Location: /{s|.*/firefox-\(.*\)\.tar.*|\1|p;q;}')} | |
# Error out if $VERISON is unset, e.g. because previous command failed | |
if [ -z $VERSION ]; then | |
echo "Could not work out the latest version; exiting" >&2 | |
exit 1 | |
fi | |
# Don't start repackaging if the same version is already installed | |
if /bin/ls /var/log/packages/mozilla-firefox-$VERSION-* >/dev/null 2>&1 ; then | |
echo "Firefox ($VERSION) is already installed; exiting" | |
exit 0 | |
fi | |
TMP=${TMP:-/tmp} | |
OUTPUT=${OUTPUT:-/tmp} | |
BUILD=${BUILD:-1} | |
TAG=${TAG:-ro} | |
PKGTYPE=${PKGTYPE:-tgz} | |
PACKAGE="$OUTPUT/mozilla-firefox-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE" | |
# If the package was made previously, no need to make it again. ;) | |
if [ -e "$PACKAGE" ]; then | |
echo "$PACKAGE already exists; exiting" | |
exit 0 | |
fi | |
REPACKDIR=$TMP/repackage-mozilla-firefox | |
# Three sources are needed, here is where to find them if they are not | |
# already in the directory this script was started from. | |
FIREFOXPKG="https://download.mozilla.org/?product=firefox-${VERSION}&os=linux${LIBDIRSUFFIX}&lang=${FFLANG}" | |
DESKTOPFILE=https://mirrors.slackware.com/slackware/slackware-current/source/xap/mozilla-firefox/mozilla-firefox.desktop | |
SCRIPT="${0##*/}" | |
# This function can be used in place of Slackware's makepkg, with the | |
# added bonus that it is able to make packages with root owned files | |
# even when run as a regular user. | |
mkpkg() { | |
if [ "$1" = "-n" ]; then | |
TAROWNER="" | |
shift 1 | |
else | |
TAROWNER="--group 0 --owner 0" | |
fi | |
if find * -type l | grep -qm1 .; then | |
mkdir -p install | |
find * -type l -printf '( cd %h ; rm -rf %f )\n( cd %h ; ln -sf %l %f )\n' -delete > install/symlinks | |
if [ -f "install/doinst.sh" ]; then | |
printf '\n' | cat - install/doinst.sh >> install/symlinks | |
fi | |
mv install/symlinks install/doinst.sh | |
fi | |
case "$1" in | |
*tbr) cmp="brotli --quality ${BROTLI_QUALITY:-5}" ;; # Experimental support for Brotli compression | |
*tbz) | |
if command -v lbzip2 >/dev/null 2>&1; then | |
cmp=lbzip2 | |
else | |
cmp=bzip2 | |
fi | |
;; | |
*tgz) | |
if command -v pigz >/dev/null 2>&1; then | |
cmp=pigz | |
else | |
cmp=gzip | |
fi | |
;; | |
*tlz) cmp=lzma ;; | |
*txz) cmp="xz -T0" ;; | |
*tz4) cmp=lz4 ;; # Experimental support for lz4 compression | |
*tzo) cmp=lzop ;; # Experimental support for lzop compression | |
*) echo "Unknown compression type" >&2 ; exit 1 ;; | |
esac | |
if [ -x /bin/tar-1.13 ]; then | |
tar-1.13 $TAROWNER -cvvf- . | $cmp > "$1" | |
else | |
tar cvvf - . --format gnu --xform 'sx^\./\(.\)x\1x' --show-stored-names $TAROWNER | $cmp > "$1" | |
fi | |
echo "Slackware package \"$1\" created." | |
} | |
# Since packaging is about to begin errors become more important now, | |
# so exit if things fail. | |
set -eu | |
# If the repackage is already present from the past, clear it down | |
# and re-create it. | |
if [ -d "$REPACKDIR" ]; then | |
rm -fr "$REPACKDIR" | |
fi | |
mkdir -p "$REPACKDIR"/{pkg,src} | |
# Check if the current directory contains mozilla-firefox.desktop. If | |
# not try /usr/share/applications/, otherwise download it. | |
if [ -e mozilla-firefox.desktop ]; then | |
cp mozilla-firefox.desktop "$REPACKDIR/src/" | |
elif [ -e /usr/share/applications/mozilla-firefox.desktop ]; then | |
cp /usr/share/applications/mozilla-firefox.desktop "$REPACKDIR/src/" | |
else | |
wget -P "$REPACKDIR/src" $DESKTOPFILE | |
fi | |
# Save a copy if this script but remove execute persmissions as it will | |
# later be moved into the doc directory. | |
install -m 644 "${0}" "$REPACKDIR/src/$SCRIPT" | |
# Check if the current directory contains the Firefox binary package, | |
# otherwise download it. | |
if [ -e firefox-$VERSION.tar.bz2 ]; then | |
cp firefox-$VERSION.tar.bz2 "$REPACKDIR/src/" | |
else | |
wget -O "$REPACKDIR/src/firefox-$VERSION.tar.bz2" $FIREFOXPKG | |
fi | |
# Now we have all the sources in place, switch to the package directory | |
# and start setting things up. | |
cd "$REPACKDIR/pkg" | |
# Create the basic directory structure for files. | |
mkdir -p install | |
mkdir -p usr/bin | |
mkdir -p usr/doc/mozilla-firefox-$VERSION | |
mkdir -p usr/share/applications | |
mkdir -p usr/share/icons/hicolor/{16x16,32x32,48x48,128x128}/apps | |
mkdir -p usr/lib$LIBDIRSUFFIX/mozilla | |
mkdir -p usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL | |
# Copy the desktop file in place | |
cp ../src/mozilla-firefox.desktop usr/share/applications/ | |
# Copy this script into the doc directory | |
cp ../src/$SCRIPT usr/doc/mozilla-firefox-$VERSION/$SCRIPT | |
# Extract the contents of the binary Firefox package into an | |
# appropriately named lib directory. | |
tar xf ../src/firefox-$VERSION.tar.* --strip 1 -C usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL | |
# If present, move the readme or any other similar text files to the | |
# doc directory. | |
find usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL -maxdepth 1 -iname "*.txt" -exec mv {} usr/doc/mozilla-firefox-$VERSION/ \; | |
# If a plugins folder was present move it to the mozilla lib directory. | |
# Otherwise just create a directory in mozilla so that there is | |
# definately somthing to symlink to later on in the post-install. | |
if [ -d usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/plugins ]; then | |
mv usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/plugins usr/lib$LIBDIRSUFFIX/mozilla/ | |
else | |
mkdir usr/lib$LIBDIRSUFFIX/mozilla/plugins | |
fi | |
# Setup symlinks for firefox binary, plugin directory and icons. | |
( | |
cd usr/bin | |
ln -s ../lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/firefox firefox | |
) | |
# Changes in Firefox 21 mean we need to check for the browser directory | |
if [ -d usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/browser ]; then | |
( | |
cd usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/browser | |
ln -s ../../mozilla/plugins plugins | |
) | |
else | |
( | |
cd usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL | |
ln -s ../mozilla/plugins plugins | |
) | |
fi | |
# Changes in Firefox 21 mean we need to check for the location of icons | |
if /bin/ls usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/chrome/icons/default/default*.png >/dev/null 2>&1; then | |
DEFAULTICONPATH=lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/chrome/icons/default | |
ALTICONPATH=lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/icons | |
elif /bin/ls usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/browser/chrome/icons/default/default*.png >/dev/null 2>&1; then | |
DEFAULTICONPATH=lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/browser/chrome/icons/default | |
ALTICONPATH=lib$LIBDIRSUFFIX/firefox-$FFCHANNEL/browser/icons | |
else | |
echo "Changes have been made to the internal formating of the firefox source packaging!" >&2 | |
exit 1 | |
fi | |
( | |
cd usr/share/icons/hicolor/16x16/apps | |
ln -s ../../../../../$DEFAULTICONPATH/default16.png firefox.png | |
) | |
( | |
cd usr/share/icons/hicolor/32x32/apps | |
ln -s ../../../../../$DEFAULTICONPATH/default32.png firefox.png | |
) | |
( | |
cd usr/share/icons/hicolor/48x48/apps | |
ln -s ../../../../../$DEFAULTICONPATH/default48.png firefox.png | |
) | |
( | |
cd usr/share/icons/hicolor/128x128/apps | |
ln -s ../../../../../$ALTICONPATH/mozicon128.png firefox.png | |
) | |
# Now create the post-install to register the desktop file and icons. | |
cat <<EOS> install/doinst.sh | |
# Setup menu entries | |
if command -v update-desktop-database >/dev/null 2>&1; then | |
update-desktop-database -q usr/share/applications | |
fi | |
# Setup icons | |
touch -c usr/share/icons/hicolor | |
if command -v gtk-update-icon-cache >/dev/null 2>&1; then | |
gtk-update-icon-cache -tq usr/share/icons/hicolor | |
fi | |
EOS | |
# Create a description file inside the package. | |
cat <<EOD> install/slack-desc | |
|-----handy-ruler------------------------------------------------------| | |
mozilla-firefox: mozilla-firefox (Mozilla Firefox Web browser) | |
mozilla-firefox: | |
mozilla-firefox: This project is a redesign of the Mozilla browser component written | |
mozilla-firefox: using the XUL user interface language. Firefox delivers safe, easy web | |
mozilla-firefox: browsing. | |
mozilla-firefox: | |
mozilla-firefox: Visit the Mozilla Firefox project online: | |
mozilla-firefox: http://www.mozilla.org/projects/firefox/ | |
mozilla-firefox: | |
mozilla-firefox: | |
mozilla-firefox: | |
EOD | |
# Make sure the file permissions are ok | |
# This should work and did before but now apparently fails :( | |
#chmod -R u+w,go+r-w,a-s . | |
find -L . \ | |
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ | |
-o -perm 511 \) -exec chmod 755 {} \; -o \ | |
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ | |
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; | |
# Create the Slackware package | |
mkpkg "$PACKAGE" | |
# Install if the user requested it | |
if [ $AUTO_INSTALL = "Y" ]; then | |
/sbin/upgradepkg --install-new "$PACKAGE" | |
fi |
Thanks, a bunch...wonderful.
I've noticed that when using this script, every upgrade seems to trigger the creation of a new profile (and I need to manually do about:profiles
and switch back to my old profile). I'm wondering if this is because Firefox is being installed to a new directory every time? (i.e., /usr/lib$LIBDIRSUFFIX/firefox-$VERSION
). I wonder if installing to say /usr/lib$LIBDIRSUFFIX/firefox-$FFCHANNEL
instead would avoid this?
Nothing to do with the script or how it installs @drgibbon. It is a known issue that lots of users find themselves in. Loads of threads on the Slackware forums and elsewhere.
Nothing to do with the script or how it installs @drgibbon. It is a known issue that lots of users find themselves in. Loads of threads on the Slackware forums and elsewhere.
@ruario Are you sure? I never have this problem with the Slackware ESR package (which installs to /usr/lib64/firefox/
), but starting with a completely fresh profile (nuking ~/.mozilla/
), I immediately get the problem after the first upgrade using this script. Steps:
- Have two Firefox packages ready from the script (I'm using
mozilla-firefox-82.0.1-x86_64-1ro.tgz
andmozilla-firefox-82.0.2-x86_64-1ro.tgz
) - Delete
~/.mozilla/
(backing up the original obviously). - Install version 1 (82.0.1).
- Start Firefox, do some stuff. Quit it.
- Upgrade to version 2 (82.0.2).
- Start Firefox, and it creates a brand new profile.
I remember when reading about new profiles that installs on a new hard drive location would trigger a new profile, which seems to be what this script is doing (i.e., installing to firefox-$VERSION
instead of say firefox-$FFCHANNEL
).
@drgibbon I am fairly sure because I would expect a who bunch of reports. There are loads of people using this script. Search and/or post on the Slackware forums. Otherwise, if you prefer I can look later (not a good time for me now) or you can try tweaking the script and see if the problem goes away. If so I will gladly accept a pull request or a simple patch.
@ruario Ok no problem, I will test it and send a patch if it fixes it on a blank slate test.
Thanks, you are probably right. I must admit I am a little re-occupied dealing with the issues with another browser today, so perhaps I am just dismissing this too easily! 😉
https://vivaldi.com/blog/news/minor-update-2-for-vivaldi-desktop-3-4/
https://vivaldi.com/blog/news/minor-update-3-for-vivaldi-desktop-3-4/
I do appreciate your report, work investigating and any other help you give (including a patch).
OK I tested it, installing to a new hard drive location is definitely the problem (it triggers the creation of a new profile). I will send a patch.
Thank you and apologies again then for dismissing this so fast. I should know better!
No worries! :)
@ruario Any action on this one? =)
@ruario Hello just a ping for a fix.
@drgibbon: I was fiddling with this script today to create an alternate one for thunderbird and I was wondering, on this latest topic, if it could be better to name the install directory just "firefox" with no $FFCHANNEL appended, like in Slackware package (most probably for the same reason).
@Ponce The reason I went with $FFCHANNEL
was to avoid clashing with Slackware's install directory, but also to trigger the creation of a new profile on different channel installs (esr, beta, etc), since that's what the profile feature is actually intended for.
@ruario Maybe you missed the update here, but any chance you could fix this upgrade issue? It's been quite a while now, and the fix is simple.
I'll second drgibbon's request to make the change for the install location. Having the version included in the installation directory makes Firefox generate a new profile on every upgrade, which can be quite frustrating.
I agree with their assertion to use $FFCHANNEL
in the install directory so that people are able to maintain multiple channels, if desired (and it's how it's designed by Firefox developers).
I don't really use Firefox except for testing, but I made a similar change locally on my system a while back for updates and it's been working flawlessly. This will also make it easier to recommend just your script on LQ for those interested in maintaining Firefox outside of Slackware's (I'm currently recommending both yours and drgibbon's).
I don't expect that this will be fixed any time soon. Unfortunately it's probably done some damage to Firefox's reputation on Slackware too, since people blame Firefox for the upgrade process triggering a new profile creation, instead of this script.
Well, looks like it has just been fixed. Thanks.
Yes, thanks @drgibbon. Real life and work meant that I just stopped paying any attention to this and other gists that various people used. Sorry for the problems.
No worries, thanks for sorting it.
@drgibbon, I just experienced this new profile creation issue (with the current version of the script). Switching back firefox to my old profile got the issue solved as a workaround.
But in my case, it may be because I just dropped the ESR 68 version (Slackware 64 14.2 last package). Will see for the next release.
@downwater You'll trigger it any time you change the location on the disk for a particular Firefox channel (which the old script used to do on every upgrade, but now fixed).
@drgibbon, thanks for the reply, I understand now.
@Ponce
I am wondering if you got the Thunderbird script working and if it is available?
Thanks Ponce!
-Gary AKA onebuck
link in row 109 should be fixed:
DESKTOPFILE=https://mirrors.slackware.com/slackware/slackware-current/source/xap/mozilla-firefox/firefox.desktop
than some other stuff accordingly, rows 17X+, but I dont know how to do it properly.
And many thanks for this script!
Author abandoned his code, use my fork instead https://gist.github.com/ardrabczyk/ff5890294d9df5b2e9950c63b6521a65
Hi, why not to add '-ssl'?