Skip to content

Instantly share code, notes, and snippets.

@monnoval
Last active November 22, 2021 01:50
Show Gist options
  • Save monnoval/4884f20a3cfef66604e130e0d61e4f1f to your computer and use it in GitHub Desktop.
Save monnoval/4884f20a3cfef66604e130e0d61e4f1f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Usage:
#
# run this script as executable
# $ chmod +x update-firefox.sh
# run as sudo and add a firefox version
# $ sudo ./update-firefox.sh 95.0b10
if [[ "null" = "$1" || -z "$1" ]]; then
echo "No arguments found"
echo "Example command:"
echo "sudo ./update-firefox.sh 95.0b10"
exit 1
fi
FIREFOX_VER=$1
FIREFOX_TAR="firefox-$FIREFOX_VER.tar.bz2"
FIREFOX_BETA="https://ftp.mozilla.org/pub/firefox/releases/$FIREFOX_VER/linux-x86_64/en-GB/$FIREFOX_TAR"
# check if Firefox Beta URL is valid and downloadable
CHECK_IF_VALID="curl --head --silent --fail $FIREFOX_BETA"
if $(eval echo $CHECK_IF_VALID) 2> /dev/null; then
echo "------"
echo "Downloading and extracting $FIREFOX_TAR ..."
# notice the URL is different when downloading Firefox Devedition
FIREFOX_DEV="https://download.mozilla.org/?product=firefox-devedition-latest-ssl&os=linux64&lang=en-US"
curl --location $FIREFOX_DEV | tar --extract --verbose --preserve-permissions --bzip2
else
# URL is not valid, exit asap
echo "Not a valid version: $FIREFOX_VER"
echo "Do check if this URL is valid:"
echo "$FIREFOX_BETA"
exit 1
fi
echo "------"
echo "Moving folders..."
# replace older firefox with new
rm -rf /opt/firefox-developer_old/
mv /opt/firefox-developer /opt/firefox-developer_old
# move new firefox
mv firefox/ /opt/
mv /opt/firefox /opt/firefox-developer
echo "------"
echo "Updating permissions..."
# this part is related to 1password integration
# more reading here https://1password.community/discussion/comment/596424/#Comment_596424
chown -R root:root /opt/firefox-developer/firefox && chmod 755 /opt/firefox-developer/firefox-bin
echo "------"
echo "If no errors above, then all GOOD! Congrats!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment