60 lines
1.3 KiB
Text
60 lines
1.3 KiB
Text
|
#!/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
|
||
|
|
||
|
# here we're unpacking data.tar.* manually
|
||
|
|
||
|
me=${0##*/}
|
||
|
log() { echo "${me}: $*" 1>&2 ; }
|
||
|
|
||
|
have_cmd() {
|
||
|
if ! command -v "$1" >/dev/null ; then
|
||
|
log "unable to find '$1' - install package '$2' first"
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
have_cmd ar binutils
|
||
|
|
||
|
# naive test for .deb file
|
||
|
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
|
||
|
|
||
|
if [ -z "${data_tar}" ] ; then
|
||
|
log "unable to find data.tar.* in $1 - bailing out"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
decomp= ; decomp_pkg=
|
||
|
case "${data_tar}" in
|
||
|
data.tar.gz) decomp='gzip' decomp_pkg='gzip' ;;
|
||
|
data.tar.xz) decomp='xz' decomp_pkg='xz-utils' ;;
|
||
|
data.tar.zst) decomp='zstd' decomp_pkg='zstd' ;;
|
||
|
*)
|
||
|
log "unable to handle '${data_tar}' from $1 - compression type isn't known to script"
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
have_cmd ${decomp} ${decomp_pkg}
|
||
|
|
||
|
ar p "$1" "${data_tar}" | ${decomp} -d
|