196 lines
5.5 KiB
Bash
Executable File
196 lines
5.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# vim: set sw=4 sts=4 et :
|
|
|
|
# Copyright (c) 2006, 2007, 2008, 2011 Ciaran McCreesh
|
|
#
|
|
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
|
|
# Gentoo Foundation and distributed under the terms of the GNU General
|
|
# Public License v2.
|
|
#
|
|
# This file is part of the Paludis package manager. Paludis is free software;
|
|
# you can redistribute it and/or modify it under the terms of the GNU General
|
|
# Public License as published by the Free Software Foundation; either version
|
|
# 2 of the License, or (at your option) any later version.
|
|
#
|
|
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with
|
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
# Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
die()
|
|
{
|
|
echo "unpack: error: $@" 1>&2
|
|
if [[ -z ${PALUDIS_FAILURE_IS_NONFATAL} ]]; then
|
|
echo "$(basename ${0} ): making ebuild PID ${EBUILD_KILL_PID} exit with error" 1>&2
|
|
kill -s SIGUSR1 "${EBUILD_KILL_PID}"
|
|
fi
|
|
exit 123
|
|
}
|
|
|
|
assert()
|
|
{
|
|
local _pipestatus="${PIPESTATUS[*]}"
|
|
[[ -z "${_pipestatus//[ 0]/}" ]] || die "$@: $_pipestatus"
|
|
}
|
|
|
|
unpack_tar() {
|
|
echo tar xf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" 1>&2
|
|
tar xf "${1}" --no-same-owner "${TAR_OPTIONS[@]}"
|
|
}
|
|
|
|
unpack_tar.gz() {
|
|
echo tar zxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" 1>&2
|
|
tar zxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}"
|
|
}
|
|
|
|
unpack_tar.bz2() {
|
|
echo tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" ${UNPACKONLY:+"${UNPACKONLY}"} 1>&2
|
|
tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" ${UNPACKONLY:+"${UNPACKONLY}"}
|
|
}
|
|
|
|
unpack_zip() {
|
|
echo unzip -qo "${1}" 1>&2
|
|
unzip -qo "${1}"
|
|
}
|
|
|
|
unpack_gz() {
|
|
echo gzip -dc "${1}" \> "${UNPACKTODIR}/$(basename "${1%.*}" )" 1>&2
|
|
gzip -dc "${1}" > "${UNPACKTODIR}/$(basename "${1%.*}" )"
|
|
}
|
|
|
|
unpack_bz2() {
|
|
echo bzip2 -dc "${1}" \> "${UNPACKTODIR}/$(basename "${1%.*}" )" 1>&2
|
|
bzip2 -dc "${1}" > "${UNPACKTODIR}/$(basename "${1%.*}" )" || die "Couldn't unpack ${1}"
|
|
}
|
|
|
|
unpack_rar() {
|
|
echo unrar x -idq "${1}" 1>&2
|
|
unrar x -idq "${1}"
|
|
}
|
|
|
|
unpack_lha() {
|
|
echo lha xfq "${1}" 1>&2
|
|
lha xfq "${1}"
|
|
}
|
|
|
|
unpack_a() {
|
|
echo ar x "${1}" 1>&2
|
|
ar x "${1}" 1>&2
|
|
}
|
|
|
|
unpack_tar.lzma() {
|
|
echo lzma -dc "${1}" \| strip_tar_corruption \| tar xf - --no-same-owner "${TAR_OPTIONS[@]}"
|
|
lzma -dc "${1}" | strip_tar_corruption | tar xf - --no-same-owner "${TAR_OPTIONS[@]}"
|
|
assert "Couldn't unpack ${1}"
|
|
}
|
|
|
|
unpack_lzma() {
|
|
echo lzma -dc "${1}" \> "${UNPACKTODIR}/$(basename "${1%.*}" )" 1>&2
|
|
lzma -dc "${1}" > "${UNPACKTODIR}/$(basename "${1%.*}" )"
|
|
}
|
|
|
|
unpack_7z() {
|
|
echo 7z x -y "${1}"
|
|
7z x -y "${1}"
|
|
}
|
|
|
|
unpack_tar.xz() {
|
|
echo xz -dc "${1}" \| strip_tar_corruption \| tar xf - --no-same-owner "${TAR_OPTIONS[@]}"
|
|
xz -dc "${1}" | strip_tar_corruption | tar xf - --no-same-owner "${TAR_OPTIONS[@]}"
|
|
assert "Couldn't unpack ${1}"
|
|
}
|
|
|
|
unpack_xz() {
|
|
echo xz -dc "${1}" \> "${UNPACKTODIR}/$(basename "${1%.*}" )" 1>&2
|
|
xz -dc "${1}" > "${UNPACKTODIR}/$(basename "${1%.*}" )"
|
|
}
|
|
|
|
unpack_one()
|
|
{
|
|
local file=${1} compare=${1}
|
|
[[ -n ${PALUDIS_UNPACK_CASE_INSENSITIVE} ]] &&
|
|
compare=$(tr '[:upper:]' '[:lower:]' <<<"${compare}")
|
|
|
|
[[ -z ${file} ]] && die "Bad argument for unpack_one"
|
|
[[ -e ${file} ]] || die "${file} doesn't exist"
|
|
|
|
if [[ -n "${UNPACKONLY}" ]] ; then
|
|
case ${compare} in
|
|
*.tar.bz2|*.tbz2|*.tbz)
|
|
;;
|
|
|
|
*)
|
|
die "Can't use --only with ${file}"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
local group split suffix
|
|
for group in ${PALUDIS_UNPACK_SUFFIXES}; do
|
|
split=( $(IFS=,; echo ${group} ) )
|
|
for suffix in ${split[@]}; do
|
|
[[ -n ${PALUDIS_UNPACK_CASE_INSENSITIVE} ]] &&
|
|
suffix=$(tr '[:upper:]' '[:lower:]' <<<"${suffix}")
|
|
if [[ ${compare} == *.${suffix} ]]; then
|
|
unpack_${split[0]} "${file}" || die "Couldn't unpack ${file}"
|
|
return
|
|
fi
|
|
done
|
|
done
|
|
|
|
if [[ -n "${PALUDIS_UNPACK_UNRECOGNISED_IS_FATAL}" ]] ; then
|
|
die "Don't know how to unpack ${file}"
|
|
else
|
|
echo "Skipping unpack for ${file}"
|
|
fi
|
|
}
|
|
|
|
export UNPACKFROMDIR="${!PALUDIS_UNPACK_FROM_VAR}"
|
|
export UNPACKTODIR="${PWD}"
|
|
unset UNPACKONLY
|
|
TAR_OPTIONS=( )
|
|
|
|
while [[ "${1#--}" != "${1}" ]] ; do
|
|
if [[ "${1}" == "--only" ]] ; then
|
|
shift
|
|
export UNPACKONLY="${1}"
|
|
shift
|
|
elif [[ "${1}" == "--if-compressed" ]] ; then
|
|
export PALUDIS_UNPACK_UNRECOGNISED_IS_FATAL=
|
|
shift
|
|
elif [[ "${1}" == --tar-option=* ]] ; then
|
|
TAR_OPTIONS[${#TAR_OPTIONS[@]}]="${1#*=}"
|
|
shift
|
|
else
|
|
die "Unrecognised option: ${1}"
|
|
fi
|
|
done
|
|
|
|
[[ -z "$@" ]] && die "No arguments given to unpack"
|
|
|
|
for x in "$@" ; do
|
|
x=$(echo $x )
|
|
echo ">>> Unpacking ${x} to ${UNPACKTODIR}"
|
|
if [[ ${x} != */* ]]; then
|
|
x=${UNPACKFROMDIR}/${x}
|
|
elif [[ ${x:0:2} == ./* ]]; then
|
|
:
|
|
elif [[ -n ${PALUDIS_UNPACK_ANY_PATH} ]]; then
|
|
:
|
|
else
|
|
die "Invalid path given to unpack: ${x}"
|
|
fi
|
|
mkdir -p ${UNPACKTODIR}
|
|
cd ${UNPACKTODIR}
|
|
unpack_one "${x}"
|
|
done
|
|
|
|
if [[ -n "${PALUDIS_UNPACK_FIX_PERMISSIONS}" ]] ; then
|
|
find ${UNPACKTODIR} -mindepth 1 -maxdepth 1 ! -type l -print0 | xargs -0 -r chmod -fR a+rX,u+w,go-w
|
|
fi
|
|
|