source: common/libs/func_download_pkgs@ 4c32ca8

ablfs-more legacy trunk
Last change on this file since 4c32ca8 was 2718053, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Custom tools: prevent a warning if no md5sum for patches

  • Property mode set to 100644
File size: 6.3 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 # If using CLFS, /sources is writable by all, but with sticky bit,
30 # and user does not hold MD5SUMS nor the other files, so use sudo
31 [[ -f MD5SUMS ]] && sudo rm MD5SUMS
32 [[ -f MISSING_FILES.DMP ]] && sudo rm MISSING_FILES.DMP
33 [[ -f urls.lst ]] && sudo rm urls.lst
34
35 # Generate URLs file
36 create_urls
37
38 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
39 for line in `cat urls.lst`; do
40 IFS=$saveIFS # Restore the system defaults
41
42 # Locations
43 URL1=`echo $line | cut -d" " -f2` # Preferred URL
44 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
45 FILE=`basename $URL1` # File name
46 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
47
48 # Validation pair
49 MD5="$BOOKMD5 $FILE"
50 HAVEMD5=1
51
52 set -e
53 # If the file exists in the archive copy it to the
54 # $BUILDDIR/sources dir. MD5SUM will be validated later.
55 if [ ! -z ${SRC_ARCHIVE} ] &&
56 [ -d ${SRC_ARCHIVE} ] &&
57 [ -f ${SRC_ARCHIVE}/$FILE ]; then
58 cp ${SRC_ARCHIVE}/$FILE .
59 echo "$FILE: -- copied from $SRC_ARCHIVE"
60 fromARCHIVE=1
61 else
62 fromARCHIVE=0
63 # If the file does not exist yet in /sources download a fresh one
64 if [ ! -f $FILE ] ; then
65 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
66 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
67 else
68 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
69 fi
70 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
71 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
72 continue
73 fi
74 else
75 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
76 fi
77 fi
78
79 # Deal with udev and bootscripts m5sum issue
80 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
81 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
82 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
83 [[ $BOOKMD5 = "CUSTOM-PATCH-MD5SUM" ]] && continue
84
85 # IF the md5sum does not match the existing files
86 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
87 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
88 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
89 # Remove the old file and download a new one
90 rm -fv $FILE
91 # Force storage in SRC_ARCHIVE
92 fromARCHIVE=0;
93 # Try to retrieve again the file. Servers in reverse order.
94 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
95 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
96 continue
97 fi
98 fi
99
100 # Validate the MD5SUM one last time
101 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
102 gs_wrt_message "$FILE does not match MD5SUMS value"
103 # Force generation of MD5SUM
104 HAVEMD5=0
105 fi
106
107 # Generate a fresh MD5SUM for this file
108 if [[ "$HAVEMD5" = "0" ]] ; then
109 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
110 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
111 fi
112
113 # Good or bad we write the original md5sum to a file
114 echo "$MD5" >> MD5SUMS
115
116 # Copy the freshly downloaded file
117 # to the source archive.
118 if [ ! -z ${SRC_ARCHIVE} ] &&
119 [ -d ${SRC_ARCHIVE} ] &&
120 [ -w ${SRC_ARCHIVE} ] &&
121 [ "$fromARCHIVE" = "0" ] ; then
122 echo "Storing file:<$FILE> in the package archive"
123 cp -f $FILE ${SRC_ARCHIVE}
124 fi
125
126 done
127
128 if [[ -s MISSING_FILES.DMP ]]; then
129 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"
130 # Do not allow the automatic execution of the Makefile.
131 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
132 RUNMAKE="n"
133 fi
134}
135
136#----------------------------#
137create_urls() { #
138#----------------------------#
139 cd $JHALFSDIR
140
141 case ${PROGNAME} in
142 clfs*)
143 echo -n "Creating CLFS <${ARCH}> specific URLs file"
144 xsltproc --nonet --xinclude \
145 --stringparam server "$SERVER" \
146 --stringparam family clfs \
147 -o $BUILDDIR/sources/urls.lst \
148 urls.xsl \
149 $BOOK/BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
150 echo " ...OK"
151 ;;
152 hlfs)
153 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
154 xsltproc --nonet --xinclude \
155 --stringparam server "$SERVER" \
156 --stringparam family lfs \
157 --stringparam model "$MODEL" \
158 --stringparam kernel "$KERNEL" \
159 -o $BUILDDIR/sources/urls.lst \
160 urls.xsl \
161 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
162 echo " ...OK"
163 ;;
164 lfs)
165 echo -n "Creating LFS specific URLs file"
166 xsltproc --nonet --xinclude \
167 --stringparam server "$SERVER" \
168 --stringparam family lfs \
169 --stringparam pkgmngt "$PKGMNGT" \
170 --stringparam revision "$INITSYS" \
171 --output ../sources/urls.lst \
172 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 [[ "${CUSTOM_TOOLS}" = "y" ]]; then
181 add_CustomToolsURLS
182 fi
183
184}
185
Note: See TracBrowser for help on using the repository browser.