#!/bin/sh

# Load shared functions:
. /usr/share/pkgtools/shared_functions.sh

if [ $# = 0 ]; then
  cat << EOF

Usage: explodepkg package_name [package_name2 ... ]

Explodes a Slackware compatible software package (or any tar, tar+gzip,
tar+lzma or tar+bzip2 archive) to the current directory.

Note: This should only be used for debugging or examining packages, not for
installing them. It doesn't execute installation scripts or update the package
indexes in /var/log/packages|scripts.

EOF
  exit 0
fi

while [ $# != 0 ]; do
  if [ ! -r "$1" ]; then
    echo "Error: File $1 is not readable."
  else
    # We do not check the file extension to keep explodepkg backwards
    # compatible with original version of Slackware explodepkg.
    echo "Exploding package $1 to the current directory:"
    ( umask 0000 ; uncompress_pkg "$1" | $TAR xvf - )
    if [ $? != 0 ]; then
      echo
      echo "An error occurred exploding the file $1."
      echo
    fi
    if [ -r install/doinst.sh ]; then
      echo
      echo "An installation script was detected in ./install/doinst.sh, but"
      echo "was not executed."
      echo
    fi
  fi
  shift 1
done
