Script "unpack-them.sh"
#!/bin/sh
# ----------------------
# unpack-them.sh
# version 1.1.4.17
# ----------------------
unpack_if_archive()
# parameters: file names
{
for f_name in $@
do
if [ -f "${f_name}" ]
then
type_of_file=`file "${f_name}" | cut -d':' -f2`
is_bzip2=`echo "${type_of_file}" | grep bzip2`
is_xz=`echo "${type_of_file}" | grep xz`
is_gzip=`echo "${type_of_file}" | grep gzip`
is_tar=`echo "${type_of_file}" | grep tar`
if [ ! -z "${is_bzip2}" ]; then
echo -n "extracting bzip2 archive:" "${f_name}..."
tar xjf "${f_name}" 1>/dev/null 2>&1
[ $? -eq 0 ] && echo " done"
elif [ ! -z "${is_xz}" ]; then
echo -n "extracting xz archive:" "${f_name}..."
tar xJf "${f_name}" 1>/dev/null 2>&1
[ $? -eq 0 ] && echo " done"
elif [ ! -z "${is_gzip}" ]; then
echo -n "extracting gzip archive:" "${f_name}..."
tar xzf "${f_name}" 1>/dev/null 2>&1
[ $? -eq 0 ] && echo " done"
elif [ ! -z "${is_tar}" ]; then
echo -n "extracting tar archive:" "${f_name}..."
tar xf "${f_name}" 1>/dev/null 2>&1
[ $? -eq 0 ] && echo " done"
fi
fi
done
}
# check for required binaries
REQD_BINS=""
which tar >/dev/null 2>&1 || type tar >/dev/null 2>&1 || REQD_BINS="tar,${REQD_BINS}"
which file >/dev/null 2>&1 || type file >/dev/null 2>&1 || REQD_BINS="file,${REQD_BINS}"
which grep >/dev/null 2>&1 || type grep >/dev/null 2>&1 || REQD_BINS="grep,${REQD_BINS}"
if [ ! -z "${REQD_BINS}" ]; then
echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
exit 1
fi
DIR_LS=`ls ./`
echo "${DIR_LS}" | while read LINE
do
unpack_if_archive "${LINE}"
done