You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.4 KiB
Bash

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# 校验 APT 仓库目录完整性,避免发布缺文件。
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_DIR="${APT_VERIFY_REPO_DIR:-$REPO_ROOT/dist/repo}"
SUITE="${APT_REPO_SUITE:-v10}"
COMPONENT="${APT_REPO_COMPONENT:-main}"
ARCHES="${APT_REPO_ARCHES:-amd64 arm64}"
PUBLIC_KEY_ASC_NAME="${APT_PUBLIC_KEY_ASC_NAME:-zyyun-archive-keyring.asc}"
PUBLIC_KEY_GPG_NAME="${APT_PUBLIC_KEY_GPG_NAME:-zyyun-archive-keyring.gpg}"
usage() {
cat <<EOF
用法:
$(basename "$0") [--repo-dir <dir>] [--suite <name>] [--component <name>] [--arches "amd64 arm64"]
环境变量:
APT_VERIFY_REPO_DIR 仓库目录(默认: dist/repo
APT_REPO_SUITE 仓库 suite默认: v10
APT_REPO_COMPONENT 仓库 component默认: main
APT_REPO_ARCHES 仓库架构(默认: "amd64 arm64"
EOF
}
while (($# > 0)); do
case "$1" in
--repo-dir)
REPO_DIR="${2:-}"
shift 2
;;
--suite)
SUITE="${2:-}"
shift 2
;;
--component)
COMPONENT="${2:-}"
shift 2
;;
--arches)
ARCHES="${2:-}"
shift 2
;;
--help|-h)
usage
exit 0
;;
-*)
echo "错误: 未知参数 $1" >&2
exit 1
;;
*)
echo "错误: 不支持的位置参数 $1" >&2
exit 1
;;
esac
done
if [[ ! -d "$REPO_DIR" ]]; then
echo "错误: 仓库目录不存在: $REPO_DIR" >&2
exit 1
fi
required_files=(
"$REPO_DIR/dists/$SUITE/InRelease"
"$REPO_DIR/dists/$SUITE/Release"
"$REPO_DIR/dists/$SUITE/Release.gpg"
"$REPO_DIR/$PUBLIC_KEY_ASC_NAME"
"$REPO_DIR/$PUBLIC_KEY_GPG_NAME"
)
for arch in $ARCHES; do
required_files+=("$REPO_DIR/dists/$SUITE/$COMPONENT/binary-$arch/Packages.gz")
done
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
echo "错误: 缺少必要文件: $file" >&2
exit 1
fi
done
for arch in $ARCHES; do
pkg_gz="$REPO_DIR/dists/$SUITE/$COMPONENT/binary-$arch/Packages.gz"
if ! gzip -t "$pkg_gz" >/dev/null 2>&1; then
echo "错误: Packages.gz 不是有效 gzip 文件: $pkg_gz" >&2
exit 1
fi
done
if ! find "$REPO_DIR/pool/$COMPONENT" -type f -name "*.deb" | read -r _; then
echo "错误: pool/$COMPONENT 下未发现任何 .deb 包" >&2
exit 1
fi
echo "==> APT 仓库自检通过"
echo " repo: $REPO_DIR"
echo " suite: $SUITE"
echo " component: $COMPONENT"
echo " arches: $ARCHES"