65 lines
2.1 KiB
Bash
Executable File
65 lines
2.1 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/latest"
|
|
if command -v jq >/dev/null 2>&1; then
|
|
TAG=$(curl -s "$REPO_API" | jq -r '.tag_name')
|
|
else
|
|
TAG=$(curl -s "$REPO_API" | grep -o '"tag_name"[ ]*:[ ]*\"[^\"]*\"' | head -1 | sed 's/.*: *\"\\([^\"]*\\)\"/\\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 -fsSL -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)"
|
|
echo " "
|
|
echo "try it out with:"
|
|
echo " bb64 ZWNobyAiSGVsbG8td29ybGQhIGJiNjQgaXMgd29ya2luZy4i"
|