Add install script
This commit is contained in:
31
.github/workflows/release.yml
vendored
31
.github/workflows/release.yml
vendored
@@ -55,3 +55,34 @@ jobs:
|
||||
with:
|
||||
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
|
||||
upload-assets: true
|
||||
|
||||
publish-version:
|
||||
needs: [goreleaser]
|
||||
permissions:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout gh-pages
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: gh-pages
|
||||
|
||||
- name: Update latest version
|
||||
run: |
|
||||
echo "${{ github.ref_name }}" > latest.txt
|
||||
|
||||
cat > latest.json << EOF
|
||||
{
|
||||
"version": "${{ github.ref_name }}",
|
||||
"published_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
||||
"url": "https://github.com/Use-Tusk/fence/releases/tag/${{ github.ref_name }}"
|
||||
}
|
||||
EOF
|
||||
|
||||
- name: Commit and push to gh-pages
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add latest.txt latest.json
|
||||
git commit -m "Update latest version to ${{ github.ref_name }}" || echo "No changes to commit"
|
||||
git push origin gh-pages
|
||||
|
||||
18
README.md
18
README.md
@@ -26,7 +26,23 @@ You can use Fence as a Go package or CLI tool.
|
||||
|
||||
## Installation
|
||||
|
||||
At the moment, we only support MacOS and Linux. For Windows users, we recommend using WSL.
|
||||
At the moment, we only support macOS and Linux. For Windows users, we recommend using WSL.
|
||||
|
||||
### Quick Install (Recommended)
|
||||
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/Use-Tusk/fence/main/install.sh | sh
|
||||
```
|
||||
|
||||
To install a specific version:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/Use-Tusk/fence/main/install.sh | sh -s -- v0.1.0
|
||||
```
|
||||
|
||||
### Install via Go
|
||||
|
||||
If you have Go installed:
|
||||
|
||||
```bash
|
||||
go install github.com/Use-Tusk/fence/cmd/fence@latest
|
||||
|
||||
113
install.sh
Normal file
113
install.sh
Normal file
@@ -0,0 +1,113 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Fence Installer (Linux/macOS only)
|
||||
# For Windows, we recommend using WSL.
|
||||
# Usage (latest):
|
||||
# curl -fsSL https://raw.githubusercontent.com/Use-Tusk/fence/main/install.sh | sh
|
||||
# Usage (specific version):
|
||||
# curl -fsSL https://raw.githubusercontent.com/Use-Tusk/fence/main/install.sh | sh -s -- v0.1.0
|
||||
# Or via env var:
|
||||
# curl -fsSL https://raw.githubusercontent.com/Use-Tusk/fence/main/install.sh | FENCE_VERSION=0.1.0 sh
|
||||
|
||||
REPO="Use-Tusk/fence"
|
||||
BINARY_NAME="fence"
|
||||
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
case "$OS" in
|
||||
linux*) OS="linux" ;;
|
||||
darwin*) OS="darwin" ;;
|
||||
mingw*|msys*|cygwin*)
|
||||
echo "Error: This script is for Linux/macOS only."
|
||||
echo "For Windows, we recommend using WSL."
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported operating system: $OS"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$ARCH" in
|
||||
x86_64|amd64) ARCH="x86_64" ;;
|
||||
aarch64|arm64) ARCH="arm64" ;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Determine version to install: use first arg or FENCE_VERSION env var; otherwise fallback to latest
|
||||
REQUESTED_VERSION="${1:-${FENCE_VERSION:-}}"
|
||||
if [ -n "$REQUESTED_VERSION" ]; then
|
||||
case "$REQUESTED_VERSION" in
|
||||
v*) VERSION_TAG="$REQUESTED_VERSION" ;;
|
||||
*) VERSION_TAG="v$REQUESTED_VERSION" ;;
|
||||
esac
|
||||
else
|
||||
# Try manifest first (fast, no rate limits)
|
||||
VERSION_TAG=$(curl -sL "https://use-tusk.github.io/fence/latest.txt" 2>/dev/null || echo "")
|
||||
|
||||
# Fallback to GitHub API if manifest fails
|
||||
if [ -z "$VERSION_TAG" ]; then
|
||||
VERSION_TAG=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$VERSION_TAG" ]; then
|
||||
echo "Error: Unable to determine version to install"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION_NUMBER="${VERSION_TAG#v}"
|
||||
|
||||
case "$OS" in
|
||||
linux) OS_TITLE="Linux" ;;
|
||||
darwin) OS_TITLE="Darwin" ;;
|
||||
*) OS_TITLE="$OS" ;;
|
||||
esac
|
||||
|
||||
DOWNLOAD_URL="https://github.com/$REPO/releases/download/${VERSION_TAG}/${BINARY_NAME}_${VERSION_NUMBER}_${OS_TITLE}_${ARCH}.tar.gz"
|
||||
|
||||
TMP_DIR=$(mktemp -d)
|
||||
cd "$TMP_DIR"
|
||||
|
||||
echo "Downloading from $DOWNLOAD_URL..."
|
||||
if ! curl -fsSL -o fence.tar.gz "$DOWNLOAD_URL"; then
|
||||
echo "Error: Failed to download release"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tar -xzf fence.tar.gz
|
||||
|
||||
# Install to /usr/local/bin or ~/.local/bin
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
if [ ! -w "$INSTALL_DIR" ]; then
|
||||
INSTALL_DIR="$HOME/.local/bin"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
fi
|
||||
|
||||
echo "Installing to $INSTALL_DIR..."
|
||||
mv "$BINARY_NAME" "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR/$BINARY_NAME"
|
||||
|
||||
# Cleanup
|
||||
cd - > /dev/null
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
echo "Fence $VERSION_TAG installed successfully!"
|
||||
echo ""
|
||||
echo "Run 'fence --help' to get started."
|
||||
|
||||
# Check if install dir is in PATH
|
||||
case ":$PATH:" in
|
||||
*":$INSTALL_DIR:"*) ;;
|
||||
*)
|
||||
echo ""
|
||||
echo "⚠️ Add $INSTALL_DIR to your PATH:"
|
||||
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user