Update publish.sh
This commit is contained in:
95
publish.sh
95
publish.sh
@@ -1,11 +1,10 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
PROJECT="gp"
|
PROJECT="$(basename "${SCRIPT_DIR}")"
|
||||||
|
OUTPUT="${SCRIPT_DIR}/output"
|
||||||
|
|
||||||
|
|
||||||
function heading() {
|
function heading() {
|
||||||
# print a heading with a line of dashe
|
# print a heading with a line of dashe
|
||||||
@@ -14,45 +13,61 @@ function heading() {
|
|||||||
echo "--------------------------------"
|
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}"
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# 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)"
|
heading "Publishing ${PROJECT} as tool to ${PROJECT}:${ARCH} (on getpkg.xyz)"
|
||||||
|
|
||||||
# Generate version timestamp
|
TOOLDIR="${OUTPUT}/tool"
|
||||||
VERSION=$(date -u +"%Y.%m%d.%H%M")
|
mkdir "${TOOLDIR}"
|
||||||
|
cp "${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
||||||
# Update version in the main sos script
|
"${GETPKG_PATH}" server set-token getpkg.xyz "${SOS_WRITE_TOKEN}"
|
||||||
echo "Updating version in main ${PROJECT} script to ${VERSION}..."
|
"${GETPKG_PATH}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
||||||
sed -i "s/^VERSION=\".*\"/VERSION=\"${VERSION}\"/" "${SCRIPT_DIR}/${PROJECT}"
|
|
||||||
|
|
||||||
# Copy the tool to the tool directory
|
|
||||||
TOOLDIR="${SCRIPT_DIR}/tool"
|
|
||||||
mkdir -p "${TOOLDIR}"
|
|
||||||
cp "${SCRIPT_DIR}/${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
|
||||||
|
|
||||||
# Print the version of the tool
|
|
||||||
echo "Version of the tool:"
|
|
||||||
"${TOOLDIR}/${PROJECT}" version
|
|
||||||
|
|
||||||
|
|
||||||
# Use getpkg to publish the tool - check standard location first
|
|
||||||
GETPKG="${HOME}/.local/bin/getpkg/getpkg"
|
|
||||||
if [ ! -f "$GETPKG" ]; then
|
|
||||||
GETPKG="${SCRIPT_DIR}/../getpkg/output/getpkg"
|
|
||||||
fi
|
|
||||||
if [ ! -f "$GETPKG" ]; then
|
|
||||||
GETPKG="${SCRIPT_DIR}/../getpkg/getpkg"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$GETPKG" ]; then
|
|
||||||
"${GETPKG}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
|
||||||
else
|
|
||||||
echo "Warning: getpkg not found, skipping tool publishing to getpkg.xyz"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------
|
||||||
# run sos to upload sos, using the version with the datestamp.
|
heading "Publishing ${PROJECT} to getbin.xyz"
|
||||||
"${SCRIPT_DIR}/sos" upload "getbin.xyz" "${TOOLDIR}/sos" "sos:latest"
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------
|
# Download sos if not already present
|
||||||
# Clean up tool directory
|
SOS="${OUTPUT}/sos"
|
||||||
rm -rf "${TOOLDIR}"
|
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"
|
||||||
|
Reference in New Issue
Block a user