source: common/libs/func_download_pkgs@ f7c6c3c

ablfs-more legacy trunk
Last change on this file since f7c6c3c 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
Line 
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
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}"
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
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
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
65 if [[ ! ("$SRC_ARCHIVE" = "") ]] ; then
66 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE} or ${BUILDDIR}/sources${OFF}"
67 else
68 echo "${BOLD}${YELLOW}$FILE: not found in ${BUILDDIR}/sources${OFF}"
69 fi
70 if ! wget $URL1 $WGETPARAM && ! wget $URL2 $WGETPARAM ; then
71 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
72 continue
73 fi
74 else
75 echo "${BOLD}${YELLOW}$FILE: using cached file in ${BUILDDIR}/sources${OFF}"
76 fi
77 fi
78
79 # Deal with udev and bootscripts m5sum issue
80 [[ $BOOKMD5 = "BOOTSCRIPTS-MD5SUM" ]] && continue
81 [[ $BOOKMD5 = "UDEV-MD5SUM" ]] && continue
82 [[ $BOOKMD5 = "LFS-NETSCRIPTS-MD5SUM" ]] && continue
83
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.
93 if ! wget $URL2 $WGETPARAM && ! wget $URL1 $WGETPARAM ; then
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
113 echo "$MD5" >> MD5SUMS
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
141 clfs*)
142 echo -n "Creating CLFS <${ARCH}> specific URLs file"
143 xsltproc --nonet --xinclude \
144 --stringparam server "$SERVER" \
145 --stringparam family clfs \
146 -o $BUILDDIR/sources/urls.lst \
147 urls.xsl \
148 $BOOK/BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
149 echo " ...OK"
150 ;;
151 hlfs)
152 echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
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 \
160 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
161 echo " ...OK"
162 ;;
163 lfs)
164 echo -n "Creating LFS specific URLs file"
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 \
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.