2009-10-18 11:17:26 +02:00
|
|
|
#-
|
2010-01-09 15:49:36 +01:00
|
|
|
# Copyright (c) 2008-2010 Juan Romero Pardines.
|
2009-10-18 11:17:26 +02:00
|
|
|
# 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.
|
|
|
|
#-
|
|
|
|
|
|
|
|
#
|
|
|
|
# Verifies that file's checksum downloaded matches what it's specified
|
|
|
|
# in template file.
|
|
|
|
#
|
|
|
|
verify_sha256_cksum()
|
|
|
|
{
|
|
|
|
local file="$1"
|
|
|
|
local origsum="$2"
|
|
|
|
|
|
|
|
[ -z "$file" -o -z "$cksum" ] && return 1
|
|
|
|
|
2010-12-20 07:06:48 +01:00
|
|
|
msg_normal "'$pkgname-$lver': verifying checksum for distfile '$file'... "
|
2009-10-30 22:14:09 +01:00
|
|
|
filesum=$(${XBPS_DIGEST_CMD} $XBPS_SRCDISTDIR/$file)
|
2009-10-18 11:17:26 +02:00
|
|
|
if [ "$origsum" != "$filesum" ]; then
|
2010-12-20 07:06:48 +01:00
|
|
|
echo
|
2011-06-26 22:38:17 +02:00
|
|
|
msg_error "SHA256 mismatch for '$file:'\n$filesum\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
2010-12-20 00:22:12 +01:00
|
|
|
msg_normal_append "OK.\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Downloads the distfiles and verifies checksum for all them.
|
|
|
|
#
|
|
|
|
fetch_distfiles()
|
|
|
|
{
|
2010-05-14 00:07:47 +02:00
|
|
|
local pkg="$1" upcksum="$2" dfiles localurl dfcount=0 ckcount=0 f
|
2009-10-18 11:17:26 +02:00
|
|
|
|
2010-05-14 00:07:47 +02:00
|
|
|
[ -z $pkgname ] && return 1
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# There's nothing of interest if we are a meta template.
|
|
|
|
#
|
|
|
|
[ "$build_style" = "meta-template" ] && return 0
|
|
|
|
|
2010-04-23 18:45:47 +02:00
|
|
|
[ -f "$XBPS_FETCH_DONE" ] && return 0
|
|
|
|
|
2009-10-18 11:17:26 +02:00
|
|
|
#
|
|
|
|
# If nofetch is set in a build template, skip this phase
|
|
|
|
# entirely and run the do_fetch() function.
|
|
|
|
#
|
2010-05-14 00:07:47 +02:00
|
|
|
if [ -n "$revision" ]; then
|
|
|
|
lver="${version}_${revision}"
|
|
|
|
else
|
|
|
|
lver="${version}"
|
|
|
|
fi
|
|
|
|
|
2010-05-14 02:27:38 +02:00
|
|
|
if [ -n "$nofetch" ]; then
|
2011-07-04 21:27:56 +02:00
|
|
|
cd ${XBPS_BUILDDIR}
|
|
|
|
[ -n "$build_wrksrc" ] && mkdir -p "$wrksrc"
|
|
|
|
run_func do_fetch
|
|
|
|
touch -f $XBPS_FETCH_DONE
|
|
|
|
return 0
|
2010-05-14 02:27:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd $XBPS_SRCDISTDIR || return 1
|
2009-10-18 11:17:26 +02:00
|
|
|
for f in ${distfiles}; do
|
|
|
|
curfile=$(basename $f)
|
|
|
|
if [ -f "$XBPS_SRCDISTDIR/$curfile" ]; then
|
|
|
|
for i in ${checksum}; do
|
|
|
|
if [ $dfcount -eq $ckcount -a -n $i ]; then
|
|
|
|
cksum=$i
|
|
|
|
found=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
ckcount=$(($ckcount + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z $found ]; then
|
2010-12-20 00:22:12 +01:00
|
|
|
msg_error "cannot find checksum for $curfile.\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
verify_sha256_cksum $curfile $cksum
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
unset cksum found
|
|
|
|
ckcount=0
|
|
|
|
dfcount=$(($dfcount + 1))
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-12-20 07:06:48 +01:00
|
|
|
msg_normal "'$pkgname-$lver': fetching distfile '$curfile'...\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
if [ -n "$distfiles" ]; then
|
|
|
|
localurl="$f"
|
|
|
|
else
|
|
|
|
localurl="$url/$curfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
$XBPS_FETCH_CMD $localurl
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
unset localurl
|
|
|
|
if [ ! -f $XBPS_SRCDISTDIR/$curfile ]; then
|
2010-12-20 00:22:12 +01:00
|
|
|
msg_error "couldn't fetch $curfile.\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
else
|
2010-12-20 00:22:12 +01:00
|
|
|
msg_error "there was an error fetching $curfile.\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
unset localurl
|
|
|
|
#
|
|
|
|
# XXX duplicate code.
|
|
|
|
#
|
|
|
|
for i in ${checksum}; do
|
|
|
|
if [ $dfcount -eq $ckcount -a -n $i ]; then
|
|
|
|
cksum=$i
|
|
|
|
found=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
ckcount=$(($ckcount + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z $found ]; then
|
2010-12-20 00:22:12 +01:00
|
|
|
msg_error "cannot find checksum for $curfile.\n"
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
verify_sha256_cksum $curfile $cksum
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
unset cksum found
|
|
|
|
ckcount=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
dfcount=$(($dfcount + 1))
|
|
|
|
done
|
|
|
|
|
2010-05-14 00:07:47 +02:00
|
|
|
unset lver cksum found
|
2009-10-18 11:17:26 +02:00
|
|
|
}
|