2006-11-11 20:06:46 +01:00
#!/bin/bash
#----------------------------#
get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
#----------------------------#
2022-04-01 10:18:15 +02:00
# Test if the packages must be downloaded
2022-06-14 18:55:36 +02:00
[ "$GETPKG" = y ] || return 0
2022-04-01 10:18:15 +02:00
2022-05-07 11:25:43 +02:00
local URL FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM MAYBEMORE
2010-03-12 04:32:25 +01:00
WGETPARAM=""
if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
WGETPARAM+="--retry-connrefused"
fi
WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
2006-11-11 20:06:46 +01:00
gs_wrt_message(){
echo "${RED}$1${OFF}"
echo "$1" >> MISSING_FILES.DMP
}
# Housekeeping
[[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
cd $BUILDDIR/sources
# Generate URLs file
create_urls
2022-04-01 10:18:15 +02:00
# Clean up leftovers from preceding attempts
>MISSING_FILES.DMP
2022-05-07 11:25:43 +02:00
# Normally, urls.lst contains lines with two fields:
# <package url> <book md5>, but
# if a custom patch has an md5, there is a third field
# on the line, due to the way add_CustomToolsURLS works.
cat urls.lst | while read URL BOOKMD5 MAYBEMORE; do
FILE=$(basename "$URL") # File name
2006-11-11 20:06:46 +01:00
# Validation pair
MD5="$BOOKMD5 $FILE"
HAVEMD5=1
set -e
2022-05-07 11:25:43 +02:00
# If the file exists in the archive, copy it to the
2006-11-11 20:06:46 +01:00
# $BUILDDIR/sources dir. MD5SUM will be validated later.
2022-05-07 11:25:43 +02:00
if [ -n "${SRC_ARCHIVE}" ] &&
[ -d "${SRC_ARCHIVE}" ] &&
[ -f "${SRC_ARCHIVE}/$FILE" ]; then
cp "${SRC_ARCHIVE}/$FILE" .
2006-11-11 20:06:46 +01:00
echo "$FILE: -- copied from $SRC_ARCHIVE"
fromARCHIVE=1
else
fromARCHIVE=0
2022-05-07 11:25:43 +02:00
# If the file does not exist yet in /sources, download a fresh one
if [ ! -f "$FILE" ] ; then
if [ -n "$SRC_ARCHIVE" ] ; then
echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} nor in ${BUILDDIR}/sources${OFF}"
2010-03-12 04:46:12 +01:00
else
2012-02-02 00:29:37 +01:00
echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
2010-03-12 04:46:12 +01:00
fi
2022-05-07 11:56:28 +02:00
if ! wget "$URL" $WGETPARAM; then
2022-05-07 11:25:43 +02:00
gs_wrt_message "$FILE not found on any server..SKIPPING"
2006-11-11 20:06:46 +01:00
continue
fi
2012-02-02 00:29:37 +01:00
else
echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
2006-11-11 20:06:46 +01:00
fi
fi
2022-05-07 11:25:43 +02:00
# Deal with bootscripts md5sum issue,
# or skip if it is a custom patch without md5
[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ] && continue
[ $BOOKMD5 = "CUSTOM-PATCH-MD5SUM" ] && continue
2008-08-26 16:16:37 +02:00
2022-05-07 11:25:43 +02:00
# IF the md5sum does not match
2006-11-11 20:06:46 +01:00
if ! echo "$MD5" | md5sum -c - >/dev/null ; then
2022-05-07 11:25:43 +02:00
[ "$fromARCHIVE" = 1 ] && echo "${BOLD}${YELLOW}MD5SUM did not match $SRC_ARCHIVE copy${OFF}"
[ "$fromARCHIVE" = 0 ] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
2006-11-11 20:06:46 +01:00
# Remove the old file and download a new one
2022-05-07 11:25:43 +02:00
rm -fv "$FILE"
2006-11-11 20:06:46 +01:00
# Force storage in SRC_ARCHIVE
fromARCHIVE=0;
2022-05-07 11:25:43 +02:00
# Try to retrieve again the file.
2022-05-07 11:56:28 +02:00
if ! wget "$URL" $WGETPARAM; then
2022-05-07 11:25:43 +02:00
gs_wrt_message "$FILE not found on the server... SKIPPING"
2006-11-11 20:06:46 +01:00
continue
fi
fi
# Validate the MD5SUM one last time
if ! echo "$MD5" | md5sum -c - >/dev/null ; then
gs_wrt_message "$FILE does not match MD5SUMS value"
# Force generation of MD5SUM
HAVEMD5=0
fi
# Generate a fresh MD5SUM for this file
2022-05-07 11:25:43 +02:00
if [ "$HAVEMD5" = "0" ] ; then
2006-11-11 20:06:46 +01:00
echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
fi
# Good or bad we write the original md5sum to a file
2012-02-07 23:30:26 +01:00
echo "$MD5" >> MD5SUMS
2006-11-11 20:06:46 +01:00
# Copy the freshly downloaded file
# to the source archive.
2022-05-07 11:25:43 +02:00
if [ -n "${SRC_ARCHIVE}" ] &&
[ -d "${SRC_ARCHIVE}" ] &&
[ -w "${SRC_ARCHIVE}" ] &&
[ ! -f "${SRC_ARCHIVE}/$FILE" ] &&
[ "$fromARCHIVE" = 0 ] ; then
2006-11-11 20:06:46 +01:00
echo "Storing file:<$FILE> in the package archive"
2022-05-07 11:25:43 +02:00
cp -f "$FILE" "${SRC_ARCHIVE}"
2006-11-11 20:06:46 +01:00
fi
done
if [[ -s MISSING_FILES.DMP ]]; then
echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have bad MD5SUMS.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
# Do not allow the automatic execution of the Makefile.
echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
RUNMAKE="n"
fi
}
#----------------------------#
create_urls() { #
#----------------------------#
cd $JHALFSDIR
2022-03-30 17:45:35 +02:00
echo -n "Creating URLs file... "
xsltproc --nonet --xinclude \
--stringparam pkgmngt "$PKGMNGT" \
--stringparam revision "$INITSYS" \
--output ../sources/urls.lst \
urls.xsl \
$BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
echo "OK"
2006-11-11 20:06:46 +01:00
cd $BUILDDIR/sources
if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
add_CustomToolsURLS
fi
}