source: common/libs/func_download_pkgs@ 5c8df43

ablfs-more trunk
Last change on this file since 5c8df43 was ff30640, checked in by Pierre Labastie <pierre.labastie@…>, 2 years ago

Fix an error when not downloading packages

When not downloading packages, the function "get_sources" returns
early because it begins with:

[ "$GETPKG" = y ]
return

The problem is that in this case it returns with an exit code
inherited from the last executed instruction, which is the
test (and therefore "false"). The solution is to change to
return 0.

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[fe30c61]1#!/bin/bash
2
3#----------------------------#
4get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
5#----------------------------#
[8c2b505]6
7 # Test if the packages must be downloaded
[ff30640]8 [ "$GETPKG" = y ] || return 0
[8c2b505]9
[dc53def]10 local URL FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM MAYBEMORE
[de63126]11
12 WGETPARAM=""
13 if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
14 WGETPARAM+="--retry-connrefused"
15 fi
16 WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
17 WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
[fe30c61]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
[8c2b505]30 # Clean up leftovers from preceding attempts
31 >MISSING_FILES.DMP
32
[dc53def]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
[fe30c61]39
40 # Validation pair
41 MD5="$BOOKMD5 $FILE"
42 HAVEMD5=1
43
44 set -e
[dc53def]45 # If the file exists in the archive, copy it to the
[fe30c61]46 # $BUILDDIR/sources dir. MD5SUM will be validated later.
[dc53def]47 if [ -n "${SRC_ARCHIVE}" ] &&
48 [ -d "${SRC_ARCHIVE}" ] &&
49 [ -f "${SRC_ARCHIVE}/$FILE" ]; then
50 cp "${SRC_ARCHIVE}/$FILE" .
[fe30c61]51 echo "$FILE: -- copied from $SRC_ARCHIVE"
52 fromARCHIVE=1
53 else
54 fromARCHIVE=0
[dc53def]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}"
[9d55d85]59 else
[7072e1f]60 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
[9d55d85]61 fi
[28ef51b]62 if ! wget "$URL" $WGETPARAM; then
[dc53def]63 gs_wrt_message "$FILE not found on any server..SKIPPING"
[fe30c61]64 continue
65 fi
[7072e1f]66 else
67 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
[fe30c61]68 fi
69 fi
70
[dc53def]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
[5210ae1]75
[dc53def]76 # IF the md5sum does not match
[fe30c61]77 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[dc53def]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}"
[fe30c61]80 # Remove the old file and download a new one
[dc53def]81 rm -fv "$FILE"
[fe30c61]82 # Force storage in SRC_ARCHIVE
83 fromARCHIVE=0;
[dc53def]84 # Try to retrieve again the file.
[28ef51b]85 if ! wget "$URL" $WGETPARAM; then
[dc53def]86 gs_wrt_message "$FILE not found on the server... SKIPPING"
[fe30c61]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
[dc53def]99 if [ "$HAVEMD5" = "0" ] ; then
[fe30c61]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
[93fd2d0]105 echo "$MD5" >> MD5SUMS
[fe30c61]106
107 # Copy the freshly downloaded file
108 # to the source archive.
[dc53def]109 if [ -n "${SRC_ARCHIVE}" ] &&
110 [ -d "${SRC_ARCHIVE}" ] &&
111 [ -w "${SRC_ARCHIVE}" ] &&
112 [ ! -f "${SRC_ARCHIVE}/$FILE" ] &&
113 [ "$fromARCHIVE" = 0 ] ; then
[fe30c61]114 echo "Storing file:<$FILE> in the package archive"
[dc53def]115 cp -f "$FILE" "${SRC_ARCHIVE}"
[fe30c61]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
[8825e69]133 echo -n "Creating URLs file... "
134 xsltproc --nonet --xinclude \
135 --stringparam server "$SERVER" \
136 --stringparam family lfs \
137 --stringparam pkgmngt "$PKGMNGT" \
138 --stringparam revision "$INITSYS" \
139 --output ../sources/urls.lst \
140 urls.xsl \
141 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
142 echo "OK"
[fe30c61]143
144 cd $BUILDDIR/sources
145
146 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
147 add_CustomToolsURLS
148 fi
149
150}
151
Note: See TracBrowser for help on using the repository browser.