2014-03-05 10:02:37 +00:00
|
|
|
# This hook downloads the distfiles specified in a template by
|
|
|
|
# the $distfiles variable and then verifies its sha256 checksum comparing
|
|
|
|
# its value with the one stored in the $checksum variable.
|
|
|
|
|
2015-07-03 16:30:34 +00:00
|
|
|
# Get the checksum for $curfile at index $dfcount
|
|
|
|
get_cksum() {
|
|
|
|
local curfile="$1" dfcount="$2" ckcount cksum i
|
2014-03-05 10:02:37 +00:00
|
|
|
|
2014-03-12 14:23:08 +00:00
|
|
|
ckcount=0
|
2015-07-03 16:30:34 +00:00
|
|
|
cksum=0
|
2014-03-12 14:23:08 +00:00
|
|
|
for i in ${checksum}; do
|
|
|
|
if [ $dfcount -eq $ckcount -a -n "$i" ]; then
|
|
|
|
cksum=$i
|
|
|
|
fi
|
2015-07-03 16:30:34 +00:00
|
|
|
ckcount=$((ckcount + 1))
|
2014-03-12 14:23:08 +00:00
|
|
|
done
|
2015-07-03 16:30:34 +00:00
|
|
|
if [ -z "$cksum" ]; then
|
2014-03-12 14:23:08 +00:00
|
|
|
msg_error "$pkgver: cannot find checksum for $curfile.\n"
|
|
|
|
fi
|
2015-07-03 16:30:34 +00:00
|
|
|
echo "$cksum"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify the checksum for $curfile stored at $distfile and index $dfcount
|
|
|
|
verify_cksum() {
|
|
|
|
local curfile="$1" distfile="$2" dfcount="$3" filesum cksum
|
2014-03-05 10:02:37 +00:00
|
|
|
|
2015-07-03 16:30:34 +00:00
|
|
|
cksum=$(get_cksum $curfile $dfcount)
|
2014-03-12 14:23:08 +00:00
|
|
|
msg_normal "$pkgver: verifying checksum for distfile '$curfile'... "
|
2014-03-05 10:02:37 +00:00
|
|
|
filesum=$(${XBPS_DIGEST_CMD} $distfile)
|
2014-03-12 14:23:08 +00:00
|
|
|
if [ "$cksum" != "$filesum" ]; then
|
2014-03-05 10:02:37 +00:00
|
|
|
echo
|
2014-03-12 14:23:08 +00:00
|
|
|
msg_red "SHA256 mismatch for '$curfile:'\n$filesum\n"
|
|
|
|
errors=$(($errors + 1))
|
2014-03-05 10:02:37 +00:00
|
|
|
else
|
2015-07-06 19:34:52 +00:00
|
|
|
if [ ! -f "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}" ]; then
|
2015-07-03 16:30:34 +00:00
|
|
|
mkdir -p "$XBPS_SRCDISTDIR/by_sha256"
|
|
|
|
ln -f "$distfile" "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}"
|
|
|
|
fi
|
2014-03-05 10:02:37 +00:00
|
|
|
msg_normal_append "OK.\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-03 16:30:34 +00:00
|
|
|
# Link an existing cksum $distfile for $curfile at index $dfcount
|
|
|
|
link_cksum() {
|
|
|
|
local curfile="$1" distfile="$2" dfcount="$3" filesum cksum
|
|
|
|
|
|
|
|
cksum=$(get_cksum $curfile $dfcount)
|
|
|
|
if [ -n "$cksum" -a -f "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}" ]; then
|
|
|
|
ln -f "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}" "$distfile"
|
|
|
|
msg_normal "$pkgver: using known distfile $curfile.\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-03-05 10:02:37 +00:00
|
|
|
hook() {
|
|
|
|
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
|
2014-03-12 14:23:08 +00:00
|
|
|
local dfcount=0 errors=0
|
2014-03-05 10:02:37 +00:00
|
|
|
|
|
|
|
if [ ! -d "$srcdir" ]; then
|
|
|
|
mkdir -p -m775 "$srcdir"
|
|
|
|
chgrp $(id -g) "$srcdir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $srcdir || msg_error "$pkgver: cannot change dir to $srcdir!\n"
|
|
|
|
|
2014-03-05 12:58:46 +00:00
|
|
|
# Disable trap on ERR; the code is smart enough to report errors and abort.
|
|
|
|
trap - ERR
|
|
|
|
|
2014-03-05 10:02:37 +00:00
|
|
|
for f in ${distfiles}; do
|
2014-03-12 12:47:57 +00:00
|
|
|
curfile=$(basename "${f#*>}")
|
2014-03-05 10:02:37 +00:00
|
|
|
distfile="$srcdir/$curfile"
|
2014-03-12 14:23:08 +00:00
|
|
|
|
|
|
|
# If file lock cannot be acquired wait until it's available.
|
2014-03-05 10:02:37 +00:00
|
|
|
while true; do
|
|
|
|
flock -w 1 ${distfile}.part true
|
2014-03-12 14:23:08 +00:00
|
|
|
[ $? -eq 0 ] && break
|
|
|
|
msg_warn "$pkgver: ${curfile} is being already downloaded, waiting for 1s ...\n"
|
2014-03-05 10:02:37 +00:00
|
|
|
done
|
2015-07-03 16:30:34 +00:00
|
|
|
# If distfile does not exist, try to link to it.
|
|
|
|
if [ ! -f "$distfile" ]; then
|
|
|
|
link_cksum $curfile $distfile $dfcount
|
|
|
|
fi
|
|
|
|
# If distfile does not exist, download it.
|
2014-03-12 14:23:08 +00:00
|
|
|
if [ ! -f "$distfile" ]; then
|
|
|
|
msg_normal "$pkgver: fetching distfile '$curfile'...\n"
|
2014-03-12 14:47:49 +00:00
|
|
|
flock "${distfile}.part" $XBPS_FETCH_CMD "$f"
|
2014-03-12 14:23:08 +00:00
|
|
|
if [ ! -f "$distfile" ]; then
|
|
|
|
msg_error "$pkgver: failed to fetch $curfile.\n"
|
2014-03-07 10:22:51 +00:00
|
|
|
fi
|
2014-03-05 10:02:37 +00:00
|
|
|
fi
|
2014-03-12 14:23:08 +00:00
|
|
|
# distfile downloaded, verify sha256 hash.
|
|
|
|
flock -n ${distfile}.part rm -f ${distfile}.part
|
|
|
|
verify_cksum $curfile $distfile $dfcount
|
2014-03-05 10:02:37 +00:00
|
|
|
dfcount=$(($dfcount + 1))
|
|
|
|
done
|
2014-03-07 10:12:52 +00:00
|
|
|
|
2014-03-07 10:22:51 +00:00
|
|
|
if [ $errors -gt 0 ]; then
|
2014-03-07 10:12:52 +00:00
|
|
|
msg_error "$pkgver: couldn't verify distfiles, exiting...\n"
|
|
|
|
fi
|
2014-03-05 10:02:37 +00:00
|
|
|
}
|