source: common/libs/func_download_pkgs

trunk
Last change on this file was c1f02f2, checked in by Pierre Labastie <pierre.labastie@…>, 13 months ago

LFS: remove alternate server code

It's been broken for years, and nobody has complained, so I'd say
it is not useful. If a user wants to use a mirror instead of upstream,
better use a wget-list directly on this server...

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#!/bin/bash
2
3#----------------------------#
4get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
5#----------------------------#
6
7 # Test if the packages must be downloaded
8 [ "$GETPKG" = y ] || return 0
9
10 local URL FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM MAYBEMORE
11
12 WGETPARAM=""
13 if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
14 WGETPARAM+="--retry-connrefused"
15 fi
16 WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
17 WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
18
19 gs_wrt_message(){
20 echo "${RED}$1${OFF}"
21 echo "$1" >> MISSING_FILES.DMP
22 }
23 # Housekeeping
24 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
25 cd $BUILDDIR/sources
26
27 # Generate URLs file
28 create_urls
29
30 # Clean up leftovers from preceding attempts
31 >MISSING_FILES.DMP
32
33 # Normally, urls.lst contains lines with two fields:
34 # <package url> <book md5>, but
35 # if a custom patch has an md5, there is a third field
36 # on the line, due to the way add_CustomToolsURLS works.
37 cat urls.lst | while read URL BOOKMD5 MAYBEMORE; do
38 FILE=$(basename "$URL") # File name
39
40 # Validation pair
41 MD5="$BOOKMD5 $FILE"
42 HAVEMD5=1
43
44 set -e
45 # If the file exists in the archive, copy it to the
46 # $BUILDDIR/sources dir. MD5SUM will be validated later.
47 if [ -n "${SRC_ARCHIVE}" ] &&
48 [ -d "${SRC_ARCHIVE}" ] &&
49 [ -f "${SRC_ARCHIVE}/$FILE" ]; then
50 cp "${SRC_ARCHIVE}/$FILE" .
51 echo "$FILE: -- copied from $SRC_ARCHIVE"
52 fromARCHIVE=1
53 else
54 fromARCHIVE=0
55 # If the file does not exist yet in /sources, download a fresh one
56 if [ ! -f "$FILE" ] ; then
57 if [ -n "$SRC_ARCHIVE" ] ; then
58 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} nor in ${BUILDDIR}/sources${OFF}"
59 else
60 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
61 fi
62 if ! wget "$URL" $WGETPARAM; then
63 gs_wrt_message "$FILE not found on any server..SKIPPING"
64 continue
65 fi
66 else
67 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
68 fi
69 fi
70
71 # Deal with bootscripts md5sum issue,
72 # or skip if it is a custom patch without md5
73 [ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ] && continue
74 [ $BOOKMD5 = "CUSTOM-PATCH-MD5SUM" ] && continue
75
76 # IF the md5sum does not match
77 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
78 [ "$fromARCHIVE" = 1 ] && echo "${BOLD}${YELLOW}MD5SUM did not match $SRC_ARCHIVE copy${OFF}"
79 [ "$fromARCHIVE" = 0 ] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
80 # Remove the old file and download a new one
81 rm -fv "$FILE"
82 # Force storage in SRC_ARCHIVE
83 fromARCHIVE=0;
84 # Try to retrieve again the file.
85 if ! wget "$URL" $WGETPARAM; then
86 gs_wrt_message "$FILE not found on the server... SKIPPING"
87 continue
88 fi
89 fi
90
91 # Validate the MD5SUM one last time
92 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
93 gs_wrt_message "$FILE does not match MD5SUMS value"
94 # Force generation of MD5SUM
95 HAVEMD5=0
96 fi
97
98 # Generate a fresh MD5SUM for this file
99 if [ "$HAVEMD5" = "0" ] ; then
100 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
101 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
102 fi
103
104 # Good or bad we write the original md5sum to a file
105 echo "$MD5" >> MD5SUMS
106
107 # Copy the freshly downloaded file
108 # to the source archive.
109 if [ -n "${SRC_ARCHIVE}" ] &&
110 [ -d "${SRC_ARCHIVE}" ] &&
111 [ -w "${SRC_ARCHIVE}" ] &&
112 [ ! -f "${SRC_ARCHIVE}/$FILE" ] &&
113 [ "$fromARCHIVE" = 0 ] ; then
114 echo "Storing file:<$FILE> in the package archive"
115 cp -f "$FILE" "${SRC_ARCHIVE}"
116 fi
117
118 done
119
120 if [[ -s MISSING_FILES.DMP ]]; then
121 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"
122 # Do not allow the automatic execution of the Makefile.
123 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
124 RUNMAKE="n"
125 fi
126}
127
128#----------------------------#
129create_urls() { #
130#----------------------------#
131 cd $JHALFSDIR
132
133 echo -n "Creating URLs file... "
134 xsltproc --nonet --xinclude \
135 --stringparam pkgmngt "$PKGMNGT" \
136 --stringparam revision "$INITSYS" \
137 --output ../sources/urls.lst \
138 urls.xsl \
139 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
140 echo "OK"
141
142 cd $BUILDDIR/sources
143
144 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
145 add_CustomToolsURLS
146 fi
147
148}
149
Note: See TracBrowser for help on using the repository browser.