Skip to content

Instantly share code, notes, and snippets.

@Roy-Orbison
Last active January 19, 2021 05:12
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 Roy-Orbison/fde330edf17905d168516c75f57ae106 to your computer and use it in GitHub Desktop.
Save Roy-Orbison/fde330edf17905d168516c75f57ae106 to your computer and use it in GitHub Desktop.
Basic shell script to install && update the latest Thunderbird on Linux (specifically Ubuntu)
#!/bin/bash
set -e
# Installation of this script:
# Delete one of the url variables below, or get another from
# https://www.thunderbird.net/thunderbird/all/
# and substituting its version number with 'latest'
#
url='https://download.mozilla.org/?product=thunderbird-latest-SSL&os=linux64&lang=en-US'
url='https://download.mozilla.org/?product=thunderbird-latest-SSL&os=linux64&lang=en-GB'
#
# Then run:
# sudo install thunderbird-latest-update /usr/local/sbin/
#
# Desktop integration:
# save the accompanying .desktop file or adapt from
# /usr/share/applications/thunderbird.desktop
# into
# /usr/share/applications/thunderbirdLatest.desktop
# or ~/.local/share/applications/thunderbirdLatest.desktop
#
# Change your default mail client application.
dir=/opt
subdir=thunderbird
bin="$dir/$subdir/thunderbird"
arcglob='thunderbird-*.tar.*'
arcre='\S+?(?=\.tar\.)'
help=0
delete=0
check=0
install=0
existing=0
while getopts ':hcdie' opt; do
case $opt in
h)
help=1
;;
c)
check=1
;;
d)
delete=1
;;
i)
install=1
;;
e)
existing=1
;;
\?)
>&2 echo "Unknown option $OPTARG."
help=1
;;
esac
done
if ! (( help + delete + check + install )); then
help=1
fi
if (( help )); then
>&2 cat <<-EOT
${0##*/} [ -h | -c | -i [ -d ] [ -e ] | -d [ -e ] ]
Options:
-h This help.
-c Check for an update by viewing version numbers.
-i Download and update/install, overwriting any previous install.
-d Delete existing backup & archive files from previous attempts.
If combined with -ie, leaves the installation archive intact.
-e Install/keep an existing downloaded archive.
EOT
exit
fi
if (( check )); then
>&2 echo -n 'Remote: '
wget --max-redirect=0 --method=HEAD --server-response "$url" 2>&1 > /dev/null | grep -Pio '^\s+Location:.*/\D+\K'"$arcre"
if [[ -f "$bin" ]]; then
>&2 echo -n 'Installed: '
"$bin" -v | grep -Po '^\D*\K\S+'
else
>&2 echo Not installed.
fi
exit
fi
cd "$dir"
function readarcs {
arcs=()
readarray -t arcs < <(compgen -G "$arcglob" | sort -rV)
}
readarcs
if (( delete )); then
if [[ -d "$subdir~/" ]] && ! rm -r "$subdir~/"; then
>&2 echo "Could not remove backup dir $dir/$subdir~/"
exit 1
fi
keep=0
if (( existing )); then
if [[ "${#arcs[@]}" -le 1 ]]; then
keep=1
else
n=0
for arc in "${arcs[@]}"; do
n=$(( n + 1 ))
>&2 echo "$n: $arc "`stat -c'%s' "$arc"`b
done
while ! (( keep )); do
read -r -p 'Select archive to keep for installation: ' keep
if ! [[ "$keep" =~ ^[1-9][0-9]*$ ]] || (( keep > n )); then
>&2 echo Invalid selection. Ctrl + C to terminate.
keep=0
fi
done
fi
fi
n=0
for arc in "${arcs[@]}"; do
n=$(( n + 1 ))
if [[ $keep -ne $n ]] && ! rm "$arc"; then
>&2 echo "Could not remove archive $dir/$arc"
exit 1
fi
done
elif (( install )); then
if [[ -d "$subdir~/" ]] || [[ "${#arcs[@]}" -ge 2 ]] || { ! (( existing )) && [[ "${#arcs[@]}" -gt 0 ]]; }; then
>&2 echo Delete files from previous install by adding the -d option.
exit 1;
fi
fi
if (( install )); then
if ! (( existing )); then
>&2 echo -n 'Downloading... '
if ! wget -q --trust-server-names "$url"; then
>&2 echo Failed.
exit 1;
fi
fi
readarcs
if [[ "${#arcs[@]}" -ne 1 ]]; then
>&2 echo No recognised installation archive.
exit 1;
fi
arc="${arcs[0]}"
>&2 echo -n 'Installing... '
if { ! [[ -d "$subdir/" ]] || mv "$subdir/" "$subdir~/" ; } && \
tar --no-same-owner -xf "$arc" --transform='s,^[^/]\+,'"$subdir,"
then
>&2 echo Done.
else
>&2 echo Failed.
exit 1;
fi
fi
[Desktop Entry]
Encoding=UTF-8
Name=Thunderbird Mail (latest)
Comment=Send and receive mail with Thunderbird
GenericName=Mail Client
Keywords=Email;E-mail;Newsgroup;Feed;RSS
Exec=/opt/thunderbird/thunderbird %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/opt/thunderbird/chrome/icons/default/default256.png
Categories=Application;Network;Email;
MimeType=x-scheme-handler/mailto;application/x-xpinstall;
StartupNotify=true
Actions=Compose;Contacts
[Desktop Action Compose]
Name=Compose New Message (latest)
Exec=/opt/thunderbird/thunderbird -compose
OnlyShowIn=Messaging Menu;Unity;
[Desktop Action Contacts]
Name=Contacts (latest)
Exec=/opt/thunderbird/thunderbird -addressbook
OnlyShowIn=Messaging Menu;Unity;
@Roy-Orbison
Copy link
Author

Quick start (nano is just to choose/set URL):

wget https://gist.github.com/Roy-Orbison/fde330edf17905d168516c75f57ae106/raw/55b48157f6c6430266bcd43740a09322e9415ee9/thunderbird-latest-update
nano thunderbird-latest-update
sudo install thunderbird-latest-update /usr/local/sbin/
sudo thunderbird-latest-update -i
sudo wget -P /usr/share/applications/ https://gist.github.com/Roy-Orbison/fde330edf17905d168516c75f57ae106/raw/55b48157f6c6430266bcd43740a09322e9415ee9/thunderbirdLatest.desktop

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