Skip to content

Instantly share code, notes, and snippets.

@caugner
Last active February 7, 2017 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caugner/c898527227fadc3ffa4cf5a11b0351f4 to your computer and use it in GitHub Desktop.
Save caugner/c898527227fadc3ffa4cf5a11b0351f4 to your computer and use it in GitHub Desktop.
A simple updater for Mozilla Firefox Nightly in Linux multi-user environments.
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# A simple updater for Mozilla Firefox Nightly in Linux multi-user environments.
#
# Choose your OS, architecture and destination here:
NIGHTLY_OS='linux'
NIGHTLY_ARCH='x86_64'
NIGHTLY_DEST='/opt'
# Check connectivity.
if ! ping -q -c 1 -W 1 mozilla.org >/dev/null; then
echo "Please turn on the internet."
exit 1
fi
# Check permissions.
if [[ $(id -u) -ne 0 ]]; then
echo "Please sudo me."
exit 1
fi
# Paths.
NIGHTLY_TAR="$NIGHTLY_DEST/nightly.tar.bz2"
NIGHTLY_DIR_CURR="$NIGHTLY_DEST/nightly"
NIGHTLY_DIR_PREV="$NIGHTLY_DEST/nightly-prev"
NIGHTLY_DIR_TEMP="$NIGHTLY_DEST/nightly-tmp"
echo "======================="
echo "Firefox Nightly Updater"
echo "======================="
echo "1. Retrieve version..."
NIGHTLY_VERSION=`curl --silent https://hg.mozilla.org/mozilla-central/raw-file/default/config/milestone.txt | grep -v "#" | tr -d '\040\011\012\015'`
echo " => $NIGHTLY_VERSION"
# URL differs for localised builds.
NIGHTLY_URL="https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-$NIGHTLY_VERSION.en-US.$NIGHTLY_OS-$NIGHTLY_ARCH.tar.bz2"
echo "2. Download version..."
if [[ -f "$NIGHTLY_TAR" ]]; then
NIGHTLY_STATUS=`curl --silent --location -z "$NIGHTLY_TAR" -o "$NIGHTLY_TAR" "$NIGHTLY_URL" --write-out %{http_code}`
else
NIGHTLY_STATUS=`curl --silent --location -o "$NIGHTLY_TAR" "$NIGHTLY_URL" --write-out %{http_code}`
fi
# Check HTTP status code.
if [[ $NIGHTLY_STATUS == "304" ]]; then
echo " => No new version."
exit 1
elif [[ $NIGHTLY_STATUS -ne "200" ]]; then
echo " => Oops, got HTTP $NIGHTLY_STATUS."
exit 0
fi
echo "3. Extract version..."
# Delete previous-previous version.
if [ -d "$NIGHTLY_DIR_PREV" ]; then
rm -rf "$NIGHTLY_DIR_PREV"
fi
# Delete temporary folder (just in case).
if [ -d "$NIGHTLY_DIR_TEMP" ]; then
rm -rf "$NIGHTLY_DIR_TEMP"
fi
# Extract current version.
mkdir "$NIGHTLY_DIR_TEMP"
tar -xf "$NIGHTLY_TAR" -C "$NIGHTLY_DIR_TEMP" --strip-component=1
# Move current version.
mv $NIGHTLY_DIR_TEMP $NIGHTLY_DIR_CURR
echo " => Update finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment