Last active 1747638210

Compare two manifest files and list packages present in the first but not the second.

Revision e658711e5a829c6b9a620cd717a07911b0aef483

compare_manifest.sh Raw
1#!/usr/bin/env bash
2# compare_manifest.sh - Compare two manifest files and list packages present in the first but not the second.
3
4set -euo pipefail
5
6# Function to display usage information
7usage() {
8 echo "Usage: $0 <left.manifest> <right.manifest>"
9 echo
10 echo "Extracts package names (first column, without architecture suffix) from each manifest, sorts them,"
11 echo "and prints packages present in the left file but not the right."
12 exit 1
13}
14
15# Ensure exactly two arguments are provided
16if [[ $# -ne 2 ]]; then
17 usage
18fi
19
20left_manifest="$1"
21right_manifest="$2"
22
23# Create a temporary directory for intermediate files
24tmpdir=$(mktemp -d)
25# Ensure the temporary directory is removed on script exit
26trap 'rm -rf "${tmpdir}"' EXIT
27
28# Extract package names, strip ':架构' 后缀,排序并去重,写入临时文件
29awk '{print $1}' "${left_manifest}" | sed 's/:.*$//' | sort -u > "${tmpdir}/left.txt"
30awk '{print $1}' "${right_manifest}" | sed 's/:.*$//' | sort -u > "${tmpdir}/right.txt"
31
32# Output the comparison result
33echo "Packages in '${left_manifest}' but not in '${right_manifest}':"
34comm -23 "${tmpdir}/left.txt" "${tmpdir}/right.txt"
35