57 lines
1.9 KiB
Bash
57 lines
1.9 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
PROJECT_NAME="FAQd"
|
|
PROJECT_RELEASES_URL="https://forge.cadoles.com/Cadoles/emissary/releases"
|
|
PROJECT_DESTDIR="."
|
|
PROJECT_FILE_BASENAME="faqd"
|
|
PROJECT_PLATFORM_SUFFIX="$(uname -s)_$(uname -m)"
|
|
|
|
function main {
|
|
test -z "${PROJECT_VERSION}" && PROJECT_VERSION="$(curl -sfL -o /dev/null -w %{url_effective} "${PROJECT_RELEASES_URL}/latest" |
|
|
rev |
|
|
cut -f1 -d'/'|
|
|
rev)"
|
|
|
|
# Check version variable initialization
|
|
test -z "${PROJECT_VERSION}" && {
|
|
echo "Unable to get ${PROJECT_NAME} version !" >&2
|
|
exit 1
|
|
}
|
|
|
|
test -z "${PROJECT_TMPDIR}" && PROJECT_TMPDIR="$(mktemp -d)"
|
|
export TAR_FILE="${PROJECT_TMPDIR}/${PROJECT_FILE_BASENAME}_${PROJECT_VERSION}_${PROJECT_PLATFORM_SUFFIX}.tar.gz"
|
|
|
|
(
|
|
cd "${PROJECT_TMPDIR}"
|
|
|
|
# Download project
|
|
echo "Downloading ${PROJECT_NAME} ${PROJECT_VERSION}..."
|
|
curl -sfLo "${TAR_FILE}" \
|
|
"${PROJECT_RELEASES_URL}/download/${PROJECT_VERSION}/${PROJECT_FILE_BASENAME}_${PROJECT_VERSION}_${PROJECT_PLATFORM_SUFFIX}.tar.gz" ||
|
|
( echo "Error while downloading ${PROJECT_NAME} !" >&2 && exit 1 )
|
|
|
|
# Download checksums
|
|
curl -sfLo "checksums.txt" "${PROJECT_RELEASES_URL}/download/${PROJECT_VERSION}/checksums.txt"
|
|
|
|
echo "Verifying checksum..."
|
|
check_sum ||
|
|
( echo "Error while verifying checksums !" >&2 && exit 1 )
|
|
)
|
|
|
|
# Extracting archive files
|
|
tar -xf "${TAR_FILE}" -C "${PROJECT_TMPDIR}"
|
|
|
|
# Moving downloaded binary to destination directory
|
|
mv -f "${PROJECT_TMPDIR}/${PROJECT_FILE_BASENAME}" "${PROJECT_DESTDIR}/"
|
|
|
|
echo "You can now use '${PROJECT_DESTDIR}/${PROJECT_FILE_BASENAME}', enjoy !"
|
|
}
|
|
|
|
function check_sum {
|
|
set -o pipefail
|
|
cat checksums.txt | grep ${PROJECT_FILE_BASENAME}_*_${PROJECT_PLATFORM_SUFFIX}.tar.gz | sha256sum -c
|
|
set +o pipefail
|
|
}
|
|
|
|
main $@ |