install-betterbird.sh
· 4.9 KiB · Bash
Eredeti
#!/bin/bash
# https://github.com/Betterbird/thunderbird-patches/blob/main/install-on-linux/install-betterbird.sh
# Betterbird installation script for Linux, adapted from
# https://github.com/risaer/betterbird-dirty-update/blob/main/updateBetterbird.sh
# Configuration
lang="en-US" # Language options: en-US, de, fr, es-ES, ja, it, nl, pt-BR, ru.
version="release" # Version options: previous, release, latest, future. Only 'release' is guaranteed to work.
tmpDir="$HOME/tmp/betterbird"
tmpFile="" # Will be filled by script.
tmpLocFile="$tmpDir/download.txt"
installDir="/opt"
desktopFile="/usr/share/applications/eu.betterbird.Betterbird.desktop" # Do not change this configuration without reading comment in registerMIME().
backupDir="/opt/betterbird_backup_$(date +%Y%m%d%H%M)"
logFile="/var/log/betterbird/update.log"
# Helper function for logging
echoLog() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$logFile"
}
mkdir -p "$(dirname "$logFile")" 2>/dev/null
if [ $? -ne 0 ]; then
echo "This script likely needs superuser access since it writes to /var and /opt."
echo "Can't create logfile directory $(dirname "$logFile"). Exiting."
exit 1
fi
touch "$logFile" 2>/dev/null
if [ $? -ne 0 ]; then
echo "This script likely needs superuser access since it writes to /var and /opt."
echo "Can't touch logfile at $logFile. Exiting."
exit 1
fi
echoLog "Script started."
# Functions for installation steps
checkIfBetterbirdIsRunning() {
if pgrep -f betterbird-bin > /dev/null; then
echoLog "Betterbird is running. Please close it first."
exit 1
fi
}
downloadUpdate() {
mkdir -p "$tmpDir"
wget -q -O "$tmpLocFile" "https://www.betterbird.eu/downloads/getloc.php?os=linux&lang=$lang&version=$version"
read -r fileToDownload < "$tmpLocFile"
fileToDownload=$(basename "$fileToDownload")
# extract major version (3 characters after "betterbird-")
major=${fileToDownload:11:3}
shaFile="https://www.betterbird.eu/downloads/sha256-${major}.txt" # Name of sha256 file
echoLog "Download found: $fileToDownload."
tmpFile="$tmpDir/$fileToDownload"
# Delete old downloads.
find "$tmpDir" -type f ! -name "$fileToDownload" -delete
if [ -f "$tmpFile" ]; then
echoLog "$tmpFile already present. Exiting."
exit 0;
fi
echoLog "Starting download..."
wget -q -O "$tmpFile" "https://www.betterbird.eu/downloads/get.php?os=linux&lang=$lang&version=$version"
echoLog "Downloaded archive."
}
checkHash() {
local hash=$(sha256sum "$tmpFile" | awk '{print $1}')
wget -q -O "$tmpDir/sha256.txt" "$shaFile"
local update=$(grep $hash $tmpDir/sha256.txt | awk '{print $2}')
if [ "$update" == "" ]; then
echoLog "Hash $hash not found in $shaFile."
exit 1
else
echoLog "Hash check OK, hash matched ${update:1}."
fi
rm "$tmpDir/sha256.txt"
}
backup() {
echoLog "Checking if existing Betterbird installation needs to be backed up..."
if [ -d "$installDir/betterbird" ]; then
echoLog "Creating backup of the current installation..."
cp -r "$installDir/betterbird" "$backupDir"
if [ $? -eq 0 ]; then
echoLog "Backup successfully created at $backupDir."
else
echoLog "Failed to create backup."
fi
else
echoLog "No existing Betterbird installation found to backup."
fi
}
extract() {
rm -rf "$installDir/betterbird"
tar xf "$tmpFile" -C "$installDir"
echoLog "Extracted to $installDir/betterbird."
}
createDesktopFile() {
wget -q -O "$desktopFile" "https://raw.githubusercontent.com/Betterbird/thunderbird-patches/main/metadata/eu.betterbird.Betterbird.desktop"
sed -i -e 's|Exec=betterbird %u|Exec='"$installDir"'/betterbird/betterbird %u|' "$desktopFile"
sed -i -e 's|Icon=eu.betterbird.Betterbird|Icon='"$installDir"'/betterbird/chrome/icons/default/default256.png|' "$desktopFile"
echoLog "Desktop file created."
}
registerMIME() {
# This function registers Betterbird as the default application for handling mailto: links.
# It uses xdg-mime to set and query the default MIME handler.
# Note: If you move the desktop file to a non-standard directory, you may need to update $XDG_DATA_DIRS.
# This environment variable tells the desktop environment where to find desktop files.
# Example: export XDG_DATA_DIRS="/desktop/file/directory:$XDG_DATA_DIRS"
# For more details, see: https://specifications.freedesktop.org/menu-spec/latest/ar01s02.html
xdg-mime default eu.betterbird.Betterbird.desktop x-scheme-handler/mailto
echoLog "MIME handler for x-scheme-handler/mailto registered."
# Query the current default application set for handling mailto: links.
local mimeHandler=$(xdg-mime query default x-scheme-handler/mailto)
echoLog "Current default MIME handler for mailto: $mimeHandler."
}
# Main execution
checkIfBetterbirdIsRunning
downloadUpdate
checkHash
backup
extract
createDesktopFile
registerMIME
echoLog "Install successful: Betterbird installed in $installDir/betterbird."
echoLog "Desktop file in $desktopFile."
| 1 | #!/bin/bash |
| 2 | # https://github.com/Betterbird/thunderbird-patches/blob/main/install-on-linux/install-betterbird.sh |
| 3 | |
| 4 | # Betterbird installation script for Linux, adapted from |
| 5 | # https://github.com/risaer/betterbird-dirty-update/blob/main/updateBetterbird.sh |
| 6 | |
| 7 | # Configuration |
| 8 | lang="en-US" # Language options: en-US, de, fr, es-ES, ja, it, nl, pt-BR, ru. |
| 9 | version="release" # Version options: previous, release, latest, future. Only 'release' is guaranteed to work. |
| 10 | tmpDir="$HOME/tmp/betterbird" |
| 11 | tmpFile="" # Will be filled by script. |
| 12 | tmpLocFile="$tmpDir/download.txt" |
| 13 | installDir="/opt" |
| 14 | desktopFile="/usr/share/applications/eu.betterbird.Betterbird.desktop" # Do not change this configuration without reading comment in registerMIME(). |
| 15 | backupDir="/opt/betterbird_backup_$(date +%Y%m%d%H%M)" |
| 16 | logFile="/var/log/betterbird/update.log" |
| 17 | |
| 18 | # Helper function for logging |
| 19 | echoLog() { |
| 20 | echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$logFile" |
| 21 | } |
| 22 | |
| 23 | mkdir -p "$(dirname "$logFile")" 2>/dev/null |
| 24 | if [ $? -ne 0 ]; then |
| 25 | echo "This script likely needs superuser access since it writes to /var and /opt." |
| 26 | echo "Can't create logfile directory $(dirname "$logFile"). Exiting." |
| 27 | exit 1 |
| 28 | fi |
| 29 | touch "$logFile" 2>/dev/null |
| 30 | if [ $? -ne 0 ]; then |
| 31 | echo "This script likely needs superuser access since it writes to /var and /opt." |
| 32 | echo "Can't touch logfile at $logFile. Exiting." |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | echoLog "Script started." |
| 37 | |
| 38 | # Functions for installation steps |
| 39 | checkIfBetterbirdIsRunning() { |
| 40 | if pgrep -f betterbird-bin > /dev/null; then |
| 41 | echoLog "Betterbird is running. Please close it first." |
| 42 | exit 1 |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | downloadUpdate() { |
| 47 | mkdir -p "$tmpDir" |
| 48 | wget -q -O "$tmpLocFile" "https://www.betterbird.eu/downloads/getloc.php?os=linux&lang=$lang&version=$version" |
| 49 | read -r fileToDownload < "$tmpLocFile" |
| 50 | fileToDownload=$(basename "$fileToDownload") |
| 51 | # extract major version (3 characters after "betterbird-") |
| 52 | major=${fileToDownload:11:3} |
| 53 | shaFile="https://www.betterbird.eu/downloads/sha256-${major}.txt" # Name of sha256 file |
| 54 | echoLog "Download found: $fileToDownload." |
| 55 | tmpFile="$tmpDir/$fileToDownload" |
| 56 | |
| 57 | # Delete old downloads. |
| 58 | find "$tmpDir" -type f ! -name "$fileToDownload" -delete |
| 59 | |
| 60 | if [ -f "$tmpFile" ]; then |
| 61 | echoLog "$tmpFile already present. Exiting." |
| 62 | exit 0; |
| 63 | fi |
| 64 | |
| 65 | echoLog "Starting download..." |
| 66 | wget -q -O "$tmpFile" "https://www.betterbird.eu/downloads/get.php?os=linux&lang=$lang&version=$version" |
| 67 | echoLog "Downloaded archive." |
| 68 | } |
| 69 | |
| 70 | checkHash() { |
| 71 | local hash=$(sha256sum "$tmpFile" | awk '{print $1}') |
| 72 | wget -q -O "$tmpDir/sha256.txt" "$shaFile" |
| 73 | local update=$(grep $hash $tmpDir/sha256.txt | awk '{print $2}') |
| 74 | if [ "$update" == "" ]; then |
| 75 | echoLog "Hash $hash not found in $shaFile." |
| 76 | exit 1 |
| 77 | else |
| 78 | echoLog "Hash check OK, hash matched ${update:1}." |
| 79 | fi |
| 80 | rm "$tmpDir/sha256.txt" |
| 81 | } |
| 82 | |
| 83 | backup() { |
| 84 | echoLog "Checking if existing Betterbird installation needs to be backed up..." |
| 85 | if [ -d "$installDir/betterbird" ]; then |
| 86 | echoLog "Creating backup of the current installation..." |
| 87 | cp -r "$installDir/betterbird" "$backupDir" |
| 88 | if [ $? -eq 0 ]; then |
| 89 | echoLog "Backup successfully created at $backupDir." |
| 90 | else |
| 91 | echoLog "Failed to create backup." |
| 92 | fi |
| 93 | else |
| 94 | echoLog "No existing Betterbird installation found to backup." |
| 95 | fi |
| 96 | } |
| 97 | |
| 98 | extract() { |
| 99 | rm -rf "$installDir/betterbird" |
| 100 | tar xf "$tmpFile" -C "$installDir" |
| 101 | echoLog "Extracted to $installDir/betterbird." |
| 102 | } |
| 103 | |
| 104 | createDesktopFile() { |
| 105 | wget -q -O "$desktopFile" "https://raw.githubusercontent.com/Betterbird/thunderbird-patches/main/metadata/eu.betterbird.Betterbird.desktop" |
| 106 | sed -i -e 's|Exec=betterbird %u|Exec='"$installDir"'/betterbird/betterbird %u|' "$desktopFile" |
| 107 | sed -i -e 's|Icon=eu.betterbird.Betterbird|Icon='"$installDir"'/betterbird/chrome/icons/default/default256.png|' "$desktopFile" |
| 108 | echoLog "Desktop file created." |
| 109 | } |
| 110 | |
| 111 | registerMIME() { |
| 112 | # This function registers Betterbird as the default application for handling mailto: links. |
| 113 | # It uses xdg-mime to set and query the default MIME handler. |
| 114 | # Note: If you move the desktop file to a non-standard directory, you may need to update $XDG_DATA_DIRS. |
| 115 | # This environment variable tells the desktop environment where to find desktop files. |
| 116 | # Example: export XDG_DATA_DIRS="/desktop/file/directory:$XDG_DATA_DIRS" |
| 117 | # For more details, see: https://specifications.freedesktop.org/menu-spec/latest/ar01s02.html |
| 118 | xdg-mime default eu.betterbird.Betterbird.desktop x-scheme-handler/mailto |
| 119 | echoLog "MIME handler for x-scheme-handler/mailto registered." |
| 120 | |
| 121 | # Query the current default application set for handling mailto: links. |
| 122 | local mimeHandler=$(xdg-mime query default x-scheme-handler/mailto) |
| 123 | echoLog "Current default MIME handler for mailto: $mimeHandler." |
| 124 | } |
| 125 | |
| 126 | # Main execution |
| 127 | checkIfBetterbirdIsRunning |
| 128 | downloadUpdate |
| 129 | checkHash |
| 130 | backup |
| 131 | extract |
| 132 | createDesktopFile |
| 133 | registerMIME |
| 134 | echoLog "Install successful: Betterbird installed in $installDir/betterbird." |
| 135 | echoLog "Desktop file in $desktopFile." |