source: common/libs/func_download_pkgs@ 8825e69

ablfs-more trunk
Last change on this file since 8825e69 was 8825e69, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Get completely rid of PROGNAME

There is only one PROGNAME: lfs, so no need for a variable.

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