source: common/libs/func_download_pkgs@ 30a444a

ablfs-more trunk
Last change on this file since 30a444a was 8c2b505, checked in by Pierre Labastie <pierre.labastie@…>, 2 years ago

Fix small bugs in func_download_pkgs

  • If MISSING_FILES.DMP is left from a preceding attempt, it may

generate a false warning a bout missing files even if they could
all be downloaded.

  • do not try to copy a modified file to SRC_ARCHIVE if it already

exists: it may belong to another user...

  • Property mode set to 100644
File size: 5.1 KB
Line 
1#!/bin/bash
2
3#----------------------------#
4get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
5#----------------------------#
6
7 # Test if the packages must be downloaded
8 [ ! "$GETPKG" = "y" ] && return
9
10 local saveIFS=$IFS
11 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM
12
13 WGETPARAM=""
14 if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
15 WGETPARAM+="--retry-connrefused"
16 fi
17 WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
18 WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
19
20 gs_wrt_message(){
21 echo "${RED}$1${OFF}"
22 echo "$1" >> MISSING_FILES.DMP
23 }
24 # Housekeeping
25 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
26 cd $BUILDDIR/sources
27
28 # Generate URLs file
29 create_urls
30
31 # Clean up leftovers from preceding attempts
32 >MISSING_FILES.DMP
33
34 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
35 for line in `cat urls.lst`; do
36 IFS=$saveIFS # Restore the system defaults
37
38 # Locations
39 URL1=`echo $line | cut -d" " -f2` # Preferred URL
40 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
41 FILE=`basename $URL1` # File name
42 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
43
44 # Validation pair
45 MD5="$BOOKMD5 $FILE"
46 HAVEMD5=1
47
48 set -e
49 # If the file exists in the archive copy it to the
50 # $BUILDDIR/sources dir. MD5SUM will be validated later.
51 if [ ! -z ${SRC_ARCHIVE} ] &&
52 [ -d ${SRC_ARCHIVE} ] &&
53 [ -f ${SRC_ARCHIVE}/$FILE ]; then
54 cp ${SRC_ARCHIVE}/$FILE .
55 echo "$FILE: -- copied from $SRC_ARCHIVE"
56 fromARCHIVE=1
57 else
58 fromARCHIVE=0
59 # If the file does not exist yet in /sources download a fresh one
60 if [ ! -f $FILE ] ; then
61 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
62 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
63 else
64 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
65 fi
66 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
67 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
68 continue
69 fi
70 else
71 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
72 fi
73 fi
74
75 # Deal with udev and bootscripts m5sum issue
76 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
77 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
78 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
79 [[ $BOOKMD5 = "CUSTOM-PATCH-MD5SUM" ]] && continue
80
81 # IF the md5sum does not match the existing files
82 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
83 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
84 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
85 # Remove the old file and download a new one
86 rm -fv $FILE
87 # Force storage in SRC_ARCHIVE
88 fromARCHIVE=0;
89 # Try to retrieve again the file. Servers in reverse order.
90 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
91 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
92 continue
93 fi
94 fi
95
96 # Validate the MD5SUM one last time
97 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
98 gs_wrt_message "$FILE does not match MD5SUMS value"
99 # Force generation of MD5SUM
100 HAVEMD5=0
101 fi
102
103 # Generate a fresh MD5SUM for this file
104 if [[ "$HAVEMD5" = "0" ]] ; then
105 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
106 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
107 fi
108
109 # Good or bad we write the original md5sum to a file
110 echo "$MD5" >> MD5SUMS
111
112 # Copy the freshly downloaded file
113 # to the source archive.
114 if [ ! -z ${SRC_ARCHIVE} ] &&
115 [ -d ${SRC_ARCHIVE} ] &&
116 [ -w ${SRC_ARCHIVE} ] &&
117 [ ! -f ${SRC_ARCHIVE}/$FILE ] &&
118 [ "$fromARCHIVE" = "0" ] ; then
119 echo "Storing file:<$FILE> in the package archive"
120 cp -f $FILE ${SRC_ARCHIVE}
121 fi
122
123 done
124
125 if [[ -s MISSING_FILES.DMP ]]; then
126 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"
127 # Do not allow the automatic execution of the Makefile.
128 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
129 RUNMAKE="n"
130 fi
131}
132
133#----------------------------#
134create_urls() { #
135#----------------------------#
136 cd $JHALFSDIR
137
138 echo -n "Creating URLs file... "
139 xsltproc --nonet --xinclude \
140 --stringparam server "$SERVER" \
141 --stringparam family lfs \
142 --stringparam pkgmngt "$PKGMNGT" \
143 --stringparam revision "$INITSYS" \
144 --output ../sources/urls.lst \
145 urls.xsl \
146 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
147 echo "OK"
148
149 cd $BUILDDIR/sources
150
151 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
152 add_CustomToolsURLS
153 fi
154
155}
156
Note: See TracBrowser for help on using the repository browser.