source: common/libs/func_download_pkgs@ 0d793a8

ablfs
Last change on this file since 0d793a8 was 2507cf7, checked in by Pierre Labastie <pierre@…>, 13 years ago

Major change for the inclusion of blfs-tool dependencies:

  • build them before custom tools
  • use instructions in the BLFS book instead of harcoded ones
  • use the dependency tracker of the tool itself (kind of bootstrap)
  • Property mode set to 100644
File size: 6.8 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 */check* | */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
43 [[ "$TEST" = "0" ]] && continue
44 ;;
45 */vim-*-lang* )
46 [[ "$VIMLANG" = "0" ]] && continue
47 ;;
48 esac
49
50 # Locations
51 URL1=`echo $line | cut -d" " -f2` # Preferred URL
52 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
53 FILE=`basename $URL1` # File name
54 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
55
56 # Validation pair
57 MD5="$BOOKMD5 $FILE"
58 HAVEMD5=1
59
60 set -e
61 # If the file exists in the archive copy it to the
62 # $BUILDDIR/sources dir. MD5SUM will be validated later.
63 if [ ! -z ${SRC_ARCHIVE} ] &&
64 [ -d ${SRC_ARCHIVE} ] &&
65 [ -f ${SRC_ARCHIVE}/$FILE ]; then
66 cp ${SRC_ARCHIVE}/$FILE .
67 echo "$FILE: -- copied from $SRC_ARCHIVE"
68 fromARCHIVE=1
69 else
70 fromARCHIVE=0
71 # If the file does not exist yet in /sources download a fresh one
72 if [ ! -f $FILE ] ; then
73 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
74 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
75 else
76 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
77 fi
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 else
83 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
84 fi
85 fi
86
87 # Deal with udev and bootscripts m5sum issue
88 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
89 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
90
91 # IF the md5sum does not match the existing files
92 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
93 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
94 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
95 # Remove the old file and download a new one
96 rm -fv $FILE
97 # Force storage in SRC_ARCHIVE
98 fromARCHIVE=0;
99 # Try to retrieve again the file. Servers in reverse order.
100 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
101 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
102 continue
103 fi
104 fi
105
106 # Validate the MD5SUM one last time
107 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
108 gs_wrt_message "$FILE does not match MD5SUMS value"
109 # Force generation of MD5SUM
110 HAVEMD5=0
111 fi
112
113 # Generate a fresh MD5SUM for this file
114 if [[ "$HAVEMD5" = "0" ]] ; then
115 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
116 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
117 fi
118
119 # Good or bad we write the original md5sum to a file
120 echo "$MD5" >> MD5SUMS
121
122 # Copy the freshly downloaded file
123 # to the source archive.
124 if [ ! -z ${SRC_ARCHIVE} ] &&
125 [ -d ${SRC_ARCHIVE} ] &&
126 [ -w ${SRC_ARCHIVE} ] &&
127 [ "$fromARCHIVE" = "0" ] ; then
128 echo "Storing file:<$FILE> in the package archive"
129 cp -f $FILE ${SRC_ARCHIVE}
130 fi
131
132 done
133
134 if [[ -s MISSING_FILES.DMP ]]; then
135 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"
136 # Do not allow the automatic execution of the Makefile.
137 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
138 RUNMAKE="n"
139 fi
140}
141
142#----------------------------#
143create_urls() { #
144#----------------------------#
145 cd $JHALFSDIR
146
147 case ${PROGNAME} in
148 clfs)
149 echo -n "Creating CLFS <${ARCH}> specific URLs file"
150 xsltproc --nonet --xinclude \
151 --stringparam server $SERVER \
152 --stringparam family clfs \
153 -o $BUILDDIR/sources/urls.lst urls.xsl \
154 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
155 echo " ...OK"
156 ;;
157 clfs2)
158 echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
159 xsltproc --nonet --xinclude \
160 --stringparam server $SERVER \
161 --stringparam family clfs \
162 -o $BUILDDIR/sources/urls.lst urls.xsl \
163 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
164 echo " ...OK"
165 ;;
166 clfs3)
167 echo -n "Creating CLFS3 <${ARCH}> specific URLs file"
168 xsltproc --nonet --xinclude \
169 --stringparam server $SERVER \
170 --stringparam family clfs \
171 -o $BUILDDIR/sources/urls.lst urls.xsl \
172 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
173 echo " ...OK"
174 ;;
175 hlfs)
176 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
177 xsltproc --nonet --xinclude \
178 --stringparam server $SERVER \
179 --stringparam family lfs \
180 --stringparam model $MODEL \
181 --stringparam kernel $KERNEL \
182 -o $BUILDDIR/sources/urls.lst urls.xsl \
183 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
184 echo " ...OK"
185 ;;
186 lfs)
187 echo -n "Creating LFS specific URLs file"
188 xsltproc --nonet --xinclude \
189 --stringparam server $SERVER \
190 --stringparam family lfs \
191 --stringparam pkgmngt $PKGMNGT \
192 -o ../sources/urls.lst urls.xsl \
193 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
194 echo " ...OK"
195 ;;
196 esac
197
198 cd $BUILDDIR/sources
199
200 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
201 add_CustomToolsURLS
202 fi
203
204}
205
Note: See TracBrowser for help on using the repository browser.