Last active
November 30, 2025 18:28
-
-
Save jmkim/37c035cc4c05c12f2a7d8d797e2adbd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| # Author: Jongmin Kim <jmkim@debian.org> | |
| # Usage: ./check-deb.sh file.deb | |
| # Strict mode | |
| set -eu | |
| # $1 as $DEB | |
| DEB="${1:-}" | |
| # Check if $DEB is supplied | |
| if [ -z "$DEB" ]; then | |
| echo "Usage: $0 file.deb" >&2 | |
| exit 1 | |
| fi | |
| # Check if $DEB is a regular file | |
| if [ ! -f "$DEB" ]; then | |
| echo "Error: $DEB is not a regular file (not found or dir)" >&2 | |
| exit 2 | |
| fi | |
| # Extract members from $DEB ar archive (.deb) | |
| if ! MEMBERS="$(ar t "$DEB" 2>/dev/null)"; then | |
| echo 'Error: Not a Debian binary package (not an ar archive)' >&2 | |
| exit 3 | |
| fi | |
| # Locate the tar members | |
| CONTROL_TAR="$(printf '%s\n' "$MEMBERS" | awk '/^control\.tar/ { print; exit; }')" | |
| DATA_TAR="$(printf '%s\n' "$MEMBERS" | awk '/^data\.tar/ { print; exit; }')" | |
| # Check the required members: | |
| # debian-binary (not checked by this script) | |
| # control.tar | |
| # data.tar | |
| # See https://manpages.debian.org/unstable/dpkg-dev/deb.5.en.html | |
| if [ -z "$CONTROL_TAR" ] || [ -z "$DATA_TAR" ]; then | |
| echo 'Error: Not a Debian binary package' >&2 | |
| exit 4 | |
| fi | |
| # Create a temp work dir | |
| TMPDIR="$(mktemp -d "${TMPDIR:-/tmp}/check-deb.XXXXXX")" | |
| trap 'rm -rf "$TMPDIR"' EXIT | |
| # Extract the control tar | |
| ar --output "$TMPDIR" x "$DEB" "$CONTROL_TAR" | |
| tar -C "$TMPDIR" -xf "$TMPDIR/$CONTROL_TAR" | |
| # Check if control file exists | |
| CONTROL="$TMPDIR/control" | |
| if [ ! -f "$CONTROL" ]; then | |
| echo 'Error: Not a Debian binary package (control file missing)' >&2 | |
| exit 5 | |
| fi | |
| # Extract the pkg version and pkg name from the control file | |
| VER="$(awk -F': ' '/^Version: / { print $2; }' "$CONTROL")" | |
| PKG="$(awk -F': ' '/^Package: / { print $2; }' "$CONTROL")" | |
| # Print the pkg version | |
| echo "Version: $VER" | |
| # Extract the data tar | |
| ar --output "$TMPDIR" x "$DEB" "$DATA_TAR" | |
| tar -C "$TMPDIR" -xf "$TMPDIR/$DATA_TAR" | |
| # Check for the copyright file | |
| COPYRIGHT="/usr/share/doc/$PKG/copyright" | |
| if [ -f "$TMPDIR$COPYRIGHT" ]; then | |
| echo "Has copyright file in $COPYRIGHT" | |
| else | |
| echo "Missing copyright file in $COPYRIGHT" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment