source: common/libs/func_download_pkgs@ 87eb9e9

ablfs-more trunk
Last change on this file since 87eb9e9 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
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 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"
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.