source: common/libs/func_download_pkgs@ de63126

2.3 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since de63126 was de63126, checked in by Thomas Pegg <thomasp@…>, 15 years ago

Add configuration options for retry on connection refused, number of times to attemp to download a file, and timeout for wget invocation. Thanks to Tim Sarbin for the patch, slightly modified by me to accomodate a second set of wget calls.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5
6#----------------------------#
7get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
8#----------------------------#
9 local saveIFS=$IFS
10 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM
11
12 WGETPARAM=""
13 if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
14 WGETPARAM+="--retry-connrefused"
15 fi
16 WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
17 WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
18
19 # Test if the packages must be downloaded
20 [ ! "$GETPKG" = "y" ] && return
21
22 gs_wrt_message(){
23 echo "${RED}$1${OFF}"
24 echo "$1" >> MISSING_FILES.DMP
25 }
26 # Housekeeping
27 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
28 cd $BUILDDIR/sources
29 [[ -f MD5SUMS ]] && rm MD5SUMS
30 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
31 [[ -f urls.lst ]] && rm urls.lst
32
33 # Generate URLs file
34 create_urls
35
36 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
37 for line in `cat urls.lst`; do
38 IFS=$saveIFS # Restore the system defaults
39
40 # Skip some packages if they aren't needed
41 case $line in
42 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
43 [[ "$TEST" = "0" ]] && continue
44 ;;
45 */vim-*-lang* )
46 [[ "$VIMLANG" = "0" ]] && continue
47 ;;
48 *linux/linux-* )
49 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
50 [[ "$GETKERNEL" = "n" ]] && continue
51 ;;
52 esac
53
54 # Locations
55 URL1=`echo $line | cut -d" " -f2` # Preferred URL
56 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
57 FILE=`basename $URL1` # File name
58 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
59
60 # Validation pair
61 MD5="$BOOKMD5 $FILE"
62 HAVEMD5=1
63
64 set -e
65 # If the file exists in the archive copy it to the
66 # $BUILDDIR/sources dir. MD5SUM will be validated later.
67 if [ ! -z ${SRC_ARCHIVE} ] &&
68 [ -d ${SRC_ARCHIVE} ] &&
69 [ -f ${SRC_ARCHIVE}/$FILE ]; then
70 cp ${SRC_ARCHIVE}/$FILE .
71 echo "$FILE: -- copied from $SRC_ARCHIVE"
72 fromARCHIVE=1
73 else
74 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
75 fromARCHIVE=0
76 # If the file does not exist yet in /sources download a fresh one
77 if [ ! -f $FILE ] ; then
78 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
79 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
80 continue
81 fi
82 fi
83 fi
84
85 # Deal with udev and bootscripts m5sum issue
86 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
87 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
88
89 # IF the md5sum does not match the existing files
90 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
91 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
92 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
93 # Remove the old file and download a new one
94 rm -fv $FILE
95 # Force storage in SRC_ARCHIVE
96 fromARCHIVE=0;
97 # Try to retrieve again the file. Servers in reverse order.
98 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
99 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
100 continue
101 fi
102 fi
103
104 # Validate the MD5SUM one last time
105 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
106 gs_wrt_message "$FILE does not match MD5SUMS value"
107 # Force generation of MD5SUM
108 HAVEMD5=0
109 fi
110
111 # Generate a fresh MD5SUM for this file
112 if [[ "$HAVEMD5" = "0" ]] ; then
113 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
114 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
115 fi
116
117 # Good or bad we write the original md5sum to a file
118 echo "$MD5" >> MD5SUMS
119
120 # Copy the freshly downloaded file
121 # to the source archive.
122 if [ ! -z ${SRC_ARCHIVE} ] &&
123 [ -d ${SRC_ARCHIVE} ] &&
124 [ -w ${SRC_ARCHIVE} ] &&
125 [ "$fromARCHIVE" = "0" ] ; then
126 echo "Storing file:<$FILE> in the package archive"
127 cp -f $FILE ${SRC_ARCHIVE}
128 fi
129
130 done
131
132 if [[ -s MISSING_FILES.DMP ]]; then
133 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"
134 # Do not allow the automatic execution of the Makefile.
135 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
136 RUNMAKE="n"
137 fi
138}
139
140#----------------------------#
141create_urls() { #
142#----------------------------#
143 cd $JHALFSDIR
144
145 case ${PROGNAME} in
146 clfs)
147 echo -n "Creating CLFS <${ARCH}> specific URLs file"
148 xsltproc --nonet --xinclude \
149 --stringparam server $SERVER \
150 --stringparam family clfs \
151 -o $BUILDDIR/sources/urls.lst urls.xsl \
152 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
153 echo " ...OK"
154 ;;
155 clfs2)
156 echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
157 xsltproc --nonet --xinclude \
158 --stringparam server $SERVER \
159 --stringparam family clfs \
160 -o $BUILDDIR/sources/urls.lst urls.xsl \
161 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
162 echo " ...OK"
163 ;;
164 clfs3)
165 echo -n "Creating CLFS3 <${ARCH}> specific URLs file"
166 xsltproc --nonet --xinclude \
167 --stringparam server $SERVER \
168 --stringparam family clfs \
169 -o $BUILDDIR/sources/urls.lst urls.xsl \
170 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
171 echo " ...OK"
172 ;;
173 hlfs)
174 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
175 xsltproc --nonet --xinclude \
176 --stringparam server $SERVER \
177 --stringparam family lfs \
178 --stringparam model $MODEL \
179 --stringparam kernel $KERNEL \
180 -o $BUILDDIR/sources/urls.lst urls.xsl \
181 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
182 echo " ...OK"
183 ;;
184 lfs)
185 echo -n "Creating LFS specific URLs file"
186 xsltproc --nonet --xinclude \
187 --stringparam server $SERVER \
188 --stringparam family lfs \
189 -o ../sources/urls.lst urls.xsl \
190 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
191 echo " ...OK"
192 ;;
193 esac
194
195 cd $BUILDDIR/sources
196
197 if [[ "${BLFS_TOOL}" = "y" ]]; then
198 add_blfs_deps_urls
199 fi
200
201 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
202 add_CustomToolsURLS
203 fi
204
205}
206
Note: See TracBrowser for help on using the repository browser.