Skip to content

Instantly share code, notes, and snippets.

@ngadmini
Last active June 9, 2023 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngadmini/522f482baacece8dfca570a113b28102 to your computer and use it in GitHub Desktop.
Save ngadmini/522f482baacece8dfca570a113b28102 to your computer and use it in GitHub Desktop.
Bash script for update/install Mozilla Firefox on Debian
#!/usr/bin/env bash
# TAGS
# firefox_update.sh V-4.3
# https://gist.github.com/ngadmini/522f482baacece8dfca570a113b28102
# AUTHOR
# ngadimin@warnet-ersa.net
# TL;DR
# install (system-wide installation) OR update to latest version of Mozilla Firefox
# suggestion NOPASSWD for sudo:
# echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
# pgrep firefox | xargs kill
set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_exec=/usr/bin/firefox-bin
_path=/opt/firefox
_app=/usr/share/applications/Firefox.desktop
_tar=firefox.tar.bz2
:<<'comment'
_uri0="https://download.mozilla.org/?product=firefox-nightly-latest&os=linux64&lang=en-US"
_uri0="https://download.mozilla.org/?product=firefox-beta-latest&os=linux64&lang=en-US"
_uri0="https://download.mozilla.org/?product=firefox-devedition-latest&os=linux64&lang=en-US"
_uri0="https://download.mozilla.org/?product=firefox-esr-latest&os=linux64&lang=en-US"
_uri0="https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
comment
_uri0="https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
_uri1="https://raw.githubusercontent.com/mozilla/sumo-kb/main/install-firefox-linux/firefox.desktop"
_new=$(curl -sfI "${_uri0}" | sed -n 's/.*firefox-\(.*\)\.tar.*/\1/p')
f_curl() {
if command -v curl >> /dev/null 2>&1; then
true
else
printf "[FAIL] curl not installed\n"
read -r -p "[CONFIRM] do you want to install curl ? [Y/n] " confirm
case ${confirm:0:1} in
y|Y|"") printf "[INFO] installing curl ..."
sudo apt install curl -y -qq >> /dev/null 2>&1;;
*) printf "exiting\n"; return 1;;
esac
fi
}
f_stat() {
[[ -h ${_exec} ]] || sudo ln -sf "${_path}"/firefox "${_exec}"
for _X in {"$_path","$_path"/firefox}; do
if [[ $(stat -c "%a" "${_X}") != 755 ]]; then sudo chhmod 755 "${_X}"; fi
done
}
f_fail() { printf "[FAIL] download fail\n"; return 1; }
f_update() {
printf "[INFO] download latest version: Firefox %s\n" "${_new}"
curl -sL -o "${_tar}" "${_uri0}" || f_fail
printf "[INFO] removing old version\n"
sudo rm -rf ${_path}-*
sudo mv "${_path}" "${_path}-${_cur}"
printf "[INFO] applying latest version: Firefox %s\n" "${_new}"
sudo tar -xjf "${_tar}" -C /opt
find "${_DIR}" -type f -name "${_tar}" -print0 | xargs -r0 rm -rf
f_stat
printf "[DONE] bye!\n\n"
}
f_install() {
# check required library glibc
if ! dpkg -s "libdbus-glib-1-2" >> /dev/null 2>&1; then
sudo apt install libdbus-glib-1-2 -y -qq >> /dev/null 2>&1
fi
printf "[INFO] download latest version: Firefox %s\n" "${_new}"
curl -sL -o "${_tar}" "${_uri0}" || f_fail
printf "[INFO] applying latest version: Firefox %s\n" "${_new}"
sudo tar -xjf "${_tar}" -C /opt
find "${_DIR}" -type f -name "${_tar}" -print0 | xargs -r0 rm -rf
curl -s -o "${_app}" "${_uri1}" || f_fail
f_stat
printf "[DONE] bye!\n\n"
}
f_confirm() {
read -r -p "do you want to closed it's ? [Y/n] " answer
case ${answer:0:1} in
y|Y:"") printf "[INFO] closing and updating Firefox\n"
kill -9 "$(pgrep ${_exec##*/})"
f_update;;
*) printf "\n"; return 1;;
esac
}
f_check() {
_cur=$(firefox -v | awk -F' ' '{print $NF}')
if ! [[ ${_new} == "${_cur}" ]]; then
printf "[INFO] you're running release-version: Firefox %s\n" "${_cur}"
printf "[INFO] an update available: Firefox %s\n" "${_new}"
if pgrep -x "${_exec##*/})" &>/dev/null; then
f_update
else
printf "[FAIL] %s is running (proc_id: %s)\n" "${_exec##*/}" "$(pgrep ${_exec##*/})"
printf "[HINT] closed it's, then run %s again\n" "${0##*/}"
f_confirm # append option to close running firefox, then update it's
fi
else
printf "[INFO] no update available\nyou're running latest release-version: Firefox %s\n\n" "${_new}"
return 1
fi
}
# main script
cd "${_DIR}"
printf "\n[INFO] starting %s ...\n" "${0##*/}"
f_curl
if command -v firefox >> /dev/null 2>&1; then
f_check
else
printf "[INFO] look like firefox not installed\n"
# append option to install it's
read -r -p "do you want to install it's ? [Y/n] " answer
case ${answer:0:1} in
y|Y|"") f_install;;
*) printf "\n"; exit 1;;
esac
fi
exit 0
@ngadmini
Copy link
Author

ngadmini commented Nov 2, 2022

direct usage:

curl -sL https://gist.github.com/ngadmini/522f482baacece8dfca570a113b28102/raw | bash
wget -qO- https://gist.github.com/ngadmini/522f482baacece8dfca570a113b28102/raw | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment