bb64/install.sh
2025-05-12 19:06:01 +12:00

64 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -e
# Require root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
fi
# Installs bb64 on the local machine.
# 1. determines the architecture of the local machine
# 2. downloads the appropriate bb64 binary from the latest public release on Gitea (https://gitea.jde.nz/j/bb64/releases)
# 3. makes the bb64 binary executable
# 4. moves the bb64 binary to /usr/local/bin
# 5. prints a message to the user
# 1. Determine architecture
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
BIN=bb64.amd64
elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
BIN=bb64.arm64
else
echo "Unsupported architecture: $ARCH" >&2
exit 1
fi
# 2. Get latest release tag from Gitea API
REPO_API="https://gitea.jde.nz/api/v1/repos/j/bb64/releases"
if command -v jq >/dev/null 2>&1; then
TAG=$(curl -s "$REPO_API" | jq -r '.[0].tag_name')
else
TAG=$(curl -s "$REPO_API" | grep -m1 '"tag_name"' | sed 's/.*"tag_name"[ ]*:[ ]*"\([^"]*\)".*/\1/')
fi
if [ -z "$TAG" ] || [ "$TAG" = "null" ]; then
echo "Could not determine latest release tag from $REPO_API" >&2
exit 1
fi
echo "Latest version of bb64 is: $TAG"
# 3. Download the appropriate binary to a temp directory
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
URL="https://gitea.jde.nz/j/bb64/releases/download/$TAG/$BIN"
echo "Downloading $BIN from $URL..."
curl -L -o "$TMPDIR/bb64" "$URL"
# 4. Make it executable
chmod +x "$TMPDIR/bb64"
# 5. Move to /usr/local/bin
mv "$TMPDIR/bb64" /usr/local/bin/bb64
# 6. Print success message
echo "bb64 installed successfully to /usr/local/bin/bb64 (version $TAG, arch $ARCH)"