source: common/libs/func_download_pkgs@ b217a30

ablfs-more legacy trunk
Last change on this file since b217a30 was 085435e, checked in by Pierre Labastie <pierre@…>, 5 years ago

Remove the obsolete vim-lang instructions and variable, and add non-wide-
charater ncurses library

  • Property mode set to 100644
File size: 6.2 KB
RevLine 
[fe30c61]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
[de63126]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}"
[fe30c61]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
[bb4b5c3]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
[fe30c61]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
[9d55d85]65 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
[7072e1f]66 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
[9d55d85]67 else
[7072e1f]68 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
[9d55d85]69 fi
[de63126]70 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
[fe30c61]71 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
72 continue
73 fi
[7072e1f]74 else
75 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
[fe30c61]76 fi
77 fi
78
[5210ae1]79 # Deal with udev and bootscripts m5sum issue
[0700131]80 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
81 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
82 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
[5210ae1]83
[fe30c61]84 # IF the md5sum does not match the existing files
85 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
86 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
87 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
88 # Remove the old file and download a new one
89 rm -fv $FILE
90 # Force storage in SRC_ARCHIVE
91 fromARCHIVE=0;
92 # Try to retrieve again the file. Servers in reverse order.
[de63126]93 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
[fe30c61]94 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
95 continue
96 fi
97 fi
98
99 # Validate the MD5SUM one last time
100 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
101 gs_wrt_message "$FILE does not match MD5SUMS value"
102 # Force generation of MD5SUM
103 HAVEMD5=0
104 fi
105
106 # Generate a fresh MD5SUM for this file
107 if [[ "$HAVEMD5" = "0" ]] ; then
108 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
109 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
110 fi
111
112 # Good or bad we write the original md5sum to a file
[93fd2d0]113 echo "$MD5" >> MD5SUMS
[fe30c61]114
115 # Copy the freshly downloaded file
116 # to the source archive.
117 if [ ! -z ${SRC_ARCHIVE} ] &&
118 [ -d ${SRC_ARCHIVE} ] &&
119 [ -w ${SRC_ARCHIVE} ] &&
120 [ "$fromARCHIVE" = "0" ] ; then
121 echo "Storing file:<$FILE> in the package archive"
122 cp -f $FILE ${SRC_ARCHIVE}
123 fi
124
125 done
126
127 if [[ -s MISSING_FILES.DMP ]]; then
128 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"
129 # Do not allow the automatic execution of the Makefile.
130 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
131 RUNMAKE="n"
132 fi
133}
134
135#----------------------------#
136create_urls() { #
137#----------------------------#
138 cd $JHALFSDIR
139
140 case ${PROGNAME} in
[809a821]141 clfs*)
[fe30c61]142 echo -n "Creating CLFS <${ARCH}> specific URLs file"
[a4acb12]143 xsltproc --nonet --xinclude \
144 --stringparam server "$SERVER" \
145 --stringparam family clfs \
146 -o $BUILDDIR/sources/urls.lst \
147 urls.xsl \
[809a821]148 $BOOK/BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
[fe30c61]149 echo " ...OK"
150 ;;
151 hlfs)
[139c34e]152 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
[a4acb12]153 xsltproc --nonet --xinclude \
154 --stringparam server "$SERVER" \
155 --stringparam family lfs \
156 --stringparam model "$MODEL" \
157 --stringparam kernel "$KERNEL" \
158 -o $BUILDDIR/sources/urls.lst \
159 urls.xsl \
[fe30c61]160 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
161 echo " ...OK"
162 ;;
163 lfs)
164 echo -n "Creating LFS specific URLs file"
[a4acb12]165 xsltproc --nonet --xinclude \
166 --stringparam server "$SERVER" \
167 --stringparam family lfs \
168 --stringparam pkgmngt "$PKGMNGT" \
169 --stringparam revision "$INITSYS" \
170 --output ../sources/urls.lst \
171 urls.xsl \
[fe30c61]172 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
173 echo " ...OK"
174 ;;
175 esac
176
177 cd $BUILDDIR/sources
178
179 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
180 add_CustomToolsURLS
181 fi
182
183}
184
Note: See TracBrowser for help on using the repository browser.