143 lines
3.5 KiB
Bash
Executable File
143 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# 🧪 Load local environment overrides
|
|
if [[ -f .localenv.sh ]]; then
|
|
# If a custom path or other environment variables are needed, include them in .localenv.sh
|
|
source .localenv.sh
|
|
fi
|
|
|
|
# 🧭 Config
|
|
VERSION=$(grep "^const.*version\ *=\ *" main.go | sed -E 's/.*"([^"]+)".*/\1/')
|
|
TAG="v${VERSION}"
|
|
BIN_NAME="x11proxy"
|
|
DIST_DIR="dist/X11Proxy"
|
|
ARCHIVE_NAME="X11Proxy-${VERSION}-linux-x86_64.tar.gz"
|
|
REPO="ezterry/X11Proxy"
|
|
GITEA_URL="https://git-hojo.devnull.name"
|
|
|
|
if [[ -z "$VERSION" ]]; then
|
|
echo "❌ Failed to extract version from main.go"
|
|
echo "please fix the version constant in main.go"
|
|
exit 1
|
|
fi
|
|
|
|
echo "$BIN_NAME build script (version: $VERSION)"
|
|
|
|
# 🧹 Clean build artifacts
|
|
clean() {
|
|
rm -f "$BIN_NAME"
|
|
rm -rf dist "$ARCHIVE_NAME"
|
|
}
|
|
|
|
# 🛠️ Build binary
|
|
build_binary() {
|
|
echo "🔨 Building $BIN_NAME..."
|
|
go build -ldflags "-X main.version=${VERSION}" -o "$BIN_NAME" .
|
|
}
|
|
|
|
# 📦 Build distribution package
|
|
build_dist() {
|
|
clean
|
|
build_binary
|
|
|
|
echo "📦 Creating distribution package..."
|
|
mkdir -p "$DIST_DIR"
|
|
cp "$BIN_NAME" hello_xclock.sh README.md LICENSE.md "$DIST_DIR"
|
|
tar -czvf "$ARCHIVE_NAME" -C dist X11Proxy
|
|
echo "✅ Built: $ARCHIVE_NAME"
|
|
}
|
|
|
|
# 🚀 Publish release to Gitea
|
|
publish_release() {
|
|
#verify we will not run into an issue from a missing jq command
|
|
command -v jq >/dev/null || {
|
|
echo "❌ 'jq' is required but not installed. Please install it to continue."
|
|
exit 1
|
|
}
|
|
|
|
build_dist
|
|
|
|
echo "🔐 Enter Gitea token (will not be saved):"
|
|
read -r -s GITEA_TOKEN
|
|
echo
|
|
|
|
echo "🏷️ Tagging release: $TAG"
|
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
|
echo "❌ Tag $TAG already exists"
|
|
exit 1
|
|
fi
|
|
git tag -a "$TAG" -m "Release $TAG"
|
|
git push origin $TAG
|
|
|
|
echo "📤 Creating release on Gitea..."
|
|
RELEASE_JSON=$(curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d @- <<EOF
|
|
{
|
|
"tag_name": "${TAG}",
|
|
"name": "X11Proxy ${VERSION}",
|
|
"body": "Release ${VERSION}",
|
|
"draft": false,
|
|
"prerelease": false
|
|
}
|
|
EOF
|
|
)
|
|
|
|
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id')
|
|
|
|
echo "📎 Uploading asset to release ID ${RELEASE_ID}..."
|
|
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F name="${ARCHIVE_NAME}" \
|
|
-F attachment=@"${ARCHIVE_NAME}"
|
|
|
|
echo "✅ Published release ${TAG} with asset ${ARCHIVE_NAME}"
|
|
}
|
|
|
|
# 📖 Help message
|
|
print_help() {
|
|
cat <<EOF
|
|
Usage: ./build.sh [OPTION]
|
|
|
|
Build and manage the X11Proxy project.
|
|
|
|
Options:
|
|
--dist Build a distribution package (tar.gz)
|
|
--publish Build and publish release to Gitea (asks for token)
|
|
--help Show this help message
|
|
|
|
By default (no options), the script builds the x11proxy binary.
|
|
|
|
Environment:
|
|
If a .localenv.sh file exists, it will be sourced.
|
|
Use this to override paths or set environment variables.
|
|
|
|
All operations assume a clean build:
|
|
Removes previous binary and dist artifacts before building.
|
|
EOF
|
|
}
|
|
|
|
# 🧭 Main logic
|
|
case "${1:-}" in
|
|
--dist)
|
|
build_dist
|
|
;;
|
|
--publish)
|
|
publish_release
|
|
;;
|
|
--help)
|
|
print_help
|
|
;;
|
|
"")
|
|
clean
|
|
build_binary
|
|
;;
|
|
*)
|
|
echo "❌ Unknown option: $1"
|
|
print_help
|
|
exit 1
|
|
;;
|
|
esac
|