Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Last active December 1, 2025 15:16
Show Gist options
  • Select an option

  • Save MohamedElashri/4bf2ccd7fa552fbb060017a78d4b6a11 to your computer and use it in GitHub Desktop.

Select an option

Save MohamedElashri/4bf2ccd7fa552fbb060017a78d4b6a11 to your computer and use it in GitHub Desktop.
Automate thunderbird linux update

Mozilla does provide flatback and official Flatpak for thunderbird, but they are always behind release and they usually stick for long time at old versions.

I don't want also to have to check for updates and do them manually on my linux machine. so I wrote this to do automate the process

  1. Create the auto-update script: ~/.local/bin/update-thunderbird
#!/bin/bash
set -euo pipefail

LOG="${HOME}/.local/log/thunderbird-update.log"
mkdir -p "$(dirname "$LOG")"

log() { echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG"; }
error() { echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: $*" >&2 | tee -a "$LOG"; exit 1; }

log "Starting Thunderbird update check..."

# --- 1. Get candidate version from API ---
CANDIDATE_VERSION=$(curl -fsS "https://product-details.mozilla.org/1.0/thunderbird_versions.json" \
  | jq -r '.LATEST_THUNDERBIRD_VERSION // empty')
if [[ -z "$CANDIDATE_VERSION" ]]; then
  error "Failed to fetch version from Mozilla API"
fi
log "Candidate version (API): $CANDIDATE_VERSION"

# --- 2. Validate .deb exists for candidate; if not, fall back to latest published ---
validate_version() {
  local v="$1"
  local url="https://archive.mozilla.org/pub/thunderbird/releases/${v}/linux-x86_64/en-US/thunderbird-${v}.deb"
  if curl -fsSI "$url" | head -n1 | grep -q "200"; then
    echo "$v"
    return 0
  fi
  return 1
}

VERSION=""
if validate_version "$CANDIDATE_VERSION"; then
  VERSION="$CANDIDATE_VERSION"
  log "Using candidate version: $VERSION"
else
  log "Binary for $CANDIDATE_VERSION not yet available. Falling back to latest published..."
  VERSION=$(curl -fsS "https://archive.mozilla.org/pub/thunderbird/releases/" \
            | grep -oE 'href="[0-9]+\.[0-9]+(\.[0-9]+)?/"' \
            | sed 's|href="||; s|/"||' \
            | grep -v -i 'esr' \
            | sort -V \
            | tail -n1)
  if [[ -z "$VERSION" ]]; then
    error "No non-ESR versions found"
  fi
  log "Fallback version: $VERSION"
  validate_version "$VERSION" || error "Even fallback version $VERSION has no .deb"
fi

# --- 3. Get installed version ---
INSTALLED_VERSION=""
if dpkg -l thunderbird &>/dev/null; then
  INSTALLED_VERSION=$(dpkg-query -f '${Version}' -W thunderbird 2>/dev/null \
                        | sed 's/.*://' \
                        | cut -d'-' -f1 \
                        | sed 's/esr.*//')
  log "Installed version: $INSTALLED_VERSION"
else
  log "Thunderbird not installed"
fi

# --- 4. Compare versions and exit early if already up-to-date ---
if [[ -n "$INSTALLED_VERSION" && "$INSTALLED_VERSION" == "$VERSION" ]]; then
  log "Already up-to-date (installed: $INSTALLED_VERSION, latest: $VERSION)."
  exit 0
fi

# --- 5. Download & install ---
DEB_FILE="/tmp/thunderbird-${VERSION}.deb"
DEB_URL="https://archive.mozilla.org/pub/thunderbird/releases/${VERSION}/linux-x86_64/en-US/thunderbird-${VERSION}.deb"

log "Downloading $DEB_URL"
curl -fsSL "$DEB_URL" -o "$DEB_FILE"

log "Installing..."
sudo dpkg -i "$DEB_FILE" || sudo apt-get -f install -y

log "Thunderbird updated to $VERSION"
rm -f "$DEB_FILE"

# Optional: desktop notification
if command -v notify-send >/dev/null; then
  notify-send "Thunderbird Updated" "v$VERSION installed" --icon=mail-unread
fi

log "Done."
  1. Make it executable & test
chmod +x ~/.local/bin/update-thunderbird
mkdir -p ~/.local/log

Test dry-run (comment out dpkg/apt lines first if cautious)

~/.local/bin/update-thunderbird
  1. Automate with systemd timer (I prefer over cron as more reliable) Create ~/.config/systemd/user/thunderbird-update.timer
[Unit]
Description=Check for Thunderbird updates weekly

[Timer]
OnCalendar=weekly
Persistent=true
RandomizedDelaySec=3600

[Install]
WantedBy=timers.target

And ~/.config/systemd/user/thunderbird-update.service

[Unit]
Description=Update Thunderbird to latest release
After=network-online.target

[Service]
Type=oneshot
ExecStart=%h/.local/bin/update-thunderbird
Environment=HOME=%h

Then enable:

systemctl --user daemon-reload
systemctl --user enable --now thunderbird-update.timer

This Runs weekly, survives reboots and send logs to ~/.local/log/thunderbird-update.log.

Or as an alternative we can use this one-liner for quick manual check

Add to ~/.bashrc or ~/.bash_aliases:

alias tb-update='VERSION=$(curl -s https://product-details.mozilla.org/1.0/thunderbird_versions.json | jq -r .LATEST_THUNDERBIRD_VERSION) && echo "Latest: $VERSION" && wget -qO /tmp/tb.deb "https://download.mozilla.org/?product=thunderbird-$VERSION&os=linux64&lang=en-US" && sudo dpkg -i /tmp/tb.deb || sudo apt --fix-broken install -y && rm -f /tmp/tb.deb'

Then simply run

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