#!/bin/bash

set -euo pipefail

PROJECT="getpkg"

#SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

echo "Installing $PROJECT"

ARCH=$(uname -m)

wget -nv "https://getbin.xyz/${PROJECT}:latest-${ARCH}" -O bootstrap && chmod a+x bootstrap

./bootstrap install $PROJECT

rm ./bootstrap

GETPKG_PATH="${HOME}/.local/bin/getpkg/getpkg"

if [ ! -f "$GETPKG_PATH" ]; then
    echo "getpkg not found in $GETPKG_PATH"
    exit 1
fi

VERSION=$(${GETPKG_PATH} version)

echo "getpkg $VERSION installed"
