mmdebstrap/debextract
Konstantin Demin 2dad1c662c
mmdebstrap: unpack essential packages with proxy script
try unpack package with dpkg-deb and fallback to manual extraction

Signed-off-by: Konstantin Demin <rockdrilla@gmail.com>
2023-01-08 12:55:03 +03:00

50 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
set -ef
# assume that both data.tar and control.tar are compressed with same compressor
# if dpkg-deb can handle control.tar.* then it will handle data.tar.* too
if dpkg-deb --ctrl-tarfile "$1" >/dev/null 2>&1 ; then
exec dpkg-deb --fsys-tarfile "$1"
fi
me=${0##*/}
log() { echo "${me}: $*" 1>&2 ; }
# here we're unpacking data.tar.* manually
# naive test for .deb file
# also check `ar' presense
ar t "$1" >/dev/null
data_tar=
while read -r pkg_member ; do
[ -n "${pkg_member}" ] || continue
if [ -n "${data_tar}" ] ; then
log "extra data tarball '${pkg_member}' in package $1 - bailing out"
exit 1
fi
data_tar="${pkg_member}"
done <<-EOF
$(ar t "$1" | grep -E '^data\.tar')
EOF
decomp=
case "${data_tar}" in
data.tar.gz) decomp='gzip' ;;
data.tar.xz) decomp='xz' ;;
data.tar.zst) decomp='zstd' ;;
esac
if [ -z "${decomp}" ] ; then
log "unable to handle '${data_tar}' from $1 - compression type isn't known to script"
exit 1
fi
if ! command -v ${decomp} >/dev/null ; then
log "enable to find '${decomp}'"
exit 1
fi
ar p "$1" "${data_tar}" | ${decomp} -d