source: common/libs/func_download_pkgs@ 401aac8

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

Use continue instead of return, continue allows the loop to continue from the beginning instead of jumping completely out of the function.

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