2008-12-13 04:23:16 +00:00
|
|
|
#-
|
|
|
|
# Copyright (c) 2008 Juan Romero Pardines.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
|
|
|
#
|
|
|
|
# Extracts contents of distfiles specified in a template into
|
|
|
|
# the $wrksrc directory.
|
|
|
|
#
|
|
|
|
extract_distfiles()
|
|
|
|
{
|
2009-03-28 07:27:29 +00:00
|
|
|
local count=0 pkg="$1"
|
|
|
|
local curfile cursufx lwrksrc ltar_cmd f lver
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
[ -f $XBPS_EXTRACT_DONE ] && return 0
|
2008-12-18 07:17:46 +00:00
|
|
|
[ -z "$in_chroot" -a ! -w $XBPS_BUILDDIR ] && \
|
2008-12-16 22:44:35 +00:00
|
|
|
msg_error "can't extract distfile(s) (permission denied)"
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# If we are being called via the target, just extract and return.
|
|
|
|
#
|
|
|
|
[ -n "$pkg" -a -z "$pkgname" ] && return 1
|
|
|
|
|
|
|
|
#
|
|
|
|
# There's nothing of interest if we are a meta template.
|
|
|
|
#
|
|
|
|
[ "$build_style" = "meta-template" ] && return 0
|
|
|
|
|
2009-03-28 07:27:29 +00:00
|
|
|
if [ -n "$revision" ]; then
|
|
|
|
lver="${version}_${revision}"
|
|
|
|
else
|
|
|
|
lver="${version}"
|
|
|
|
fi
|
2009-03-21 04:28:39 +00:00
|
|
|
#
|
|
|
|
# If noextract is set, do a "fake extraction".
|
|
|
|
#
|
2009-03-29 07:46:55 +00:00
|
|
|
if [ -z "$distfiles" -o -n "$noextract" ]; then
|
2009-03-21 04:28:39 +00:00
|
|
|
mkdir $wrksrc
|
|
|
|
touch -f $XBPS_EXTRACT_DONE
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2008-12-13 04:23:16 +00:00
|
|
|
for f in ${distfiles}; do
|
|
|
|
count=$(($count + 1))
|
|
|
|
done
|
|
|
|
|
2008-12-27 03:21:38 +00:00
|
|
|
if [ "$count" -gt 1 ]; then
|
2008-12-13 04:23:16 +00:00
|
|
|
if [ -z "$wrksrc" ]; then
|
|
|
|
msg_error "\$wrksrc must be defined with multiple distfiles."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
mkdir $wrksrc
|
|
|
|
fi
|
|
|
|
|
2009-03-28 07:27:29 +00:00
|
|
|
msg_normal "Extracting $pkgname-$lver distfile(s)."
|
2008-12-13 04:23:16 +00:00
|
|
|
|
|
|
|
if [ -n "$tar_override_cmd" ]; then
|
|
|
|
ltar_cmd="$tar_override_cmd"
|
|
|
|
else
|
|
|
|
ltar_cmd="tar"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for f in ${distfiles}; do
|
2008-12-15 23:04:23 +00:00
|
|
|
curfile=$(basename $f)
|
|
|
|
|
2009-03-29 10:55:33 +00:00
|
|
|
if $(echo $f|grep -q '.tar.lzma'); then
|
|
|
|
cursufx=".tar.lzma"
|
|
|
|
elif $(echo $f|grep -q '.tar.bz2'); then
|
2008-12-13 04:23:16 +00:00
|
|
|
cursufx=".tar.bz2"
|
|
|
|
elif $(echo $f|grep -q '.tbz'); then
|
|
|
|
cursufx=".tbz"
|
|
|
|
elif $(echo $f|grep -q '.tar.gz'); then
|
|
|
|
cursufx=".tar.gz"
|
2009-03-14 00:21:27 +00:00
|
|
|
elif $(echo $f|grep -q '.tgz'); then
|
|
|
|
cursufx=".tgz"
|
2008-12-15 23:04:23 +00:00
|
|
|
elif $(echo $f|grep -q '.gz'); then
|
|
|
|
cursufx=".gz"
|
|
|
|
elif $(echo $f|grep -q '.bz2'); then
|
|
|
|
cursufx=".bz2"
|
2008-12-13 04:23:16 +00:00
|
|
|
elif $(echo $f|grep -q '.tar'); then
|
|
|
|
cursufx=".tar"
|
|
|
|
elif $(echo $f|grep -q '.zip'); then
|
|
|
|
cursufx=".zip"
|
|
|
|
else
|
2008-12-15 23:04:23 +00:00
|
|
|
msg_error "unknown distfile suffix for $curfile."
|
2008-12-13 04:23:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ $count -gt 1 ]; then
|
2008-12-16 01:17:32 +00:00
|
|
|
lwrksrc="$wrksrc"
|
2008-12-13 04:23:16 +00:00
|
|
|
else
|
|
|
|
lwrksrc="$XBPS_BUILDDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case ${cursufx} in
|
2009-03-29 10:55:33 +00:00
|
|
|
.tar.lzma)
|
|
|
|
if [ -x $XBPS_MASTERDIR/usr/bin/lzma ]; then
|
|
|
|
cp -f $XBPS_SRCDISTDIR/$curfile $lwrksrc
|
|
|
|
cd $lwrksrc && \
|
|
|
|
$XBPS_MASTERDIR/usr/bin/lzma \
|
|
|
|
-d $curfile && \
|
|
|
|
$ltar_cmd xf ${curfile%.lzma} \
|
|
|
|
-C $lwrksrc && \
|
|
|
|
rm -f ${curfile%.lzma}
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "extracting $curfile into $lwrksrc."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
msg_error "cannot find lzma bin for extraction."
|
|
|
|
fi
|
|
|
|
;;
|
2008-12-13 04:23:16 +00:00
|
|
|
.tar.bz2|.tbz)
|
|
|
|
$ltar_cmd xfj $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "extracting $curfile into $lwrksrc."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
.tar.gz|.tgz)
|
|
|
|
$ltar_cmd xfz $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "extracting $curfile into $lwrksrc."
|
|
|
|
fi
|
|
|
|
;;
|
2008-12-15 23:04:23 +00:00
|
|
|
.gz|.bz2)
|
2008-12-16 01:17:32 +00:00
|
|
|
cp -f $XBPS_SRCDISTDIR/$curfile $lwrksrc
|
2008-12-15 23:04:23 +00:00
|
|
|
if [ "$cursufx" = ".gz" ]; then
|
2008-12-16 01:17:32 +00:00
|
|
|
cd $lwrksrc && gunzip $curfile
|
2008-12-15 23:04:23 +00:00
|
|
|
else
|
2008-12-16 01:17:32 +00:00
|
|
|
cd $lwrksrc && bunzip2 $curfile
|
2008-12-15 23:04:23 +00:00
|
|
|
fi
|
|
|
|
;;
|
2008-12-13 04:23:16 +00:00
|
|
|
.tar)
|
|
|
|
$ltar_cmd xf $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "extracting $curfile into $lwrksrc."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
.zip)
|
|
|
|
if [ -x $XBPS_MASTERDIR/usr/bin/unzip ]; then
|
|
|
|
$XBPS_MASTERDIR/usr/bin/unzip \
|
|
|
|
-q -x $XBPS_SRCDISTDIR/$curfile -d $lwrksrc
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "extracting $curfile into $lwrksrc."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
msg_error "cannot find unzip bin for extraction"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
msg_error "cannot guess $curfile extract suffix. ($cursufx)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
touch -f $XBPS_EXTRACT_DONE
|
|
|
|
}
|