#!/bin/bash

set -euo pipefail

#set projec to the folder this script is in.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT=$(basename "$SCRIPT_DIR")
SOS_DIR="${SCRIPT_DIR}/../sos"

# run sos to upload sos
"${SOS_DIR}/sos" upload "getbin.xyz" "${SCRIPT_DIR}/${PROJECT}" "${PROJECT}:latest" 

# publish the tool
GETPKG="${SCRIPT_DIR}/../getpkg/output/getpkg"
[ -f "${GETPKG}" ] || die "Failed to find getpkg"
TOOLDIR="${SCRIPT_DIR}/tool"
mkdir -p "${TOOLDIR}"
cp "${SCRIPT_DIR}/${PROJECT}" "${TOOLDIR}/${PROJECT}"   
"${GETPKG}" publish "${PROJECT}" "${TOOLDIR}"
rm -rf "${TOOLDIR}"
