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