This repository has been archived on 2026-03-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
greywall/install.sh
juanarias8 8565916178 feat(install): improve version tag validation and update download URL
- ensure valid semver tags when fetching version
- validate fallback version tag format
- switch download URL to Gitea releases
2026-03-10 14:25:52 -05:00

119 lines
3.1 KiB
Bash

#!/bin/sh
set -e
# Greywall Installer (Linux/macOS only)
# For Windows, we recommend using WSL.
# Usage (latest):
# curl -fsSL https://gitea.app.monadical.io/monadical/greywall/raw/branch/main/install.sh | sh
# Usage (specific version):
# curl -fsSL https://gitea.app.monadical.io/monadical/greywall/raw/branch/main/install.sh | sh -s -- v0.1.0
# Or via env var:
# curl -fsSL https://gitea.app.monadical.io/monadical/greywall/raw/branch/main/install.sh | GREYWALL_VERSION=0.1.0 sh
REPO="monadical/greywall"
BINARY_NAME="greywall"
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 GREYWALL_VERSION env var; otherwise fallback to latest
REQUESTED_VERSION="${1:-${GREYWALL_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) — only accept valid semver tags
VERSION_TAG=$(curl -sL "https://gitea.app.monadical.io/monadical/greywall/raw/branch/gh-pages/latest.txt" 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "")
# Fallback to Gitea API if manifest fails
if [ -z "$VERSION_TAG" ]; then
VERSION_TAG=$(curl -s "https://gitea.app.monadical.io/api/v1/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# Validate it looks like a version tag
case "$VERSION_TAG" in
v[0-9]*) ;;
*) VERSION_TAG="" ;;
esac
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://gitea.app.monadical.io/$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 greywall.tar.gz "$DOWNLOAD_URL"; then
echo "Error: Failed to download release"
exit 1
fi
tar -xzf greywall.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 "Greywall $VERSION_TAG installed successfully!"
echo ""
echo "Run 'greywall --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