#!/bin/sh # A Better Antivirus installer for Linux. # # curl -fsSL https://update.abetterantivirus.com/install.sh | sh # # Downloads the latest release for this machine from ABA's update site # (update.abetterantivirus.com), the way the automatic updates do: the site's # release manifest and the release's SHA256SUMS-linux.txt must each carry a # valid signature from one of ABA's release keys (the same keys the automatic # updates check, their public halves written out below). Then it checks the # download against that list, and runs `sudo aba install`. # Afterwards `aba` works in this terminal. # # Pass other arguments with ABA_ARGS, e.g. for a throwaway test machine: # curl -fsSL …/install.sh | ABA_ARGS='install --yes --preset strict --learning 0' sh # NetShield's block lists for an unattended install (with --yes in ABA_ARGS): # ABA_NETSHIELD=malware,ads (or default, all, off) # # For testing a local copy of a release's files (only from this machine, # never from the internet): ABA_RELEASE_URL=http://127.0.0.1:PORT (or # file:///dir) holding them, ABA_TAG naming the release and ABA_RELEASE_KEY a # PEM file with the public key it was signed with. (No manifest then: the # release is the one named.) set -eu SITE=https://update.abetterantivirus.com # ABA's release keys (PEM): internal/update's PublicKey, then NextKeys. RELEASE_KEYS='-----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAVLEZ7MWwcu4LFSYPzA71J9M0WWbqQryOGki0GSvuihU= -----END PUBLIC KEY----- -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEASC7IC0R0KPMKpJ3WN8sxEIO1RnQYPUrJAtif/8SvdTE= -----END PUBLIC KEY----- -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAul/gh0qnU2YnidyWEM1Z9uVRjeFMdLs5AUgfKAefmg0= -----END PUBLIC KEY-----' if [ -t 1 ]; then G=$(printf '\033[32m'); R=$(printf '\033[31m'); D=$(printf '\033[2m'); N=$(printf '\033[0m'); else G=; R=; D=; N=; fi say() { printf ' %s✓%s %s %s%s%s\n' "$G" "$N" "$1" "$D" "${2:-}" "$N"; } stop() { printf '\n %s✗ %s%s\n' "$R" "$1" "$N" [ -n "${2:-}" ] && printf ' %s%s%s\n' "$D" "$2" "$N" printf '\n' exit 1 } printf "\n A Better Antivirus %sit's not an antivirus. it's a better one.%s\n\n" "$D" "$N" [ "$(uname -s)" = Linux ] || stop "This installer is for Linux." "On Windows and macOS, get ABA from https://abetterantivirus.com" case "$(uname -m)" in x86_64|amd64) ARCH=amd64 ;; aarch64|arm64) ARCH=arm64 ;; *) stop "There's no build of A Better Antivirus for $(uname -m) yet." ;; esac [ -d /run/systemd/system ] || stop "A Better Antivirus needs a system run by systemd, for now." fetch() { # fetch URL FILE case "$1" in file://*) cp "${1#file://}" "$2" ;; *) if command -v curl >/dev/null 2>&1; then curl -fsS --proto '=https,http' --max-time 300 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q --max-redirect=0 -T 300 -O "$2" "$1" else stop "Neither curl nor wget is installed." "Install one of them and run the command again." fi ;; esac } # A local copy of a release, for tests: only from this machine. BASE="" if [ -n "${ABA_RELEASE_URL:-}" ]; then case "$ABA_RELEASE_URL" in http://127.0.0.1:*|http://localhost:*|file:///*) ;; *) stop "ABA_RELEASE_URL may only point at this machine." ;; esac [ -n "${ABA_TAG:-}" ] || stop "ABA_RELEASE_URL needs ABA_TAG." if [ -n "${ABA_RELEASE_KEY:-}" ]; then RELEASE_KEYS=$(cat "$ABA_RELEASE_KEY"); fi TAG=$ABA_TAG; BASE=${ABA_RELEASE_URL%/} fi DIR=$(mktemp -d "${TMPDIR:-/tmp}/aba-install.XXXXXX") trap 'rm -rf "$DIR"' EXIT INT TERM command -v openssl >/dev/null 2>&1 || stop "openssl is needed to check the release's signature." "Install it (it's the openssl package) and run the command again." # One PEM file per release key. printf '%s\n' "$RELEASE_KEYS" | awk -v d="$DIR" '/BEGIN PUBLIC KEY/ { n++ } n { print > (d "/key" n ".pem") }' ls "$DIR"/key*.pem >/dev/null 2>&1 || stop "This installer carries no release key." # signed FILE SIGFILE: FILE carries a valid signature (base64) by one of the # release keys; KEY is set to that key's PEM file. KEY="" signed() { base64 -d "$2" > "$DIR/sig.bin" 2>/dev/null || return 1 for k in "$DIR"/key*.pem; do if openssl pkeyutl -verify -pubin -inkey "$k" -rawin -in "$1" -sigfile "$DIR/sig.bin" >/dev/null 2>&1; then KEY=$k; return 0; fi done if ! openssl pkeyutl -help 2>&1 | grep -q rawin; then stop "This openssl is too old to check the release's signature (it needs OpenSSL 3)." "Install a newer openssl, or install ABA's .deb or .rpm package from https://abetterantivirus.com instead." fi return 1 } sha256() { sha256sum "$1" | cut -d' ' -f1; } SUMS=SHA256SUMS-linux.txt LISTSUM="" if [ -z "$BASE" ]; then # Which release is the latest: the site's stable manifest, signed with a # release key (the site itself isn't trusted). fetch "$SITE/stable/latest.json" "$DIR/latest.json" 2>/dev/null \ || stop "Couldn't reach ${SITE#https://} to find the latest release." "Check your internet connection and run the command again." [ "$(wc -c < "$DIR/latest.json")" -le 65536 ] || stop "The update site's release manifest is too large; not going on." # {"manifest": "", "signature": ""}, one field per line. sed -n 's/^[[:space:]]*"manifest":[[:space:]]*"\([A-Za-z0-9+/=]*\)".*/\1/p' "$DIR/latest.json" | head -n 1 | base64 -d > "$DIR/manifest.json" 2>/dev/null || true sed -n 's/^[[:space:]]*"signature":[[:space:]]*"\([A-Za-z0-9+/=]*\)".*/\1/p' "$DIR/latest.json" | head -n 1 > "$DIR/manifest.sig" [ -s "$DIR/manifest.json" ] && signed "$DIR/manifest.json" "$DIR/manifest.sig" \ || stop "The update site's release manifest isn't signed with ABA's key, so nothing was downloaded." "Run the command again. If it keeps happening, please let us know." # Signed, so written by ABA's release tool: one field per line. field() { sed -n 's/^ "'"$1"'": \(.*\),\{0,1\}$/\1/p' "$DIR/manifest.json" | sed 's/,$//' | head -n 1; } [ "$(field kind)" = '"aba-update-manifest"' ] && [ "$(field schema)" = 1 ] && [ "$(field channel)" = '"stable"' ] \ || stop "The update site's release manifest isn't one this installer understands, so nothing was downloaded." "Get the newest installer and run it again." TAG=$(field version | tr -d '"') LISTSUM=$(sed -n 's/^ "'"$SUMS"'": "\([0-9a-fA-F]\{64\}\)",\{0,1\}$/\1/p' "$DIR/manifest.json" | head -n 1 | tr 'A-F' 'a-f') BASE="$SITE/releases/$TAG" fi case "$TAG" in *[!A-Za-z0-9._-]*|"") stop "The release has an odd name ($TAG); not going on." ;; esac if [ -z "${ABA_RELEASE_URL:-}" ]; then VN='\(0\|[1-9][0-9]\{0,5\}\)' printf '%s\n' "$TAG" | grep -qx "v$VN\.$VN\.$VN" || stop "The release has an odd name ($TAG); not going on." [ -n "$LISTSUM" ] || stop "Release $TAG has no build for Linux yet." "Try again later." say "Latest release: $TAG" "signed manifest from ${SITE#https://}" fi NAME="aba_${TAG}_linux_${ARCH}" fetch "$BASE/$SUMS" "$DIR/$SUMS" && fetch "$BASE/$SUMS.sig" "$DIR/$SUMS.sig" \ || stop "The download didn't finish." "Check your internet connection and run the command again." # The checksum list must be signed with ABA's release key too, and be the # very list the signed manifest names. signed "$DIR/$SUMS" "$DIR/$SUMS.sig" && { [ -z "$LISTSUM" ] || [ "$(sha256 "$DIR/$SUMS")" = "$LISTSUM" ]; } \ || stop "The release's checksum list isn't signed with ABA's key, so nothing was run." "Run the command again. If it keeps happening, please let us know." say "Signed with ABA's release key" "ed25519" RELEASE_KEY=$(cat "$KEY") fetch "$BASE/$NAME" "$DIR/aba" \ || stop "Release $TAG has no build for this machine ($ARCH), or the download didn't finish." "Check your internet connection and run the command again." say "Downloaded $TAG" "$(du -k "$DIR/aba" | cut -f1) KB, $ARCH" WANT=$(awk -v n="$NAME" '{ f = $2; sub(/^\*/, "", f) } f == n && length($1) == 64 { print tolower($1); exit }' "$DIR/$SUMS") GOT=$(sha256 "$DIR/aba") [ -n "$WANT" ] && [ "$WANT" = "$GOT" ] || stop "The download doesn't match the release's signed checksum, so it was not run." "Run the command again. If it keeps happening, please let us know." say "Checksum matches the signed list" "SHA-256" chmod 755 "$DIR/aba" SUDO="" if [ "$(id -u)" != 0 ]; then command -v sudo >/dev/null 2>&1 || stop "Setting ABA up needs root, and sudo isn't here." "Run this as root instead." SUDO=sudo fi if [ -z "${ABA_ARGS:-}" ]; then printf ' %s›%s Starting setup %ssudo asks for your password%s\n' "$G" "$N" "$D" "$N" fi # Piped into sh, this script's input is the script: setup asks its questions # on the terminal instead, when there is one. IN=/dev/null if (exec /dev/null; then IN=/dev/tty; fi SHIELD="" if [ -n "${ABA_NETSHIELD:-}" ]; then case "$ABA_NETSHIELD" in *[!a-z,]*) stop "ABA_NETSHIELD must be lists separated by commas, like malware,ads (or default, all, off)." "" ;; esac SHIELD="--netshield=$ABA_NETSHIELD" fi # Everything above ran as you, in a folder that is yours: any program running # as you could swap the files there between those checks and sudo. So, as # root: copy them into a folder only root can change, check the signature and # the checksum again on those copies, and run that copy. # shellcheck disable=SC2016 # expanded by the root shell, not here AS_ROOT='set -eu key=$1 name=$2 sums=$3 src=$4; shift 4 R="" trap '"'"'[ -z "$R" ] || rm -rf "$R"'"'"' EXIT INT TERM refuse() { echo "$1: nothing was run." >&2; exit "$2"; } # A new folder only root can change, where programs may run (some systems # mount /var/tmp or /tmp noexec): /usr/local/lib first, where ABA goes anyway. for d in /usr/local/lib /var/lib /root /var/tmp; do [ -d "$d" ] || continue R=$(mktemp -d "$d/aba-install.XXXXXX" 2>/dev/null) || { R=""; continue; } # (-P: a link left in your folder is copied as a link, and refused below.) cp -P "$src/aba" "$R/aba" && cp -P "$src/$sums" "$R/sums" && cp -P "$src/$sums.sig" "$R/sums.sig" || refuse "Couldn'"'"'t copy the download" 90 for f in aba sums sums.sig; do if [ -L "$R/$f" ] || [ ! -f "$R/$f" ]; then refuse "The download isn'"'"'t plain files any more (a link was put in its place)" 90; fi done printf "%s\n" "$key" > "$R/key.pem" base64 -d "$R/sums.sig" > "$R/sig.bin" 2>/dev/null || refuse "The release signature changed after it was checked" 90 openssl pkeyutl -verify -pubin -inkey "$R/key.pem" -rawin -in "$R/sums" -sigfile "$R/sig.bin" >/dev/null 2>&1 \ || refuse "The checksum list changed after it was checked" 90 want=$(awk -v n="$name" '"'"'{ f = $2; sub(/^\*/, "", f) } f == n && length($1) == 64 { print tolower($1); exit }'"'"' "$R/sums") got=$(sha256sum "$R/aba" | cut -d" " -f1) [ -n "$want" ] && [ "$want" = "$got" ] || refuse "aba changed after it was checked (another program swapped it)" 91 chmod 700 "$R/aba" # Checked: now see that it can start here (exit 126 where programs may not). if "$R/aba" --version >/dev/null 2>&1; then break; fi rm -rf "$R"; R="" done [ -n "$R" ] || refuse "No folder here lets ABA run as root" 92 "$R/aba" "$@"' set +e # shellcheck disable=SC2086 # ABA_ARGS is a list of words on purpose $SUDO sh -c "$AS_ROOT" sh "$RELEASE_KEY" "$NAME" "$SUMS" "$DIR" ${ABA_ARGS:-install} $SHIELD <"$IN" CODE=$? set -e printf '\n' if [ "$CODE" = 0 ] && [ -x /usr/local/lib/file-access-monitor/aba ]; then say "A Better Antivirus is installed." printf ' %sType%s aba%s for the dashboard, or%s aba test%s to watch it catch a fake stealer.%s\n\n' "$D" "$G" "$D" "$G" "$D" "$N" elif [ "$CODE" != 0 ]; then printf ' %s✗ Setup didn'"'"'t finish (exit code %s).%s %sRun the command again to retry.%s\n\n' "$R" "$CODE" "$N" "$D" "$N" exit "$CODE" fi