Files
dshash/publish.sh
Your Name dc717b7064
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 20s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s
feat: Update 4 files
2025-09-02 20:31:24 +12:00

84 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ARCH=$(uname -m)
PROJECT="$(basename "${SCRIPT_DIR}")"
OUTPUT="${SCRIPT_DIR}/output"
VERSION=$(date -u +"%Y.%m%d.%H%M")
function heading() {
echo "--------------------------------"
echo "$1"
echo "--------------------------------"
}
#--------------------------------------------------------------------------------
heading "Publishing ${PROJECT}"
function die() {
heading "error: $1"
exit 1
}
[[ -n ${SOS_WRITE_TOKEN:-} ]] || die "SOS_WRITE_TOKEN not specified"
# clear output dir
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT}"
#--------------------------------------------------------------------------------
heading "Building ${PROJECT}"
# Replace __VERSION__ in the source file before building
sed -i "s|__VERSION__|${VERSION}|g" "${SCRIPT_DIR}/dshash/main.cpp"
# build release version
"${SCRIPT_DIR}/build.sh"
[ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed."
# Restore the placeholder for future builds
sed -i "s|${VERSION}|__VERSION__|g" "${SCRIPT_DIR}/dshash/main.cpp"
# install getpkg
GETPKG_PATH="${HOME}/.local/bin/getpkg/getpkg"
if [ ! -f "${GETPKG_PATH}" ]; then
heading "Installing getpkg"
curl https://getbin.xyz/getpkg-install | bash
if [ ! -f "${GETPKG_PATH}" ]; then
die "getpkg failed to install to ${GETPKG_PATH}"
fi
fi
#--------------------------------------------------------------------------------
heading "Publishing ${PROJECT} as tool to ${PROJECT}:${ARCH} (on getpkg.xyz)"
TOOLDIR="${OUTPUT}/tool"
mkdir "${TOOLDIR}"
cp "${OUTPUT}/${PROJECT}" "${TOOLDIR}/${PROJECT}"
"${GETPKG_PATH}" server set-token getpkg.xyz "${SOS_WRITE_TOKEN}"
"${GETPKG_PATH}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
#--------------------------------------------------------------------------------
heading "Publishing ${PROJECT} to getbin.xyz"
# Download sos if not already present
SOS="${OUTPUT}/sos"
if [ ! -f "${SOS}" ]; then
heading "Downloading sos tool"
curl -L -s -o "${SOS}" "https://getbin.xyz/sos:latest" || die "Failed to download sos"
chmod +x "${SOS}"
fi
# Upload architecture-specific binary to getbin.xyz
heading "Uploading ${PROJECT} binary to getbin.xyz as ${PROJECT}:latest-${ARCH}"
"${SOS}" upload "getbin.xyz" "${OUTPUT}/${PROJECT}" "${PROJECT}:latest-${ARCH}" || die "Failed to upload ${PROJECT} binary to getbin.xyz"
# Check if there's an install script to upload
if [ -f "${SCRIPT_DIR}/install.sh" ]; then
heading "Uploading install.sh to getbin.xyz as ${PROJECT}-install:latest"
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/install.sh" "${PROJECT}-install:latest" || die "Failed to upload install script to getbin.xyz"
fi
heading "Successfully published ${PROJECT} to both getpkg.xyz and getbin.xyz"