Utoljára aktív 1 week ago

Betterbird installation script for Linux

Revízió bf12552168daaa360e290087d9c5a83747110c8c

install-betterbird.sh Eredeti
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
8lang="en-US" # Language options: en-US, de, fr, es-ES, ja, it, nl, pt-BR, ru.
9version="release" # Version options: previous, release, latest, future. Only 'release' is guaranteed to work.
10tmpDir="$HOME/tmp/betterbird"
11tmpFile="" # Will be filled by script.
12tmpLocFile="$tmpDir/download.txt"
13installDir="/opt"
14desktopFile="/usr/share/applications/eu.betterbird.Betterbird.desktop" # Do not change this configuration without reading comment in registerMIME().
15backupDir="/opt/betterbird_backup_$(date +%Y%m%d%H%M)"
16logFile="/var/log/betterbird/update.log"
17
18# Helper function for logging
19echoLog() {
20 echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$logFile"
21}
22
23mkdir -p "$(dirname "$logFile")" 2>/dev/null
24if [ $? -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
28fi
29touch "$logFile" 2>/dev/null
30if [ $? -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
34fi
35
36echoLog "Script started."
37
38# Functions for installation steps
39checkIfBetterbirdIsRunning() {
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
46downloadUpdate() {
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
70checkHash() {
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
83backup() {
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
98extract() {
99 rm -rf "$installDir/betterbird"
100 tar xf "$tmpFile" -C "$installDir"
101 echoLog "Extracted to $installDir/betterbird."
102}
103
104createDesktopFile() {
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
111registerMIME() {
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
127checkIfBetterbirdIsRunning
128downloadUpdate
129checkHash
130backup
131extract
132createDesktopFile
133registerMIME
134echoLog "Install successful: Betterbird installed in $installDir/betterbird."
135echoLog "Desktop file in $desktopFile."