source: common/libs/func_download_pkgs@ 4c36783

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

Remove legacy: remove everything about HLFS

  • Property mode set to 100644
File size: 5.8 KB
Line 
1#!/bin/bash
2
3#----------------------------#
4get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
5#----------------------------#
6 local saveIFS=$IFS
7 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE WGETPARAM
8
9 WGETPARAM=""
10 if [[ "${RETRYSRCDOWNLOAD}" = "y" ]] ; then
11 WGETPARAM+="--retry-connrefused"
12 fi
13 WGETPARAM+=" --tries ${RETRYDOWNLOADCNT}"
14 WGETPARAM+=" --timeout ${DOWNLOADTIMEOUT}"
15
16 # Test if the packages must be downloaded
17 [ ! "$GETPKG" = "y" ] && return
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 # If using CLFS, /sources is writable by all, but with sticky bit,
27 # and user does not hold MD5SUMS nor the other files, so use sudo
28 [[ -f MD5SUMS ]] && sudo rm MD5SUMS
29 [[ -f MISSING_FILES.DMP ]] && sudo rm MISSING_FILES.DMP
30 [[ -f urls.lst ]] && sudo rm urls.lst
31
32 # Generate URLs file
33 create_urls
34
35 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
36 for line in `cat urls.lst`; do
37 IFS=$saveIFS # Restore the system defaults
38
39 # Locations
40 URL1=`echo $line | cut -d" " -f2` # Preferred URL
41 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
42 FILE=`basename $URL1` # File name
43 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
44
45 # Validation pair
46 MD5="$BOOKMD5 $FILE"
47 HAVEMD5=1
48
49 set -e
50 # If the file exists in the archive copy it to the
51 # $BUILDDIR/sources dir. MD5SUM will be validated later.
52 if [ ! -z ${SRC_ARCHIVE} ] &&
53 [ -d ${SRC_ARCHIVE} ] &&
54 [ -f ${SRC_ARCHIVE}/$FILE ]; then
55 cp ${SRC_ARCHIVE}/$FILE .
56 echo "$FILE: -- copied from $SRC_ARCHIVE"
57 fromARCHIVE=1
58 else
59 fromARCHIVE=0
60 # If the file does not exist yet in /sources download a fresh one
61 if [ ! -f $FILE ] ; then
62 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
63 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
64 else
65 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
66 fi
67 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
68 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
69 continue
70 fi
71 else
72 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
73 fi
74 fi
75
76 # Deal with udev and bootscripts m5sum issue
77 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
78 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
79 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
80 [[ $BOOKMD5 = "CUSTOM-PATCH-MD5SUM" ]] && continue
81
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 $WGETPARAM && ! wget $URL1 $WGETPARAM ; 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" \
143 --stringparam family clfs \
144 -o $BUILDDIR/sources/urls.lst \
145 urls.xsl \
146 $BOOK/BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
147 echo " ...OK"
148 ;;
149 lfs)
150 echo -n "Creating LFS specific URLs file"
151 xsltproc --nonet --xinclude \
152 --stringparam server "$SERVER" \
153 --stringparam family lfs \
154 --stringparam pkgmngt "$PKGMNGT" \
155 --stringparam revision "$INITSYS" \
156 --output ../sources/urls.lst \
157 urls.xsl \
158 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
159 echo " ...OK"
160 ;;
161 esac
162
163 cd $BUILDDIR/sources
164
165 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
166 add_CustomToolsURLS
167 fi
168
169}
170
Note: See TracBrowser for help on using the repository browser.