#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

function upload_file() {
    local file="$1"
    local server="getbin.xyz"
    local tag="latest"
    local name;
    name=$(basename "${file}")

    # upload the file to the server
    echo "Uploading ${file} to the server"
    sos upload "${server}" "${file}" "${name}:${tag}"
}


if ! command -v sos &> /dev/null ; then
    echo "sos could not be found"
    exit 1
fi

# find all .tgz in this directory
for file in "${SCRIPT_DIR}"/*.tgz; do
    # upload the file to the server
    echo "Uploading ${file} to the server"
    upload_file "${file}"
done