88 lines
2.9 KiB
Bash
Executable File
88 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
BUILD_DIR="$ROOT_DIR/deployment/build"
|
|
ART_ROOT="$ROOT_DIR/deployment/artifact"
|
|
|
|
. "$BUILD_DIR/common.sh"
|
|
|
|
usage() { cat <<'EOF'
|
|
Build Argus Client Offline Package
|
|
|
|
Usage: build_client_package.sh [--version YYYYMMDD] [--out DIR]
|
|
|
|
Produces: deployment/artifact/client/<YYYYMMDD>/argus-metric_<YYYYMMDD>.tar.gz
|
|
EOF
|
|
}
|
|
|
|
VERSION="$(today_version)"
|
|
OUT_DIR=""
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--version) VERSION="$2"; shift 2;;
|
|
--out) OUT_DIR="$2"; shift 2;;
|
|
-h|--help) usage; exit 0;;
|
|
*) err "unknown arg: $1"; usage; exit 1;;
|
|
esac
|
|
done
|
|
|
|
PKG_DIR="${OUT_DIR:-$ART_ROOT/client/$VERSION}"
|
|
make_dir "$PKG_DIR"
|
|
|
|
log "Packaging client from all-in-one-full artifact"
|
|
PLUGIN_DIR="$ROOT_DIR/src/metric/client-plugins/all-in-one-full"
|
|
require_cmd bash tar gzip
|
|
|
|
(cd "$PLUGIN_DIR" && bash scripts/package_artifact.sh --force)
|
|
|
|
# pick latest artifact dir
|
|
ART_BASE="$PLUGIN_DIR/artifact"
|
|
latest_dir=$(ls -1dt "$ART_BASE"/*/ 2>/dev/null | head -n1 || true)
|
|
[[ -n "$latest_dir" ]] || { err "no client artifact found in $ART_BASE"; exit 1; }
|
|
|
|
tmpdir=$(mktemp -d)
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
# Filter-only copy: keep install_order files + scripts + deps + version.json
|
|
mkdir -p "$tmpdir/src"
|
|
cp -f "$latest_dir/version.json" "$tmpdir/src/version.json"
|
|
if command -v jq >/dev/null 2>&1; then
|
|
mapfile -t files < <(jq -r '.install_order[]' "$latest_dir/version.json")
|
|
else
|
|
files=( $(grep -E '"install_order"' -A10 "$latest_dir/version.json" | sed -n 's/\s*"\(.*\.tar\.gz\)".*/\1/p') )
|
|
fi
|
|
for f in "${files[@]}"; do
|
|
[[ -f "$latest_dir/$f" ]] && cp -f "$latest_dir/$f" "$tmpdir/src/$f"
|
|
done
|
|
for aux in install.sh uninstall.sh check_health.sh check_version.sh sync_dns.sh restart_unhealthy.sh config.env; do
|
|
[[ -f "$latest_dir/$aux" ]] && cp -f "$latest_dir/$aux" "$tmpdir/src/$aux";
|
|
done
|
|
if [[ -d "$latest_dir/deps" ]]; then
|
|
mkdir -p "$tmpdir/src/deps" && rsync -a "$latest_dir/deps/" "$tmpdir/src/deps/" >/dev/null 2>&1 || cp -r "$latest_dir/deps/." "$tmpdir/src/deps/";
|
|
fi
|
|
|
|
out_name="argus-metric_$(echo "$VERSION" | sed 's/\./_/g').tar.gz"
|
|
|
|
(cd "$tmpdir/src" && tar -czf "$PKG_DIR/$out_name" .)
|
|
|
|
log "Client package ready: $PKG_DIR/$out_name"
|
|
echo "$VERSION" > "$PKG_DIR/LATEST_VERSION"
|
|
|
|
# include publish helper and setup.sh for convenience
|
|
PUBLISH_TPL="$BUILD_DIR/templates/client/publish.sh"
|
|
if [[ -f "$PUBLISH_TPL" ]]; then
|
|
cp "$PUBLISH_TPL" "$PKG_DIR/publish.sh" && chmod +x "$PKG_DIR/publish.sh"
|
|
fi
|
|
|
|
# also place a copy of setup.sh alongside
|
|
SETUP_SRC="$ROOT_DIR/src/metric/client-plugins/all-in-one-full/scripts/setup.sh"
|
|
[[ -f "$SETUP_SRC" ]] && cp "$SETUP_SRC" "$PKG_DIR/setup.sh" || true
|
|
|
|
# docs for end users
|
|
CLIENT_DOC_DIR="$BUILD_DIR/templates/client"
|
|
if [[ -d "$CLIENT_DOC_DIR" ]]; then
|
|
rsync -a "$CLIENT_DOC_DIR/" "$PKG_DIR/" >/dev/null 2>&1 || cp -r "$CLIENT_DOC_DIR/." "$PKG_DIR/"
|
|
fi
|
|
|
|
exit 0
|