diff --git a/deploy.sh b/deploy.sh index 4822447..3b0e1cd 100644 --- a/deploy.sh +++ b/deploy.sh @@ -28,8 +28,34 @@ case "$ARCH" in *) echo -e "${RED}Unsupported architecture: $ARCH${NC}"; exit 1 ;; esac -REPO="https://git.sechpoint.app/customer-engineering/wallarm" -BIN_URL="${REPO}/raw/branch/main/bin/wallarm-linux-${BIN_ARCH}" +REPO="https://git.sechpoint.app" +REPO_PATH="customer-engineering/wallarm" +API_URL="${REPO}/api/v1/repos/${REPO_PATH}/releases" + +# Fetch latest release info +echo -e "${YELLOW}Checking latest release...${NC}" +if command -v curl >/dev/null 2>&1; then + RELEASE_JSON=$(curl -fsSL "${API_URL}?limit=1" 2>/dev/null) +elif command -v wget >/dev/null 2>&1; then + RELEASE_JSON=$(wget -qO- "${API_URL}?limit=1" 2>/dev/null) +else + echo -e "${RED}Neither curl nor wget found. Install one and re-run.${NC}" + exit 1 +fi + +# Parse release tag and asset URL +RELEASE_TAG=$(echo "$RELEASE_JSON" | grep -o '"tag_name":"[^"]*"' | head -1 | cut -d'"' -f4) +if [[ -z "$RELEASE_TAG" ]]; then + echo -e "${RED}No release found. Create a Gitea release first.${NC}" + exit 1 +fi + +BIN_URL="${REPO}/api/v1/repos/${REPO_PATH}/releases/tags/${RELEASE_TAG}/assets" +echo -e "${GREEN} Latest release: ${RELEASE_TAG}${NC}" + +# Download the binary via release assets API +ASSETS_JSON=$(curl -fsSL "${REPO}/api/v1/repos/${REPO_PATH}/releases/tags/${RELEASE_TAG}" 2>/dev/null) +DOWNLOAD_URL=$(echo "$ASSETS_JSON" | grep -o "\"browser_download_url\":\"[^\"]*wallarm-linux-${BIN_ARCH}[^\"]*" | head -1 | cut -d'"' -f4) DEPLOY_DIR="${HOME:-/root}/deploy" BIN_PATH="${DEPLOY_DIR}/wallarm" @@ -39,11 +65,18 @@ echo -e "${BOLD}Wallarm Deployment Bootstrap${NC}" echo # Download the binary -echo -e "${YELLOW}Downloading wallarm binary (linux-${BIN_ARCH})...${NC}" +if [[ -z "$DOWNLOAD_URL" ]]; then + echo -e "${RED}No linux-${BIN_ARCH} binary found in release ${RELEASE_TAG}.${NC}" + echo -e "${YELLOW}Available assets:${NC}" + echo "$ASSETS_JSON" | grep -o '"name":"[^"]*"' | cut -d'"' -f4 + exit 1 +fi + +echo -e "${YELLOW}Downloading wallarm (${RELEASE_TAG}, linux-${BIN_ARCH})...${NC}" if command -v curl >/dev/null 2>&1; then - curl -fsSL --progress-bar "$BIN_URL" -o "$BIN_PATH" + curl -fsSL --progress-bar "$DOWNLOAD_URL" -o "$BIN_PATH" elif command -v wget >/dev/null 2>&1; then - wget -q --show-progress "$BIN_URL" -O "$BIN_PATH" + wget -q --show-progress "$DOWNLOAD_URL" -O "$BIN_PATH" else echo -e "${RED}Neither curl nor wget found. Install one and re-run.${NC}" exit 1