Files
orrisroot a033dfa970
Validate / lint (push) Successful in 11m0s
Validate / import-test (push) Canceled after 1m12s
feat: bootstrap Zabbix template repository
Set up a repository for custom Zabbix templates and add the first
template for Dell PowerVault ME storage systems.

- Add conventions, version policy, and release documentation.
- Add validation, index, packaging, export, and import-test scripts.
- Add a disposable Zabbix test stack with version-aware imports.
- Add PowerVault ME SNMP exports for Zabbix 7.0 and 8.0.
- Cover system information, unit health, sensors, ports, and
  firmware revisions.
2026-11-03 14:40:19 +09:00

115 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DIST="$ROOT/dist"
usage() {
cat <<'EOF'
Usage:
scripts/package.sh [package-id]
If package-id is omitted, all packages are packaged.
Example:
scripts/package.sh app/apache
EOF
}
if [[ $# -gt 1 ]]; then
usage
exit 1
fi
target="${1:-}"
target="${target%/}"
command -v zip >/dev/null 2>&1 || {
echo "ERROR: zip is required." >&2
exit 1
}
python3 -c 'import yaml' >/dev/null 2>&1 || {
echo "ERROR: PyYAML is required (pip install -r requirements-dev.txt)." >&2
exit 1
}
mkdir -p "$DIST"
tmp_root="$(mktemp -d)"
cleanup() {
rm -rf "$tmp_root"
}
trap cleanup EXIT
created=0
while IFS= read -r manifest; do
package_dir="$(dirname "$manifest")"
rel="${package_dir#"$ROOT/templates/"}"
if [[ -n "$target" && "$rel" != "$target" ]]; then
continue
fi
meta="$(
python3 - "$manifest" <<'PY'
import sys
import yaml
with open(sys.argv[1], encoding="utf-8") as fh:
data = yaml.safe_load(fh) or {}
print(data.get("id") or "")
print(data.get("version") or "")
PY
)"
id="$(sed -n '1p' <<<"$meta")"
version="$(sed -n '2p' <<<"$meta")"
if [[ -z "$id" || -z "$version" ]]; then
echo "WARN: id or version is empty: ${manifest#"$ROOT/"}" >&2
continue
fi
for version_dir in "$package_dir"/*/; do
[[ -d "$version_dir" ]] || continue
zbx_version="$(basename "$version_dir")"
[[ "$zbx_version" =~ ^[0-9]+\.[0-9]+$ ]] || continue
mapfile -t yaml_files < <(
find "$version_dir" -maxdepth 1 -type f \
\( -name '*.yaml' -o -name '*.yml' \) | sort
)
if [[ ${#yaml_files[@]} -eq 0 ]]; then
echo "SKIP: No YAML files in ${version_dir#"$ROOT/"}" >&2
continue
fi
safe_id="${id//\//_}"
staging="$tmp_root/${safe_id}-${version}-${zbx_version}"
mkdir -p "$staging"
cp "$package_dir/README.md" "$package_dir/CHANGELOG.md" \
"$package_dir/manifest.yaml" "$staging/"
cp "${yaml_files[@]}" "$staging/"
if [[ -d "$package_dir/assets" ]]; then
cp -R "$package_dir/assets" "$staging/"
fi
out="$DIST/${safe_id}-${version}-zbx${zbx_version}.zip"
rm -f "$out"
(cd "$staging" && zip -q -r "$out" .)
rm -rf "$staging"
echo "Created: ${out#"$ROOT/"}"
created=$((created + 1))
done
done < <(find "$ROOT/templates" -name manifest.yaml -type f | sort)
if [[ $created -eq 0 ]]; then
if [[ -n "$target" ]]; then
echo "ERROR: Package not found or it has no distributable YAML: $target" >&2
exit 1
fi
echo "No artifacts were created."
fi