#!/usr/bin/env bash set -euo pipefail if [ "$#" -ne 3 ]; then echo "usage: $0 " >&2 exit 2 fi source_dir="$1" output_dir="$2" agent_version="$3" if [ ! -d "$source_dir" ]; then echo "artifact directory does not exist: $source_dir" >&2 exit 1 fi case "$agent_version" in ''|*[!0-9A-Za-z._-]*) echo "invalid agent version: $agent_version" >&2 exit 1 ;; esac if [ -e "$output_dir" ] && [ -n "$(find "$output_dir" -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null)" ]; then echo "output directory must be empty: $output_dir" >&2 exit 1 fi mkdir -p "$output_dir/feeds/$agent_version/openwrt" "$output_dir/keys/usign" "$output_dir/keys/apk" manifest_entries="$output_dir/.update-manifest-entries" : > "$manifest_entries" artifact_count=0 for artifact_dir in "$source_dir"/openwrt-*; do [ -d "$artifact_dir" ] || continue artifact_name="$(basename "$artifact_dir")" remainder="${artifact_name#openwrt-}" openwrt_release="${remainder%%-*}" target_label="${remainder#"$openwrt_release"-}" if [ -z "$openwrt_release" ] || [ -z "$target_label" ] || [ "$target_label" = "$remainder" ]; then echo "cannot parse artifact name: $artifact_name" >&2 exit 1 fi case "$openwrt_release:$target_label" in *[!0-9A-Za-z._:-]*) echo "artifact name contains unsupported manifest characters: $artifact_name" >&2 exit 1 ;; esac destination="$output_dir/feeds/$agent_version/openwrt/$openwrt_release/$target_label" mkdir -p "$destination" cp "$artifact_dir"/* "$destination/" package_format="ipk" if find "$artifact_dir" -maxdepth 1 -type f -name '*.apk' -print -quit | grep -q .; then package_format="apk" fi package_file="$(find "$artifact_dir" -maxdepth 1 -type f \( -name 'rmm-agent-go-production_*.ipk' -o -name 'rmm-agent-go-production-*.apk' \) -print -quit)" package_name="$(basename "$package_file")" case "$package_file" in *.ipk) package_version="$(awk ' /^Package: / { package = substr($0, 10) } package == "rmm-agent-go-production" && /^Version: / { print substr($0, 10); exit } /^$/ { package = "" } ' "$artifact_dir/Packages" 2>/dev/null || true)" if [ -z "$package_version" ]; then package_version="$(printf '%s\n' "$package_name" | sed -n 's/^rmm-agent-go-production_\([^_]*\)_.*/\1/p')" fi ;; *.apk) package_version="$(printf '%s\n' "$package_name" | sed -n 's/^rmm-agent-go-production[-_]\([^_]*\)_.*/\1/p')" ;; *) echo "cannot determine rmm-agent-go-production package version in $artifact_dir" >&2 exit 1 ;; esac case "$package_version" in ''|*[!0-9A-Za-z.+:~_-]*) echo "invalid package version: $package_version" >&2 exit 1 ;; esac if [ -s "$manifest_entries" ]; then printf ',\n' >> "$manifest_entries" fi printf ' {"openwrt_release":"%s","target":"%s","format":"%s","feed_url":"%s","package_version":"%s"}' \ "$openwrt_release" \ "$target_label" \ "$package_format" \ "https://benya9669.github.io/openwrt-rmm/feeds/$agent_version/openwrt/$openwrt_release/$target_label" \ "$package_version" \ >> "$manifest_entries" while IFS= read -r public_key; do cp "$public_key" "$output_dir/keys/usign/$(basename "$public_key")" done < <(find "$artifact_dir" -maxdepth 1 -type f -regextype posix-extended \ -regex '.*/[0-9a-f]{16}' -print) if [ -f "$artifact_dir/rmm-openwrt.pem" ]; then cp "$artifact_dir/rmm-openwrt.pem" "$output_dir/keys/apk/rmm-openwrt.pem" fi artifact_count=$((artifact_count + 1)) done if [ "$artifact_count" -eq 0 ]; then echo "no openwrt-* artifact directories found in $source_dir" >&2 exit 1 fi mkdir -p "$output_dir/feeds/stable" cp -a "$output_dir/feeds/$agent_version/." "$output_dir/feeds/stable/" touch "$output_dir/.nojekyll" cat > "$output_dir/update-manifest.json" <> "$output_dir/update-manifest.json" printf '\n' >> "$output_dir/update-manifest.json" cat >> "$output_dir/update-manifest.json" < "$output_dir/index.html" < OpenWrt RMM package repository

OpenWrt RMM package repository

Текущая стабильная версия агента: ${agent_version}.

Инструкции подключения находятся в документации проекта.

EOF