Build and test / Tests and license checks (push) Has been cancelled
Build and test / OpenWrt 24.10.7 · x86-64 (push) Has been cancelled
Build and test / OpenWrt 25.12.4 · x86-64 (push) Has been cancelled
Build and test / OpenWrt 24.10.7 · ipq40xx-generic (push) Has been cancelled
Build and test / OpenWrt 25.12.4 · ipq40xx-generic (push) Has been cancelled
Build and test / OpenWrt 24.10.7 · mediatek-filogic (push) Has been cancelled
Build and test / OpenWrt 25.12.4 · mediatek-filogic (push) Has been cancelled
Build and test / OpenWrt 24.10.7 · ath79-generic (push) Has been cancelled
Build and test / OpenWrt 25.12.4 · ath79-generic (push) Has been cancelled
Build and test / OpenWrt 24.10.7 · ramips-mt7621 (push) Has been cancelled
Build and test / OpenWrt 25.12.4 · ramips-mt7621 (push) Has been cancelled
Build and test / Publish agent GitHub release assets (push) Has been cancelled
Build and test / Publish signed package repository (push) Has been cancelled
153 lines
4.9 KiB
Bash
153 lines
4.9 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "usage: $0 <downloaded-artifacts-dir> <output-dir> <agent-version>" >&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" <<EOF
|
|
{
|
|
"schema": 1,
|
|
"channel": "stable",
|
|
"agent": {
|
|
"version": "${agent_version}",
|
|
"release_url": "https://github.com/Benya9669/openwrt-rmm/releases/tag/agent-v${agent_version}",
|
|
"feed_base_url": "https://benya9669.github.io/openwrt-rmm/feeds/${agent_version}/openwrt"
|
|
},
|
|
"packages": [
|
|
EOF
|
|
cat "$manifest_entries" >> "$output_dir/update-manifest.json"
|
|
printf '\n' >> "$output_dir/update-manifest.json"
|
|
cat >> "$output_dir/update-manifest.json" <<EOF
|
|
]
|
|
}
|
|
EOF
|
|
rm -f "$manifest_entries"
|
|
|
|
cat > "$output_dir/index.html" <<EOF
|
|
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>OpenWrt RMM package repository</title>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>OpenWrt RMM package repository</h1>
|
|
<p>Текущая стабильная версия агента: <strong>${agent_version}</strong>.</p>
|
|
<p>Инструкции подключения находятся в документации проекта.</p>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
EOF
|