aboutsummaryrefslogtreecommitdiff
path: root/debian-container/lib/manifest.sh
diff options
context:
space:
mode:
Diffstat (limited to 'debian-container/lib/manifest.sh')
-rw-r--r--debian-container/lib/manifest.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/debian-container/lib/manifest.sh b/debian-container/lib/manifest.sh
new file mode 100644
index 0000000..2b018c9
--- /dev/null
+++ b/debian-container/lib/manifest.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Copyright (C) 2026 by Richard Qin
+
+dc_manifest_write() {
+ local manifest=$1
+ local tarball=$2
+ local suite=$3
+ local arch=$4
+ local mirror=$5
+ local include=$6
+ local exclude=$7
+ local checksum
+
+ checksum=$(sha256sum "$tarball" | awk '{print $1}')
+ {
+ printf 'format=debootstrap-package-tarball\n'
+ printf 'tarball=%s\n' "$tarball"
+ printf 'suite=%s\n' "$suite"
+ printf 'arch=%s\n' "$arch"
+ printf 'mirror=%s\n' "$mirror"
+ printf 'include=%s\n' "$include"
+ printf 'exclude=%s\n' "$exclude"
+ printf 'created_at=%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+ printf 'sha256=%s\n' "$checksum"
+ } > "$manifest"
+}
+
+dc_manifest_info() {
+ local input=${1:-}
+ local manifest
+ local tarball
+ local expected
+ local actual
+
+ (($# == 1)) || dc_die '用法:base-info TARBALL'
+ dc_require_commands awk sha256sum
+
+ if [[ "$input" == *.manifest ]]; then
+ manifest=$input
+ tarball=${input%.manifest}
+ else
+ manifest="$input.manifest"
+ tarball=$input
+ fi
+ [[ -f "$manifest" ]] || dc_die "找不到 manifest:$manifest"
+
+ cat "$manifest"
+ expected=$(awk -F= '$1 == "sha256" { print $2 }' "$manifest")
+ if [[ -f "$tarball" && -n "$expected" ]]; then
+ actual=$(sha256sum "$tarball" | awk '{print $1}')
+ if [[ "$actual" == "$expected" ]]; then
+ echo 'checksum=match'
+ else
+ echo 'checksum=mismatch'
+ fi
+ fi
+}