#!/usr/bin/env bash

auth_version=$1
if [[ -z "$auth_version" ]]; then
    echo "You must supply a version number."
    exit 1
fi

# The single quotes around EOF is to stop attempted variable and backtick expansion.
read -r -d '' release_description << 'EOF'
SAFE Network client side Rust module(s)

### SAFE Authenticator FFI
FFI is used to generate the native libraries which can be used by other high level languages to consume the Rust API. The development version uses a mocked SAFE network, which allows you to work against a file that mimics the network, where SafeMoney are created for local use.

| OS | Download link | SHA-256 checksum |
| --- | --- | --- |
| Linux | [Download](S3_SAFE_AUTH_FFI_LINUX_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_LINUX_CHECKSUM |
| macOS | [Download](S3_SAFE_AUTH_FFI_MACOS_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_MACOS_CHECKSUM |
| Windows | [Download](S3_SAFE_AUTH_FFI_WIN_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_WINDOWS_CHECKSUM |
| iOS | [Download](S3_SAFE_AUTH_FFI_IOS_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_IOS_CHECKSUM |
| Android ARMv7 | [Download](S3_SAFE_AUTH_FFI_ANDROID_ARMV7_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_ANDROID_ARMV7_CHECKSUM |
| Android x86_64 | [Download](S3_SAFE_AUTH_FFI_ANDROID_X86_64_DEPLOY_URL) | TAR_SAFE_AUTH_FFI_ANDROID_X86_64_CHECKSUM |

EOF

s3_safe_auth_ffi_linux_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-x86_64-unknown-linux-gnu.tar.gz"
s3_safe_auth_ffi_win_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-x86_64-pc-windows-gnu.tar.gz"
s3_safe_auth_ffi_macos_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-x86_64-apple-darwin.tar.gz"
s3_safe_auth_ffi_ios_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-apple-ios.tar.gz"
s3_safe_auth_ffi_android_armv7_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-armv7-linux-androideabi.tar.gz"
s3_safe_auth_ffi_android_x86_64_deploy_url="https:\/\/sn-client.s3.amazonaws.com\/safe_authenticator_ffi-dev-$auth_version-x86_64-linux-android.tar.gz"

tar_safe_auth_ffi_linux_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-x86_64-unknown-linux-gnu.tar.gz" | \
    awk '{ print $1 }')
tar_safe_auth_ffi_macos_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-x86_64-apple-darwin.tar.gz" | \
    awk '{ print $1 }')
tar_safe_auth_ffi_win_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-x86_64-pc-windows-gnu.tar.gz" | \
    awk '{ print $1 }')
tar_safe_auth_ffi_ios_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-apple-ios.tar.gz" | \
    awk '{ print $1 }')
tar_safe_auth_ffi_android_armv7_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-armv7-linux-androideabi.tar.gz" | \
    awk '{ print $1 }')
tar_safe_auth_ffi_android_x86_64_checksum=$(sha256sum \
    "./deploy/prod/safe_authenticator_ffi-$auth_version-x86_64-pc-windows-gnu.tar.gz" | \
    awk '{ print $1 }')

release_description=$(sed "s/S3_SAFE_AUTH_FFI_LINUX_DEPLOY_URL/$s3_safe_auth_ffi_linux_deploy_url/g" <<< "$release_description")
release_description=$(sed "s/S3_SAFE_AUTH_FFI_MACOS_DEPLOY_URL/$s3_safe_auth_ffi_macos_deploy_url/g" <<< "$release_description")
release_description=$(sed "s/S3_SAFE_AUTH_FFI_WIN_DEPLOY_URL/$s3_safe_auth_ffi_win_deploy_url/g" <<< "$release_description")
release_description=$(sed "s/S3_SAFE_AUTH_FFI_IOS_DEPLOY_URL/$s3_safe_auth_ffi_ios_deploy_url/g" <<< "$release_description")
release_description=$(sed "s/S3_SAFE_AUTH_FFI_ANDROID_ARMV7_DEPLOY_URL/$s3_safe_auth_ffi_android_armv7_deploy_url/g" <<< "$release_description")
release_description=$(sed "s/S3_SAFE_AUTH_FFI_ANDROID_X86_64_DEPLOY_URL/$s3_safe_auth_ffi_android_x86_64_deploy_url/g" <<< "$release_description")

release_description=$(sed "s/TAR_SAFE_AUTH_FFI_LINUX_CHECKSUM/$tar_safe_auth_ffi_linux_checksum/g" <<< "$release_description")
release_description=$(sed "s/TAR_SAFE_AUTH_FFI_WINDOWS_CHECKSUM/$tar_safe_auth_ffi_win_checksum/g" <<< "$release_description")
release_description=$(sed "s/TAR_SAFE_AUTH_FFI_MACOS_CHECKSUM/$tar_safe_auth_ffi_macos_checksum/g" <<< "$release_description")
release_description=$(sed "s/TAR_SAFE_AUTH_FFI_IOS_CHECKSUM/$tar_safe_auth_ffi_ios_checksum/g" <<< "$release_description")
release_description=$(sed "s/TAR_SAFE_AUTH_FFI_ANDROID_ARMV7_CHECKSUM/$tar_safe_auth_ffi_android_armv7_checksum/g" <<< "$release_description")
release_description=$(sed "s/TAR_SAFE_AUTH_FFI_ANDROID_X86_64_CHECKSUM/$tar_safe_auth_ffi_android_x86_64_checksum/g" <<< "$release_description")

echo "$release_description"
