#!/bin/sh # Indie Marketer Server: installer for Linux (x64 and arm64, glibc). # # curl -fsSL https://indiemarketer.app/install.sh | sh # curl -fsSL https://indiemarketer.app/install.sh | sh -s -- --systemd # also run it as a service # # Options: --dir DIR (default: /usr/local/bin as root, ~/.local/bin otherwise), --systemd. # Read before you run: this script only downloads one file, checks it and copies it into place. # Help: https://indiemarketer.app/download#linux, team@indiemarketer.app set -eu BASE="${IM_INSTALL_BASE:-https://dl.indiemarketer.app/}" MANIFEST="${IM_INSTALL_MANIFEST:-https://dl.indiemarketer.app/linux/latest.json}" NAME="indiemarketer-server" DIR="" SYSTEMD=0 say() { printf '%s\n' "$*"; } die() { printf 'indiemarketer install: %s\n' "$*" >&2; exit 1; } while [ $# -gt 0 ]; do case "$1" in --dir) [ $# -ge 2 ] || die "--dir needs a directory"; DIR="$2"; shift 2 ;; --systemd) SYSTEMD=1; shift ;; -h|--help) sed -n '2,10p' "$0" 2>/dev/null || true; exit 0 ;; *) die "unknown option $1" ;; esac done case "$(uname -s)" in Linux) ;; Darwin) die "this is the Linux server. On a Mac, use the app: https://indiemarketer.app/download" ;; *) die "Indie Marketer Server runs on Linux (x64 or arm64)." ;; esac case "$(uname -m)" in x86_64|amd64) ARCH=x64 ;; aarch64|arm64) ARCH=arm64 ;; *) die "no build for $(uname -m); releases exist for x86_64 and arm64." ;; esac if ldd --version 2>&1 | grep -qi musl; then die "this system uses musl (Alpine). Use a glibc distribution (Debian, Ubuntu, Fedora, ...) or a glibc-based container image." fi if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL --retry 2 -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } else die "needs curl or wget." fi if command -v sha256sum >/dev/null 2>&1; then sha256() { sha256sum "$1" | cut -d ' ' -f 1; } elif command -v shasum >/dev/null 2>&1; then sha256() { shasum -a 256 "$1" | cut -d ' ' -f 1; } else die "needs sha256sum (coreutils) to check the download." fi TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT INT TERM FILE="indiemarketer-linux-$ARCH" say "Downloading $FILE ..." fetch "$BASE$FILE" "$TMP/$FILE" || die "download failed: $BASE$FILE" fetch "$BASE$FILE.sha256" "$TMP/$FILE.sha256" || die "download failed: $BASE$FILE.sha256" WANT="$(cut -d ' ' -f 1 "$TMP/$FILE.sha256")" GOT="$(sha256 "$TMP/$FILE")" [ -n "$WANT" ] && [ "$WANT" = "$GOT" ] || die "checksum mismatch (expected $WANT, got $GOT). Nothing was installed; try again in a minute." say "Checksum OK ($GOT)." # The signed release manifest, when OpenSSL 3 can check ed25519 signatures. if command -v openssl >/dev/null 2>&1 && openssl version 2>/dev/null | grep -Eq '^OpenSSL ([3-9]|[1-9][0-9])\.'; then cat > "$TMP/release.pem" <<'PEM' -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAFPUYNzwVFLGpfUxeyc0FwB/N2VUGjCI/MFMHlCdpwZk= -----END PUBLIC KEY----- PEM fetch "$MANIFEST" "$TMP/latest.json" || die "download failed: $MANIFEST" fetch "$MANIFEST.sig" "$TMP/latest.json.sig" || die "download failed: $MANIFEST.sig" openssl pkeyutl -verify -pubin -inkey "$TMP/release.pem" -rawin -in "$TMP/latest.json" -sigfile "$TMP/latest.json.sig" >/dev/null 2>&1 \ || die "the release manifest's signature does not verify. Nothing was installed." grep -q "\"$GOT\"" "$TMP/latest.json" || die "the binary is not the one the signed manifest lists (a release may be going out; try again in a minute)." say "Signed release manifest OK." fi if [ -z "$DIR" ]; then if [ "$(id -u)" = 0 ]; then DIR=/usr/local/bin; else DIR="$HOME/.local/bin"; fi fi mkdir -p "$DIR" chmod 0755 "$TMP/$FILE" mv -f "$TMP/$FILE" "$DIR/.$NAME.new" mv -f "$DIR/.$NAME.new" "$DIR/$NAME" BIN="$DIR/$NAME" VERSION="$("$BIN" version)" || die "the installed binary does not run on this system." say "Installed $BIN ($VERSION)." case ":$PATH:" in *":$DIR:"*) ;; *) say "Note: $DIR is not on your PATH. Add it: export PATH=\"$DIR:\$PATH\"" ;; esac command -v ffprobe >/dev/null 2>&1 || say "Note: install ffmpeg (it provides ffprobe) to post images and videos, e.g. sudo apt install ffmpeg." if [ "$SYSTEMD" = 1 ]; then command -v systemctl >/dev/null 2>&1 || die "--systemd needs systemd." "$BIN" init >/dev/null if [ "$(id -u)" = 0 ]; then UNIT=/etc/systemd/system/indiemarketer-server.service SCOPE="" else UNIT="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/indiemarketer-server.service" SCOPE="--user" mkdir -p "$(dirname "$UNIT")" fi cat > "$UNIT" <" say " $((STEP + 3)). Approve posts yourself: $NAME approvals, then $NAME approve "