Compare commits
3 Commits
8404e80bb8
...
21b486ceb0
| Author | SHA1 | Date | |
|---|---|---|---|
| 21b486ceb0 | |||
| 633a5c2aa1 | |||
| 52eaba7d76 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.vscode
|
||||
x11proxy
|
||||
build.sh
|
||||
dist
|
||||
.localenv.sh
|
||||
X11Proxy-*.tar.gz
|
||||
127
build.sh
Executable file
127
build.sh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/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"
|
||||
|
||||
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() {
|
||||
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"
|
||||
|
||||
echo "📤 Creating release on Gitea..."
|
||||
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
|
||||
|
||||
echo "📎 Uploading asset..."
|
||||
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases/${TAG}/assets" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-F name="${ARCHIVE_NAME}" \
|
||||
-F attachment=@"${ARCHIVE_NAME}"
|
||||
|
||||
echo "✅ Published release ${TAG} with asset ${ARCHIVE_NAME}"
|
||||
echo "📌 Remember to push the tag: git push origin ${TAG}"
|
||||
}
|
||||
|
||||
# 📖 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
|
||||
@@ -37,11 +37,9 @@ cleanup_stale_logs() {
|
||||
if [ "${1:-}" != "--daemon" ]; then
|
||||
cleanup_stale_logs
|
||||
echo "Launching X11 proxy and container in background..."
|
||||
mkdir -p "${TEMPBASE}"
|
||||
|
||||
# Launch self in background and prepend PID to log
|
||||
nohup "$0" --daemon 2>&1 > "$LOGFILE" &
|
||||
|
||||
sleep 1 #let the pocess start (and echo any nohup warnings)
|
||||
echo "Started background process. Logs: $LOGFILE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user