#!/bin/sh # SPDX-License-Identifier: Apache-2.0 # # Boom Box installer for Linux. Downloads the newest release from GitHub, # checks it against the release's SHA256SUMS, and installs it the way your # distro expects: a .deb (Debian, Ubuntu, Mint, Pop!_OS), an .rpm (Fedora, # openSUSE), or the AppImage with an app-menu entry (Arch and everything else). # # curl -fsSL https://raw.githubusercontent.com/aacronicer/boom-box/main/install.sh | sh # # Options (after `sh -s --`): # --headless the core only, as a background service (Raspberry Pi, media PC) # --appimage the AppImage even where a .deb/.rpm would fit # --version X a specific release, e.g. 0.10.2 (default: the newest, beta included) # --dry-run show what would happen; download and verify, but don't install # # Windows: irm https://raw.githubusercontent.com/aacronicer/boom-box/main/install.ps1 | iex # Everything is inside main(), called on the last line, so a half-downloaded # script never runs. set -eu REPO="aacronicer/boom-box" API="${BOOMBOX_API:-https://api.github.com/repos/$REPO/releases}" ICON_URL="https://raw.githubusercontent.com/$REPO/main/apps/web/public/icon-512.png" say() { printf '%s\n' "$*"; } step() { printf '\033[1m==> %s\033[0m\n' "$*"; } warn() { printf '\033[33mwarning:\033[0m %s\n' "$*" >&2; } die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2 exit 1 } has() { command -v "$1" >/dev/null 2>&1; } # Downloads a URL to a file (curl, else wget). Gives up on a connection that # can't be made in 20 s or stalls for 30 s, rather than hanging. fetch() { if has curl; then curl -fsSL --retry 3 --connect-timeout 20 --speed-limit 1 --speed-time 30 \ -H "User-Agent: boom-box-installer" -o "$2" "$1" elif has wget; then wget -q --tries=3 --timeout=30 --header="User-Agent: boom-box-installer" -O "$2" "$1" else die "this needs curl or wget" fi } # Runs a command as root: directly if we are root, else through sudo. as_root() { if [ "$(id -u)" -eq 0 ]; then "$@" elif has sudo; then sudo "$@" else die "installing needs root rights: run this as root or install sudo" fi } # Runs (or, with --dry-run, only shows) an install step. run() { if [ "$DRY_RUN" = 1 ]; then say " would run: $*" else "$@" fi } sha256() { if has sha256sum; then sha256sum "$1" | cut -d' ' -f1 elif has shasum; then shasum -a 256 "$1" | cut -d' ' -f1 else die "this needs sha256sum or shasum to check the download" fi } usage() { cat <"$WORK/urls" case "$MODE" in deb) FILE="boom-box_${VER}_${DEB_ARCH}.deb" ;; rpm) FILE="boom-box-${VER}-1.${RPM_ARCH}.rpm" ;; appimage) FILE="boom-box_${VER}_${APPIMAGE_ARCH}.AppImage" ;; headless) FILE="boomboxd-${VER}-linux-${TAR_ARCH}.tar.gz" ;; esac URL=$(grep "/$FILE\$" "$WORK/urls" | head -n 1 || true) [ -n "$URL" ] || die "release $TAG has no $FILE. See https://github.com/$REPO/releases/tag/$TAG" SUMS_URL=$(grep '/SHA256SUMS$' "$WORK/urls" | head -n 1 || true) step "Downloading $FILE" fetch "$URL" "$WORK/$FILE" if [ -n "$SUMS_URL" ]; then fetch "$SUMS_URL" "$WORK/SHA256SUMS" WANT=$(awk -v f="$FILE" '$2 == f || $2 == "*" f { print $1; exit }' "$WORK/SHA256SUMS") [ -n "$WANT" ] || die "SHA256SUMS of $TAG doesn't list $FILE" GOT=$(sha256 "$WORK/$FILE") [ "$WANT" = "$GOT" ] || die "the download is damaged or was tampered with (SHA-256 $GOT, expected $WANT)" say " checksum OK" else warn "release $TAG has no SHA256SUMS; the download could not be checked" fi step "Installing Boom Box $VER" case "$MODE" in deb) say " as a .deb package (needs your password)" run as_root apt-get install -y "$WORK/$FILE" ;; rpm) say " as an .rpm package (needs your password)" if has dnf; then run as_root dnf install -y "$WORK/$FILE" else # Release .rpm files aren't GPG-signed yet. run as_root zypper --non-interactive install --allow-unsigned-rpm "$WORK/$FILE" fi ;; appimage) install_appimage ;; headless) install_headless ;; esac step "Done" if [ "$DRY_RUN" = 1 ]; then say "Dry run: nothing was installed." return 0 fi case "$MODE" in deb | rpm | appimage) say "Open Boom Box from your app menu. It keeps running in the tray when you close the window." ;; headless) say "Boom Box runs in the background as your user (systemctl --user status boomboxd)." say "To pair a phone: systemctl --user stop boomboxd && $HEADLESS_DIR/boomboxd --pair" say " scan the code, press Ctrl+C, then: systemctl --user start boomboxd" ;; esac say "Phone remote and more: https://github.com/$REPO#readme" } # The AppImage in ~/.local/bin, with an app-menu entry and icon. install_appimage() { BIN_DIR="$HOME/.local/bin" APP="$BIN_DIR/boom-box.AppImage" DESKTOP="$HOME/.local/share/applications/io.github.aacronicer.boombox.desktop" ICON="$HOME/.local/share/icons/hicolor/512x512/apps/io.github.aacronicer.boombox.png" say " as an AppImage in $APP, no password needed" if ! { { ldconfig -p 2>/dev/null || /sbin/ldconfig -p 2>/dev/null; } | grep -q 'libfuse\.so\.2'; }; then warn "AppImages need FUSE 2 (libfuse2 / fuse2). If Boom Box doesn't start, install it with your package manager." fi run mkdir -p "$BIN_DIR" "$(dirname "$DESKTOP")" "$(dirname "$ICON")" run install -m 755 "$WORK/$FILE" "$APP" if [ "$DRY_RUN" = 0 ]; then fetch "$ICON_URL" "$ICON" || warn "could not fetch the icon; the menu entry will have a generic one" cat >"$DESKTOP" </dev/null || true fi else say " would add the app-menu entry $DESKTOP" fi } # The core only, unpacked to ~/.local/share/boomboxd, as a systemd user service. install_headless() { HEADLESS_DIR="$HOME/.local/share/boomboxd" UNIT_DIR="$HOME/.config/systemd/user" say " the core only, in $HEADLESS_DIR, as a user service; no password needed" # An upgrade: stop the running core and drop the old web UI first. if has systemctl && systemctl --user is-active --quiet boomboxd 2>/dev/null; then run systemctl --user stop boomboxd fi run rm -rf "$HEADLESS_DIR/web" run mkdir -p "$HEADLESS_DIR" "$UNIT_DIR" run tar -xzf "$WORK/$FILE" -C "$HEADLESS_DIR" --strip-components=1 run install -m 644 "$HEADLESS_DIR/boomboxd.service" "$UNIT_DIR/boomboxd.service" if has systemctl; then run systemctl --user daemon-reload run systemctl --user enable boomboxd run systemctl --user restart boomboxd # Keep it running without anyone logged in, if allowed. if has loginctl; then run loginctl enable-linger "$(id -un)" || warn "could not enable lingering; Boom Box will stop when you log out" fi else warn "systemd was not found: start $HEADLESS_DIR/boomboxd yourself" fi } main "$@"