Use getpkg to install.
This commit is contained in:
10
README.md
10
README.md
@@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
Automated system-wide installation:
|
If you don't already have getpkg installed:
|
||||||
```
|
```
|
||||||
curl -fsSL https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh | bash
|
curl https://getbin.xyz/getpkg-install | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
## To download just the bb64 executable:
|
Then install bb64 via getpkg for the current user:
|
||||||
|
|
||||||
```
|
```
|
||||||
curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64
|
getpkg install bb64
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Use
|
# Use
|
||||||
|
|
||||||
Bash Base64, written in C++.
|
Bash Base64, written in C++.
|
||||||
|
41
install.sh
41
install.sh
@@ -1,41 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# install bb64 using getpkg for current user.
|
|
||||||
|
|
||||||
PROJECT="bb64"
|
|
||||||
|
|
||||||
#SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
||||||
|
|
||||||
echo "Installing $PROJECT"
|
|
||||||
|
|
||||||
ARCH=$(uname -m)
|
|
||||||
|
|
||||||
# check if getpkg is installed
|
|
||||||
GETPKG_PATH="${HOME}/.local/bin/getpkg/getpkg"
|
|
||||||
if [ ! -f "$GETPKG_PATH" ]; then
|
|
||||||
wget -nv "https://getbin.xyz/getpkg:latest-${ARCH}" -O bootstrap && chmod a+x bootstrap
|
|
||||||
./bootstrap install getpkg
|
|
||||||
rm ./bootstrap
|
|
||||||
|
|
||||||
if [ ! -f "$GETPKG_PATH" ]; then
|
|
||||||
echo "getpkg failed to install to $GETPKG_PATH"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "getpkg found in $GETPKG_PATH"
|
|
||||||
|
|
||||||
# install bb64
|
|
||||||
$GETPKG_PATH install $PROJECT
|
|
||||||
|
|
||||||
# confirm bb64 is installed
|
|
||||||
PROJPATH="${HOME}/.local/bin/getpkg/${PROJECT}"
|
|
||||||
if [ ! -f "$PROJPATH" ]; then
|
|
||||||
echo "getpkg failed to install $PROJECT to $PROJPATH"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check version
|
|
||||||
VERSION=$(${PROJPATH} version)
|
|
||||||
echo "${PROJECT} ${VERSION} installed"
|
|
227
publish.sh
227
publish.sh
@@ -1,209 +1,56 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Publishes bb64 to the Gitea Releases page for the repository.
|
|
||||||
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="bb64"
|
PROJECT="$(basename "${SCRIPT_DIR}")"
|
||||||
OUTPUT="${SCRIPT_DIR}/output"
|
OUTPUT="${SCRIPT_DIR}/output"
|
||||||
|
|
||||||
ARCH_ALIAS="amd64"
|
|
||||||
if [ "$ARCH" = "aarch64" ]; then
|
|
||||||
ARCH_ALIAS="arm64"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get version from CMake timestamp
|
function heading() {
|
||||||
VERSION=$(date +"%Y.%m%d.%H%M")
|
# print a heading with a line of dashe
|
||||||
TAG="v$VERSION"
|
echo "--------------------------------"
|
||||||
echo "Building version $VERSION" >&2
|
echo "$1"
|
||||||
|
echo "--------------------------------"
|
||||||
# build release version
|
|
||||||
export CMAKE_BUILD_TYPE="Release"
|
|
||||||
|
|
||||||
# Build with or without cache based on NO_CACHE environment variable
|
|
||||||
CACHE_FLAG=""
|
|
||||||
if [ "${NO_CACHE:-false}" = "true" ]; then
|
|
||||||
CACHE_FLAG="--no-cache"
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
${CACHE_FLAG} \
|
|
||||||
-t "${PROJECT}-build" \
|
|
||||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
|
||||||
--build-arg PROJECT="${PROJECT}" \
|
|
||||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
|
||||||
--output "${OUTPUT}" \
|
|
||||||
"${SCRIPT_DIR}"
|
|
||||||
|
|
||||||
if [ ! -f "${OUTPUT}/${PROJECT}" ]; then
|
|
||||||
echo "Build failed." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH_ALIAS}"
|
|
||||||
cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH}"
|
|
||||||
|
|
||||||
# Find repo info from .git/config
|
|
||||||
REPO_URL=$(git config --get remote.origin.url)
|
|
||||||
if [[ ! $REPO_URL =~ gitea ]]; then
|
|
||||||
echo "Remote origin is not a Gitea repository: $REPO_URL" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# Extract base URL, owner, and repo
|
|
||||||
# Example: https://gitea.example.com/username/reponame.git
|
|
||||||
BASE_URL=$(echo "$REPO_URL" | sed -E 's#(https?://[^/]+)/.*#\1#')
|
|
||||||
OWNER=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)/[^/]+(\.git)?$#\1#')
|
|
||||||
REPO=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)(\.git)?$#\1#')
|
|
||||||
|
|
||||||
API_URL="$BASE_URL/api/v1/repos/$OWNER/$REPO"
|
|
||||||
|
|
||||||
# Create release
|
|
||||||
RELEASE_DATA=$(cat <<EOF
|
|
||||||
{
|
|
||||||
"tag_name": "$TAG",
|
|
||||||
"name": "$TAG",
|
|
||||||
"body": "bb64 release $TAG",
|
|
||||||
"draft": false,
|
|
||||||
"prerelease": false,
|
|
||||||
"arch": ["${ARCH_ALIAS}"]
|
|
||||||
}
|
}
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
if [ -z "$RELEASE_WRITE_TOKEN" ]; then
|
#--------------------------------------------------------------------------------
|
||||||
echo "RELEASE_WRITE_TOKEN not set" >&2
|
heading "Publishing ${PROJECT}"
|
||||||
|
|
||||||
|
function die() {
|
||||||
|
heading "error: $1"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
|
|
||||||
# Create and push git tag
|
[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN not specified"
|
||||||
echo "Creating git tag $TAG..."
|
|
||||||
|
|
||||||
# Configure git identity if not set (for CI environments)
|
# clear output dir
|
||||||
if ! git config user.email >/dev/null 2>&1; then
|
rm -rf "${OUTPUT}"
|
||||||
git config user.email "ci@gitea.jde.nz"
|
mkdir -p "${OUTPUT}"
|
||||||
git config user.name "CI Bot"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if tag already exists locally
|
|
||||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
|
||||||
echo "Tag $TAG already exists locally, deleting it first..."
|
|
||||||
git tag -d "$TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if tag exists on remote
|
|
||||||
TAG_EXISTS_ON_REMOTE=false
|
|
||||||
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
|
|
||||||
echo "Tag $TAG already exists on remote - this is expected for multi-architecture builds"
|
|
||||||
echo "Skipping tag creation and proceeding with release attachment..."
|
|
||||||
TAG_EXISTS_ON_REMOTE=true
|
|
||||||
else
|
|
||||||
echo "Creating new tag $TAG..."
|
|
||||||
git tag -a "$TAG" -m "Release $TAG"
|
|
||||||
if ! git push origin "$TAG"; then
|
|
||||||
echo "Failed to push tag $TAG to origin" >&2
|
|
||||||
# Try to delete local tag if push failed
|
|
||||||
git tag -d "$TAG"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Successfully created and pushed tag $TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Getting or creating release $TAG on Gitea..."
|
|
||||||
|
|
||||||
# First try to get existing release
|
|
||||||
EXISTING_RELEASE=$(curl -s -X GET "$API_URL/releases/tags/$TAG" \
|
|
||||||
-H "Authorization: token $RELEASE_WRITE_TOKEN")
|
|
||||||
|
|
||||||
echo "Existing release check response: $EXISTING_RELEASE" >&2
|
|
||||||
|
|
||||||
if echo "$EXISTING_RELEASE" | grep -q '"id":[0-9]*'; then
|
|
||||||
# Release already exists, get its ID
|
|
||||||
RELEASE_ID=$(echo "$EXISTING_RELEASE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
||||||
echo "Release $TAG already exists with ID: $RELEASE_ID"
|
|
||||||
else
|
|
||||||
# Create new release only if tag was just created
|
|
||||||
if [ "$TAG_EXISTS_ON_REMOTE" = true ]; then
|
|
||||||
echo "Tag exists on remote but no release found - this shouldn't happen" >&2
|
|
||||||
echo "API response was: $EXISTING_RELEASE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Creating new release $TAG on Gitea..."
|
|
||||||
RELEASE_RESPONSE=$(curl -s -X POST "$API_URL/releases" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authorization: token $RELEASE_WRITE_TOKEN" \
|
|
||||||
-d "$RELEASE_DATA")
|
|
||||||
|
|
||||||
echo "Release API response: $RELEASE_RESPONSE"
|
|
||||||
|
|
||||||
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
||||||
|
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
|
||||||
echo "Failed to create release on Gitea." >&2
|
|
||||||
echo "API URL: $API_URL/releases" >&2
|
|
||||||
echo "Release data: $RELEASE_DATA" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Created new release with ID: $RELEASE_ID"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Upload binaries and install.sh
|
|
||||||
echo "Uploading assets to release..."
|
|
||||||
for FILE in ${PROJECT}.${ARCH_ALIAS} ${PROJECT}.${ARCH} install.sh; do
|
|
||||||
if [ -f "output/$FILE" ]; then
|
|
||||||
filetoupload="output/$FILE"
|
|
||||||
elif [ -f "$FILE" ]; then
|
|
||||||
filetoupload="$FILE"
|
|
||||||
else
|
|
||||||
echo "Skipping $FILE - not found"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Uploading $filetoupload as $FILE..."
|
|
||||||
# Auto-detect content type
|
|
||||||
ctype=$(file --mime-type -b "$filetoupload")
|
|
||||||
|
|
||||||
UPLOAD_RESPONSE=$(curl -s -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$FILE" \
|
|
||||||
-H "Content-Type: $ctype" \
|
|
||||||
-H "Authorization: token $RELEASE_WRITE_TOKEN" \
|
|
||||||
--data-binary @"$filetoupload")
|
|
||||||
|
|
||||||
if echo "$UPLOAD_RESPONSE" | grep -q '"id"'; then
|
|
||||||
echo "✓ Uploaded $FILE to release $TAG as $ctype."
|
|
||||||
else
|
|
||||||
echo "✗ Failed to upload $FILE. Response: $UPLOAD_RESPONSE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Published bb64 version $VERSION to $REPO_URL (tag $TAG) with binaries for $ARCH_ALIAS / $ARCH."
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------
|
||||||
echo "Publishing ${PROJECT} as tool to getpkg.xyz"
|
heading "Building ${PROJECT}"
|
||||||
|
|
||||||
|
# build release version
|
||||||
|
export CMAKE_BUILD_TYPE="Release"
|
||||||
|
"${SCRIPT_DIR}/build.sh"
|
||||||
|
[ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed."
|
||||||
|
|
||||||
|
# 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)"
|
||||||
|
|
||||||
# Create tool directory structure
|
|
||||||
TOOLDIR="${OUTPUT}/tool"
|
TOOLDIR="${OUTPUT}/tool"
|
||||||
mkdir "${TOOLDIR}"
|
mkdir "${TOOLDIR}"
|
||||||
cp "${OUTPUT}/${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
cp "${OUTPUT}/${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
||||||
|
"${GETPKG_PATH}" server set-token getpkg.xyz "${SOS_WRITE_TOKEN}"
|
||||||
# Use getpkg to publish the tool
|
"${GETPKG_PATH}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
||||||
GETPKG="${SCRIPT_DIR}/../getpkg/output/getpkg"
|
|
||||||
if [ ! -f "$GETPKG" ]; then
|
|
||||||
GETPKG="${SCRIPT_DIR}/../getpkg/getpkg"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$GETPKG" ]; then
|
|
||||||
echo "Publishing ${PROJECT} to getpkg.xyz using ${GETPKG}..."
|
|
||||||
if "${GETPKG}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"; then
|
|
||||||
echo "✓ Successfully published ${PROJECT} to getpkg.xyz"
|
|
||||||
else
|
|
||||||
echo "✗ Failed to publish ${PROJECT} to getpkg.xyz" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Warning: getpkg not found at $GETPKG, skipping tool publishing to getpkg.xyz"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "✓ BB64 publish script completed successfully"
|
|
||||||
|
Reference in New Issue
Block a user