#!/usr/bin/env bash # Install BoltSweep on Linux in one command: # # curl -fsSL https://boltsweep.com/install.sh | bash # # What it does: installs BoltSweep the way your system installs its other # apps where it can, so mail is shown by the system's own web engine # (WebKitGTK), which gets security fixes along with the rest of the system: # # Debian, Ubuntu, Mint… the .deb from boltsweep.com, with apt-get # Fedora the .rpm from boltsweep.com, with dnf # openSUSE the .rpm from boltsweep.com, with zypper # Arch, Manjaro, CachyOS… boltsweep-bin from the AUR, once it's there # anything else the Flatpak from Flathub, once it's there # (if Flatpak is installed) # # Package managers need administrator rights, so sudo asks for your password. # A package replaces an AppImage this script installed before, menu entry and # mailto: setting included. # # Otherwise, or with --appimage, it installs the AppImage for this user, no # root needed: ~/Applications/BoltSweep.AppImage and a menu entry. The # AppImage brings its own, older copy of WebKitGTK. # # Every download is checked against the release's SHA256SUMS before anything # is installed. Run it again to update or repair. --uninstall removes # BoltSweep however this script installed it (your mail and settings in # ~/.local/share/boltsweep stay). Options go after `bash -s --`: # # curl -fsSL https://boltsweep.com/install.sh | bash -s -- --appimage # # Windows and macOS: download from https://boltsweep.com/download set -euo pipefail main() { local site="https://boltsweep.com" local bin_dir="$HOME/Applications" local app="$bin_dir/BoltSweep.AppImage" local data="${XDG_DATA_HOME:-$HOME/.local/share}" # Named after the window's app id, which is how docks (COSMIC's, for one) # find the entry and its icon. Up to 0.5.0 it was boltsweep.desktop. local entry="$data/applications/boltsweep-desktop.desktop" local old_entry="$data/applications/boltsweep.desktop" local icons="$data/icons/hicolor" local icon="$icons/512x512/apps/boltsweep.png" # The packages' names. Tauri names the .deb and .rpm after the product # name, BoltSweep, as bolt-sweep; they bring /usr/bin/boltsweep-desktop # and BoltSweep.desktop. local pkg=bolt-sweep aur_pkg=boltsweep-bin flatpak_id=com.boltsweep.BoltSweep local mode=auto case "${1:-}" in "") ;; --appimage) mode=appimage ;; --uninstall) mode=uninstall ;; *) echo "Unknown option: $1 (there's --appimage and --uninstall)" >&2 exit 1 ;; esac if [ "$(uname -s)" != Linux ]; then echo "This installer is for Linux. Download BoltSweep for your computer at $site/download" >&2 exit 1 fi # Runs a command as root: directly when this already is root, else through # sudo, which asks for the password on the terminal (under `curl | bash` # too, as it doesn't read it from the script's input). as_root() { if [ "$EUID" -eq 0 ]; then "$@"; else sudo "$@"; fi } can_be_root() { [ "$EUID" -eq 0 ] || command -v sudo >/dev/null } refresh_menu() { if command -v update-desktop-database >/dev/null; then update-desktop-database "$data/applications" 2>/dev/null || true fi if command -v gtk-update-icon-cache >/dev/null; then gtk-update-icon-cache -q -t "$icons" 2>/dev/null || true fi } # The AppImage install: what this script adds, and the icons the app adds # when it puts itself in the menu. remove_appimage() { rm -f "$app" "$entry" "$old_entry" "$icons"/{32x32,128x128,256x256,512x512}/apps/boltsweep.png } if [ "$mode" = uninstall ]; then local failed=0 # Removes a system package with the command given, or says how to. remove_package() { echo "Removing the BoltSweep package…" if [ "$EUID" -ne 0 ]; then echo "That needs administrator rights, so enter your password if asked."; fi if can_be_root && as_root "$@"; then return 0; fi echo "Couldn't remove it. Remove it with: sudo $*" >&2 failed=1 } if [[ "$(dpkg -s "$pkg" 2>/dev/null || true)" == *"Status: install ok installed"* ]]; then if command -v apt-get >/dev/null; then remove_package apt-get remove -y "$pkg"; else remove_package dpkg -r "$pkg"; fi fi if command -v rpm >/dev/null && rpm -q "$pkg" >/dev/null 2>&1; then if command -v dnf >/dev/null; then remove_package dnf remove -y "$pkg" elif command -v zypper >/dev/null; then remove_package zypper --non-interactive remove "$pkg" else remove_package rpm -e "$pkg" fi fi if command -v pacman >/dev/null && pacman -Q "$aur_pkg" >/dev/null 2>&1; then remove_package pacman -R --noconfirm "$aur_pkg" fi if command -v flatpak >/dev/null; then local scope for scope in --user --system; do if flatpak info "$scope" "$flatpak_id" >/dev/null 2>&1; then echo "Removing the BoltSweep Flatpak…" if ! flatpak uninstall "$scope" -y --noninteractive "$flatpak_id"; then echo "Couldn't remove it. Remove it with: flatpak uninstall $scope $flatpak_id" >&2 failed=1 fi fi done fi remove_appimage refresh_menu # mailto: links shouldn't go to an app that's gone. Drops BoltSweep's # entries (whichever way it was installed) from the mailto: line of # mimeapps.list; other apps listed there, and the rest, stay as they are. local list="${XDG_CONFIG_HOME:-$HOME/.config}/mimeapps.list" if [ -f "$list" ]; then local before after before="$(cat "$list")" after="$(awk ' BEGIN { ours["boltsweep-desktop.desktop"]; ours["boltsweep.desktop"] ours["BoltSweep.desktop"]; ours["com.boltsweep.BoltSweep.desktop"] } /^[ \t]*x-scheme-handler\/mailto[ \t]*=/ { eq = index($0, "=") n = split(substr($0, eq + 1), apps, ";") kept = ""; dropped = 0 for (i = 1; i <= n; i++) { a = apps[i] gsub(/^[ \t]+|[ \t]+$/, "", a) if (a == "") continue if (a in ours) dropped = 1 else kept = kept a ";" } if (!dropped) print else if (kept != "") print substr($0, 1, eq) kept next } { print } ' "$list")" if [ "$after" != "$before" ]; then printf '%s\n' "$after" >"$list" echo "mailto: links no longer go to BoltSweep." fi fi if [ "$failed" = 0 ]; then echo "BoltSweep is uninstalled."; else echo "The rest of BoltSweep is uninstalled."; fi echo "Your mail and settings are still in $data/boltsweep." if [ -d "$HOME/.var/app/$flatpak_id" ]; then echo "The Flatpak's mail and settings are still in $HOME/.var/app/$flatpak_id." fi exit "$failed" fi if [ "$(uname -m)" != x86_64 ]; then echo "BoltSweep for Linux is x86_64 only for now (this is $(uname -m))." >&2 exit 1 fi for tool in curl sha256sum; do command -v "$tool" >/dev/null || { echo "Please install $tool first." >&2; exit 1; } done local how="" # how BoltSweep got installed: deb, rpm, aur, flatpak or appimage local file="" # the release file downloaded, such as BoltSweep_0.6.1_amd64.deb local fell_back=0 # set when a package couldn't be installed # Downloads the latest release's file for $1 (appimage, deb or rpm) to $2 # and checks it against the release's SHA256SUMS. Any problem stops the # script, with nothing installed. fetch() { local url sums want echo "Downloading the latest BoltSweep…" # /api/download/ redirects to /download//; that # address says which release it is, so its SHA256SUMS can be fetched beside it. if ! url="$(curl -fL --progress-bar -o "$2" -w '%{url_effective}' "$site/api/download/$1")"; then echo "The download didn't work. Check your internet connection and try again." >&2 exit 1 fi file="${url##*/}" case "$1:$file" in appimage:*.AppImage | deb:*.deb | rpm:*.rpm) ;; *) echo "The download isn't ready yet. Try again in a little while, or see $site/download" >&2 exit 1 esac # Without the checksums the download can't be checked, so nothing is installed. if ! sums="$(curl -fsSL "${url%/*}/SHA256SUMS")"; then echo "Couldn't get the checksums to check the download with. Nothing was installed; please try again." >&2 exit 1 fi want="$(printf '%s\n' "$sums" | awk -v f="$file" '$2 == f || $2 == "*" f { print $1 }')" # From stdin: given a path with a backslash in it, sha256sum puts one # before the checksum too. if [ -z "$want" ] || [ "$want" != "$(sha256sum <"$2" | cut -d' ' -f1)" ]; then echo "The download doesn't match its checksum. Nothing was installed; please try again." >&2 exit 1 fi echo "Checksum OK." } # The .deb or .rpm ($1) with apt-get, dnf or zypper ($2). try_package() { if ! can_be_root; then echo "Installing the .$1 package needs administrator rights, and sudo isn't installed." fell_back=1 return 0 fi echo "Installing BoltSweep with $2, your system's package manager." if [ "$EUID" -ne 0 ]; then echo "That needs administrator rights, so enter your password if asked."; fi if ! as_root true; then echo "Couldn't get administrator rights." fell_back=1 return 0 fi # In /tmp and readable by everyone, so apt can read it as its own _apt # user; otherwise it warns that it had to read it "unsandboxed" as root. local dir dir="$(mktemp -d /tmp/boltsweep.XXXXXX)" trap 'rm -rf "$dir"' EXIT chmod 755 "$dir" fetch "$1" "$dir/BoltSweep.$1" chmod 644 "$dir/BoltSweep.$1" case "$2" in apt-get) # Fresh package lists, so apt finds what BoltSweep needs (WebKitGTK). # One broken extra repository shouldn't stop the install, hence || true. echo "Refreshing the package lists…" as_root apt-get update -qq || true if as_root env DEBIAN_FRONTEND=noninteractive apt-get install -y "$dir/BoltSweep.deb"; then how=deb; fi ;; dnf) if as_root dnf install -y "$dir/BoltSweep.rpm"; then how=rpm; fi ;; zypper) # zypper refuses unsigned packages unless told; the .rpm isn't signed yet. if as_root zypper --non-interactive install --allow-unsigned-rpm "$dir/BoltSweep.rpm"; then how=rpm; fi ;; esac rm -rf "$dir" trap - EXIT if [ -z "$how" ]; then echo "Couldn't install the .$1 package (see above)." fell_back=1 fi } # boltsweep-bin from the AUR, if it's there. It's built from the .deb, which # makepkg checks against the checksum in the package's PKGBUILD. try_aur() { local info="" info="$(curl -fsS "https://aur.archlinux.org/rpc/v5/info?arg%5B%5D=$aur_pkg" 2>/dev/null)" || true [[ "$info" == *'"resultcount":1'* ]] || return 0 # Already the AUR's version: nothing to build. local have have="$(pacman -Q "$aur_pkg" 2>/dev/null || true)" if [ -n "$have" ] && [[ "$info" == *"\"Version\":\"${have#* }\""* ]]; then echo "$aur_pkg ${have#* } is installed, the latest on the AUR." how=aur return 0 fi # makepkg and AUR helpers refuse to run as root. if [ "$EUID" -eq 0 ]; then echo "AUR packages are built as a normal user. To install $aur_pkg from the AUR, run this again without sudo." fell_back=1 return 0 fi if ! command -v sudo >/dev/null; then echo "Installing $aur_pkg from the AUR needs sudo, which isn't installed." fell_back=1 return 0 fi local helper="" if command -v paru >/dev/null; then helper=paru; elif command -v yay >/dev/null; then helper=yay; fi if [ -z "$helper" ] && { ! command -v git >/dev/null || ! command -v fakeroot >/dev/null; }; then echo "To install $aur_pkg from the AUR, first install git and base-devel:" echo " sudo pacman -S --needed git base-devel" echo "then run this again." fell_back=1 return 0 fi echo "Installing $aur_pkg from the AUR." echo "That needs administrator rights, so enter your password if asked." case "$helper" in paru) if paru -S --needed --noconfirm --skipreview "$aur_pkg"; then how=aur; fi ;; yay) if yay -S --needed --noconfirm "$aur_pkg"; then how=aur; fi ;; *) local dir dir="$(mktemp -d)" trap 'rm -rf "$dir"' EXIT if git clone -q "https://aur.archlinux.org/$aur_pkg.git" "$dir/$aur_pkg" && (cd "$dir/$aur_pkg" && makepkg -si --needed --noconfirm); then how=aur fi rm -rf "$dir" trap - EXIT ;; esac if [ -z "$how" ]; then echo "Couldn't install $aur_pkg from the AUR (see above)." fell_back=1 fi } # The Flatpak from Flathub, if Flatpak is installed and Flathub has it. # Flatpak checks what it downloads against Flathub's signature itself. try_flatpak() { command -v flatpak >/dev/null || return 0 # Flathub's API answers 404 for apps it doesn't have. curl -fsS -o /dev/null "https://flathub.org/api/v2/appstream/$flatpak_id" 2>/dev/null || return 0 echo "Installing BoltSweep from Flathub…" if flatpak info "$flatpak_id" >/dev/null 2>&1; then if flatpak update -y --noninteractive "$flatpak_id"; then how=flatpak; fi elif flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo && flatpak install --user -y --noninteractive flathub "$flatpak_id"; then how=flatpak fi if [ -z "$how" ]; then echo "Couldn't install BoltSweep from Flathub (see above)." fell_back=1 fi } # Which app opens mailto: links now. Asked before anything changes, as # some desktops only name apps whose menu entry still exists. local mailto="" if command -v xdg-mime >/dev/null; then mailto="$(xdg-mime query default x-scheme-handler/mailto 2>/dev/null || true)" fi # Sends mailto: links to the menu entry $1 instead, and notes where they # go now. (xdg-mime writes ~/.config/mimeapps.list but won't make ~/.config.) move_mailto() { mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}" xdg-mime default "$1" x-scheme-handler/mailto 2>/dev/null || true mailto="$(xdg-mime query default x-scheme-handler/mailto 2>/dev/null || true)" } if [ "$mode" = auto ]; then # Image-based systems (Fedora Silverblue, Bazzite…) don't take packages # this way; Flatpak is their way. if [ ! -e /run/ostree-booted ]; then if command -v apt-get >/dev/null; then try_package deb apt-get elif command -v dnf >/dev/null; then try_package rpm dnf elif command -v zypper >/dev/null; then try_package rpm zypper elif command -v pacman >/dev/null; then try_aur fi fi if [ -z "$how" ]; then try_flatpak; fi fi if [ -n "$how" ]; then local own_entry=BoltSweep.desktop run=boltsweep-desktop what="$file" if [ "$how" = aur ]; then what="$aur_pkg from the AUR"; fi if [ "$how" = flatpak ]; then own_entry="$flatpak_id.desktop" run="flatpak run $flatpak_id" what="BoltSweep from Flathub"; fi # One BoltSweep in the menu: the package's replaces the AppImage's. if [ -e "$app" ] || [ -e "$entry" ] || [ -e "$old_entry" ]; then remove_appimage refresh_menu echo "Removed the AppImage installed earlier ($app). Your mail and settings stay." fi if [ "$mailto" = boltsweep-desktop.desktop ] || [ "$mailto" = boltsweep.desktop ]; then move_mailto "$own_entry" fi echo echo "Installed $what." echo "Open it from your application menu (\"BoltSweep\") or run: $run" if [ "$mailto" = "$own_entry" ]; then echo "mailto: links open in BoltSweep." else echo "To open mailto: links with it: xdg-mime default $own_entry x-scheme-handler/mailto" fi return 0 fi if [ "$fell_back" = 1 ]; then echo echo "Installing the AppImage instead. To go straight to it next time:" echo " curl -fsSL $site/install.sh | bash -s -- --appimage" echo fi mkdir -p "$bin_dir" "$(dirname "$entry")" "$(dirname "$icon")" local tmp tmp="$(mktemp "$bin_dir/.BoltSweep.XXXXXX")" trap 'rm -f "$tmp"' EXIT fetch appimage "$tmp" chmod +x "$tmp" mv -f "$tmp" "$app" trap - EXIT curl -fsSL -o "$icon" "$site/logo.png" || true rm -f "$old_entry" # Exec= as the Desktop Entry spec wants it. A path with spaces or other # special characters goes in double quotes, with " ` $ \ backslash-escaped; # since Exec is a string value, where \\ stands for \, those backslashes # are doubled once more (so a $ is written \\$). A % is written %%. local cmd cmd="$(printf '%s' "$app" | sed -e 's/%/%%/g')" case "$app" in *[![:alnum:]/._+,:@=-]*) cmd="\"$(printf '%s' "$cmd" | sed -e 's/[\\"`$]/\\&/g' -e 's/\\/\\\\/g')\"" esac cat >"$entry" </dev/null && libs="$(ldconfig -p 2>/dev/null || true)" if [[ "$libs" != *libfuse.so.2* ]] && ! ls /usr/lib/libfuse.so.2 /usr/lib64/libfuse.so.2 /usr/lib/x86_64-linux-gnu/libfuse.so.2 >/dev/null 2>&1; then echo echo "BoltSweep needs FUSE 2 to start. Install it with:" if command -v pacman >/dev/null; then echo " sudo pacman -S --needed fuse2" elif command -v apt-get >/dev/null; then echo " sudo apt install libfuse2t64 (Ubuntu 22.04 / Debian 12 and older: libfuse2)" elif command -v dnf >/dev/null; then echo " sudo dnf install fuse-libs" elif command -v zypper >/dev/null; then echo " sudo zypper install libfuse2" else echo " your distribution's libfuse2 / fuse2 package" fi fi if [ "$mailto" = boltsweep-desktop.desktop ]; then echo "mailto: links open in BoltSweep." else echo "To open mailto: links with it: xdg-mime default boltsweep-desktop.desktop x-scheme-handler/mailto" fi } # Everything is inside main, so a download cut short runs nothing. main "$@"