source: common/libs/func_download_pkgs@ e576789

2.4 ablfs-more legacy new_features trunk
Last change on this file since e576789 was e576789, checked in by Pierre Labastie <pierre@…>, 11 years ago

Merge ablfs branch. Normally, jhalfs should not perform differently
for building LFS

  • Property mode set to 100644
File size: 6.1 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 */tree* | */gcc-testsuite* ) #unneeded now?
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 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
91
92 # IF the md5sum does not match the existing files
93 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
94 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
95 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
96 # Remove the old file and download a new one
97 rm -fv $FILE
98 # Force storage in SRC_ARCHIVE
99 fromARCHIVE=0;
100 # Try to retrieve again the file. Servers in reverse order.
101 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
102 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
103 continue
104 fi
105 fi
106
107 # Validate the MD5SUM one last time
108 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
109 gs_wrt_message "$FILE does not match MD5SUMS value"
110 # Force generation of MD5SUM
111 HAVEMD5=0
112 fi
113
114 # Generate a fresh MD5SUM for this file
115 if [[ "$HAVEMD5" = "0" ]] ; then
116 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
117 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
118 fi
119
120 # Good or bad we write the original md5sum to a file
121 echo "$MD5" >> MD5SUMS
122
123 # Copy the freshly downloaded file
124 # to the source archive.
125 if [ ! -z ${SRC_ARCHIVE} ] &&
126 [ -d ${SRC_ARCHIVE} ] &&
127 [ -w ${SRC_ARCHIVE} ] &&
128 [ "$fromARCHIVE" = "0" ] ; then
129 echo "Storing file:<$FILE> in the package archive"
130 cp -f $FILE ${SRC_ARCHIVE}
131 fi
132
133 done
134
135 if [[ -s MISSING_FILES.DMP ]]; then
136 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"
137 # Do not allow the automatic execution of the Makefile.
138 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
139 RUNMAKE="n"
140 fi
141}
142
143#----------------------------#
144create_urls() { #
145#----------------------------#
146 cd $JHALFSDIR
147
148 case ${PROGNAME} in
149 clfs*)
150 echo -n "Creating CLFS <${ARCH}> specific URLs file"
151 xsltproc --nonet --xinclude \
152 --stringparam server $SERVER \
153 --stringparam family clfs \
154 -o $BUILDDIR/sources/urls.lst urls.xsl \
155 $BOOK/BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
156 echo " ...OK"
157 ;;
158 hlfs)
159 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
160 xsltproc --nonet --xinclude \
161 --stringparam server $SERVER \
162 --stringparam family lfs \
163 --stringparam model $MODEL \
164 --stringparam kernel $KERNEL \
165 -o $BUILDDIR/sources/urls.lst urls.xsl \
166 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
167 echo " ...OK"
168 ;;
169 lfs)
170 echo -n "Creating LFS specific URLs file"
171 xsltproc --nonet --xinclude \
172 --stringparam server $SERVER \
173 --stringparam family lfs \
174 --stringparam pkgmngt $PKGMNGT \
175 -o ../sources/urls.lst urls.xsl \
176 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
177 echo " ...OK"
178 ;;
179 esac
180
181 cd $BUILDDIR/sources
182
183 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
184 add_CustomToolsURLS
185 fi
186
187}
188
Note: See TracBrowser for help on using the repository browser.