#!/bin/bash
set -eu

# The published digest is pinned so the selected upstream bytes do not drift.
archive=/usr/local/src/listmonk_6.2.0_linux_amd64.tar.gz
url=https://github.com/knadh/listmonk/releases/download/v6.2.0/listmonk_6.2.0_linux_amd64.tar.gz
proxy=()
if [[ -n "${FAB_HTTP_PROXY:-}" ]]; then
    proxy=(--proxy "$FAB_HTTP_PROXY")
fi
curl -fLsS "${proxy[@]}" -o "$archive" "$url"
printf '%s  %s\n' ce78c89d8aac0df3ffe0e110b008e7bb5dae13e6ad0c57b43aa7094971e8698e "$archive" | sha256sum -c -
tar -xzf "$archive" -C /usr/local/src listmonk LICENSE
install -o root -g root -m 0755 /usr/local/src/listmonk /usr/local/bin/listmonk
install -d -o root -g root -m 0755 /usr/share/doc/listmonk
install -o root -g root -m 0644 /usr/local/src/LICENSE /usr/share/doc/listmonk/copyright
rm -f "$archive" /usr/local/src/listmonk /usr/local/src/LICENSE
