1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 |
|
---|
6 | #----------------------------#
|
---|
7 | get_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 | fromARCHIVE=0
|
---|
75 | # If the file does not exist yet in /sources download a fresh one
|
---|
76 | if [ ! -f $FILE ] ; then
|
---|
77 | if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
|
---|
78 | echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or /sources${OFF}"
|
---|
79 | else
|
---|
80 | echo "${BOLD}${YELLOW}$FILE: not found in /sources${OFF}"
|
---|
81 | fi
|
---|
82 | if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
|
---|
83 | gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
|
---|
84 | continue
|
---|
85 | fi
|
---|
86 | else
|
---|
87 | echo "${BOLD}${YELLOW}$FILE: using cached file in /sources${OFF}"
|
---|
88 | fi
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # Deal with udev and bootscripts m5sum issue
|
---|
92 | [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
|
---|
93 | [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
|
---|
94 |
|
---|
95 | # IF the md5sum does not match the existing files
|
---|
96 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
97 | [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
|
---|
98 | [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
|
---|
99 | # Remove the old file and download a new one
|
---|
100 | rm -fv $FILE
|
---|
101 | # Force storage in SRC_ARCHIVE
|
---|
102 | fromARCHIVE=0;
|
---|
103 | # Try to retrieve again the file. Servers in reverse order.
|
---|
104 | if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
|
---|
105 | gs_wrt_message "$FILE not found on the servers.. SKIPPING"
|
---|
106 | continue
|
---|
107 | fi
|
---|
108 | fi
|
---|
109 |
|
---|
110 | # Validate the MD5SUM one last time
|
---|
111 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
112 | gs_wrt_message "$FILE does not match MD5SUMS value"
|
---|
113 | # Force generation of MD5SUM
|
---|
114 | HAVEMD5=0
|
---|
115 | fi
|
---|
116 |
|
---|
117 | # Generate a fresh MD5SUM for this file
|
---|
118 | if [[ "$HAVEMD5" = "0" ]] ; then
|
---|
119 | echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
|
---|
120 | echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
|
---|
121 | fi
|
---|
122 |
|
---|
123 | # Good or bad we write the original md5sum to a file
|
---|
124 | echo "$MD5" >> MD5SUMS
|
---|
125 |
|
---|
126 | # Copy the freshly downloaded file
|
---|
127 | # to the source archive.
|
---|
128 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
129 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
130 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
131 | [ "$fromARCHIVE" = "0" ] ; then
|
---|
132 | echo "Storing file:<$FILE> in the package archive"
|
---|
133 | cp -f $FILE ${SRC_ARCHIVE}
|
---|
134 | fi
|
---|
135 |
|
---|
136 | done
|
---|
137 |
|
---|
138 | if [[ -s MISSING_FILES.DMP ]]; then
|
---|
139 | 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"
|
---|
140 | # Do not allow the automatic execution of the Makefile.
|
---|
141 | echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
|
---|
142 | RUNMAKE="n"
|
---|
143 | fi
|
---|
144 | }
|
---|
145 |
|
---|
146 | #----------------------------#
|
---|
147 | create_urls() { #
|
---|
148 | #----------------------------#
|
---|
149 | cd $JHALFSDIR
|
---|
150 |
|
---|
151 | case ${PROGNAME} in
|
---|
152 | clfs)
|
---|
153 | echo -n "Creating CLFS <${ARCH}> specific URLs file"
|
---|
154 | xsltproc --nonet --xinclude \
|
---|
155 | --stringparam server $SERVER \
|
---|
156 | --stringparam family clfs \
|
---|
157 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
158 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
159 | echo " ...OK"
|
---|
160 | ;;
|
---|
161 | clfs2)
|
---|
162 | echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
|
---|
163 | xsltproc --nonet --xinclude \
|
---|
164 | --stringparam server $SERVER \
|
---|
165 | --stringparam family clfs \
|
---|
166 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
167 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
168 | echo " ...OK"
|
---|
169 | ;;
|
---|
170 | clfs3)
|
---|
171 | echo -n "Creating CLFS3 <${ARCH}> specific URLs file"
|
---|
172 | xsltproc --nonet --xinclude \
|
---|
173 | --stringparam server $SERVER \
|
---|
174 | --stringparam family clfs \
|
---|
175 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
176 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
177 | echo " ...OK"
|
---|
178 | ;;
|
---|
179 | hlfs)
|
---|
180 | echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
|
---|
181 | xsltproc --nonet --xinclude \
|
---|
182 | --stringparam server $SERVER \
|
---|
183 | --stringparam family lfs \
|
---|
184 | --stringparam model $MODEL \
|
---|
185 | --stringparam kernel $KERNEL \
|
---|
186 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
187 | $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
|
---|
188 | echo " ...OK"
|
---|
189 | ;;
|
---|
190 | lfs)
|
---|
191 | echo -n "Creating LFS specific URLs file"
|
---|
192 | xsltproc --nonet --xinclude \
|
---|
193 | --stringparam server $SERVER \
|
---|
194 | --stringparam family lfs \
|
---|
195 | -o ../sources/urls.lst urls.xsl \
|
---|
196 | $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
|
---|
197 | echo " ...OK"
|
---|
198 | ;;
|
---|
199 | esac
|
---|
200 |
|
---|
201 | cd $BUILDDIR/sources
|
---|
202 |
|
---|
203 | if [[ "${BLFS_TOOL}" = "y" ]]; then
|
---|
204 | add_blfs_deps_urls
|
---|
205 | fi
|
---|
206 |
|
---|
207 | if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
|
---|
208 | add_CustomToolsURLS
|
---|
209 | fi
|
---|
210 |
|
---|
211 | }
|
---|
212 |
|
---|