#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Publish Argus client package to FTP Usage: ./publish.sh --server HOST --user USER --password PASS [--port 21] Notes: - This script expects to run inside the built client artifact directory. - It reads LATEST_VERSION and uploads setup.sh, argus-metric_.tar.gz, and LATEST_VERSION. EOF } HOST=""; USERNAME=""; PASSWORD=""; PORT=21 while [[ $# -gt 0 ]]; do case "$1" in --server) HOST="$2"; shift 2;; --user) USERNAME="$2"; shift 2;; --password) PASSWORD="$2"; shift 2;; --port) PORT="$2"; shift 2;; -h|--help) usage; exit 0;; *) echo "unknown arg: $1" >&2; usage; exit 1;; esac done [[ -n "$HOST" && -n "$USERNAME" && -n "$PASSWORD" ]] || { usage; exit 1; } here="$(pwd)" if [[ ! -f "$here/LATEST_VERSION" ]]; then echo "LATEST_VERSION not found in $(pwd)" >&2; exit 1; fi VER=$(cat "$here/LATEST_VERSION" | tr -d '\n') PKG="argus-metric_${VER}.tar.gz" if [[ ! -f "$here/$PKG" ]]; then echo "client tar not found: $PKG" >&2; exit 1 fi # locate setup.sh (prefer colocated, fallback to bundled path if provided) SETUP="${here}/setup.sh" if [[ ! -f "$SETUP" ]]; then echo "setup.sh not found in $(pwd)" >&2; exit 1 fi echo "[PUBLISH] server=$HOST port=$PORT version=$VER" curl -u "$USERNAME:$PASSWORD" -sfT "$SETUP" "ftp://$HOST:$PORT/setup.sh" curl -u "$USERNAME:$PASSWORD" -sfT "$PKG" "ftp://$HOST:$PORT/$PKG" printf "%s" "$VER" | curl -u "$USERNAME:$PASSWORD" -sfT - "ftp://$HOST:$PORT/LATEST_VERSION" echo "[OK] publish completed"