[9c9775f] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # $Id$
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | #----------------------------#
|
---|
| 7 | get_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
|
---|
| 11 |
|
---|
| 12 | # Test if the packages must be downloaded
|
---|
| 13 | [ ! "$GETPKG" = "y" ] && return
|
---|
| 14 |
|
---|
| 15 | gs_wrt_message(){
|
---|
| 16 | echo "${RED}$1${OFF}"
|
---|
| 17 | echo "$1" >> MISSING_FILES.DMP
|
---|
| 18 | }
|
---|
| 19 | # Housekeeping
|
---|
| 20 | [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
|
---|
| 21 | cd $BUILDDIR/sources
|
---|
| 22 | [[ -f MD5SUMS ]] && rm MD5SUMS
|
---|
| 23 | [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
|
---|
| 24 | [[ -f urls.lst ]] && rm urls.lst
|
---|
| 25 |
|
---|
| 26 | # Generate URLs file
|
---|
| 27 | create_urls
|
---|
| 28 |
|
---|
| 29 | IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
|
---|
| 30 | for line in `cat urls.lst`; do
|
---|
| 31 | IFS=$saveIFS # Restore the system defaults
|
---|
| 32 |
|
---|
| 33 | # Skip some packages if they aren't needed
|
---|
| 34 | case $line in
|
---|
| 35 | */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
|
---|
| 36 | [[ "$TEST" = "0" ]] && continue
|
---|
| 37 | ;;
|
---|
| 38 | */vim-*-lang* )
|
---|
| 39 | [[ "$VIMLANG" = "0" ]] && continue
|
---|
| 40 | ;;
|
---|
| 41 | *linux/linux-* )
|
---|
| 42 | [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
|
---|
| 43 | [[ "$GETKERNEL" = "n" ]] && continue
|
---|
| 44 | ;;
|
---|
| 45 | esac
|
---|
| 46 |
|
---|
| 47 | # Locations
|
---|
| 48 | URL1=`echo $line | cut -d" " -f2` # Preferred URL
|
---|
| 49 | URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
|
---|
| 50 | FILE=`basename $URL1` # File name
|
---|
| 51 | BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
|
---|
| 52 |
|
---|
| 53 | # Validation pair
|
---|
| 54 | MD5="$BOOKMD5 $FILE"
|
---|
| 55 | HAVEMD5=1
|
---|
| 56 |
|
---|
| 57 | set -e
|
---|
| 58 | # If the file exists in the archive copy it to the
|
---|
| 59 | # $BUILDDIR/sources dir. MD5SUM will be validated later.
|
---|
| 60 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
| 61 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
| 62 | [ -f ${SRC_ARCHIVE}/$FILE ]; then
|
---|
| 63 | cp ${SRC_ARCHIVE}/$FILE .
|
---|
| 64 | echo "$FILE: -- copied from $SRC_ARCHIVE"
|
---|
| 65 | fromARCHIVE=1
|
---|
| 66 | else
|
---|
| 67 | echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
|
---|
| 68 | fromARCHIVE=0
|
---|
| 69 | # If the file does not exist yet in /sources download a fresh one
|
---|
| 70 | if [ ! -f $FILE ] ; then
|
---|
| 71 | if ! wget $URL1 && ! wget $URL2 ; then
|
---|
| 72 | gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
|
---|
| 73 | continue
|
---|
| 74 | fi
|
---|
| 75 | fi
|
---|
| 76 | fi
|
---|
| 77 |
|
---|
| 78 | # IF the md5sum does not match the existing files
|
---|
| 79 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
| 80 | [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
|
---|
| 81 | [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
|
---|
| 82 | # Remove the old file and download a new one
|
---|
| 83 | rm -fv $FILE
|
---|
| 84 | # Force storage in SRC_ARCHIVE
|
---|
| 85 | fromARCHIVE=0;
|
---|
| 86 | # Try to retrieve again the file. Servers in reverse order.
|
---|
| 87 | if ! wget $URL2 && ! wget $URL1 ; then
|
---|
| 88 | gs_wrt_message "$FILE not found on the servers.. SKIPPING"
|
---|
| 89 | continue
|
---|
| 90 | fi
|
---|
| 91 | fi
|
---|
| 92 |
|
---|
| 93 | # Validate the MD5SUM one last time
|
---|
| 94 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
| 95 | gs_wrt_message "$FILE does not match MD5SUMS value"
|
---|
| 96 | # Force generation of MD5SUM
|
---|
| 97 | HAVEMD5=0
|
---|
| 98 | fi
|
---|
| 99 |
|
---|
| 100 | # Generate a fresh MD5SUM for this file
|
---|
| 101 | if [[ "$HAVEMD5" = "0" ]] ; then
|
---|
| 102 | echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
|
---|
| 103 | echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
|
---|
| 104 | fi
|
---|
| 105 |
|
---|
| 106 | # Good or bad we write the original md5sum to a file
|
---|
| 107 | echo "$MD5" >> MD5SUMS
|
---|
| 108 |
|
---|
| 109 | # Copy the freshly downloaded file
|
---|
| 110 | # to the source archive.
|
---|
| 111 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
| 112 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
| 113 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
| 114 | [ "$fromARCHIVE" = "0" ] ; then
|
---|
| 115 | echo "Storing file:<$FILE> in the package archive"
|
---|
| 116 | cp -f $FILE ${SRC_ARCHIVE}
|
---|
| 117 | fi
|
---|
| 118 |
|
---|
| 119 | done
|
---|
| 120 |
|
---|
| 121 | if [[ -s MISSING_FILES.DMP ]]; then
|
---|
| 122 | 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"
|
---|
| 123 | # Do not allow the automatic execution of the Makefile.
|
---|
| 124 | echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
|
---|
| 125 | RUNMAKE="n"
|
---|
| 126 | fi
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | #----------------------------#
|
---|
| 130 | create_urls() { #
|
---|
| 131 | #----------------------------#
|
---|
| 132 | cd $JHALFSDIR
|
---|
| 133 |
|
---|
| 134 | case ${PROGNAME} in
|
---|
| 135 | clfs)
|
---|
| 136 | echo -n "Creating CLFS <${ARCH}> specific URLs file"
|
---|
| 137 | xsltproc --nonet --xinclude \
|
---|
| 138 | --stringparam server $SERVER \
|
---|
| 139 | --stringparam family clfs \
|
---|
[9c60012] | 140 | -o $BUILDDIR/sources/urls.lst $CODE_DIR/XSL/urls.xsl \
|
---|
[9c9775f] | 141 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
| 142 | ;;
|
---|
| 143 | clfs2)
|
---|
| 144 | echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
|
---|
| 145 | xsltproc --nonet --xinclude \
|
---|
| 146 | --stringparam server $SERVER \
|
---|
| 147 | --stringparam family clfs \
|
---|
[9c60012] | 148 | -o $BUILDDIR/sources/urls.lst $CODE_DIR/XSL/urls.xsl \
|
---|
[9c9775f] | 149 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
| 150 | ;;
|
---|
| 151 | clfs3)
|
---|
| 152 | echo -n "Creating CLFS3 <${ARCH}> specific URLs file"
|
---|
| 153 | xsltproc --nonet --xinclude \
|
---|
| 154 | --stringparam server $SERVER \
|
---|
| 155 | --stringparam family clfs \
|
---|
[9c60012] | 156 | -o $BUILDDIR/sources/urls.lst $CODE_DIR/XSL/urls.xsl \
|
---|
[9c9775f] | 157 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
| 158 | ;;
|
---|
| 159 | hlfs)
|
---|
| 160 | echo -n "Creating HLFS <${MODEL}> + <${KERNEL}> specific URLs file"
|
---|
| 161 | xsltproc --nonet --xinclude \
|
---|
| 162 | --stringparam server $SERVER \
|
---|
| 163 | --stringparam family lfs \
|
---|
| 164 | --stringparam model $MODEL \
|
---|
| 165 | --stringparam kernel $KERNEL \
|
---|
[9c60012] | 166 | -o $BUILDDIR/sources/urls.lst $CODE_DIR/XSL/urls.xsl \
|
---|
[9c9775f] | 167 | $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
|
---|
| 168 | ;;
|
---|
| 169 | lfs)
|
---|
| 170 | echo -n "Creating LFS specific URLs file"
|
---|
| 171 | xsltproc --nonet --xinclude \
|
---|
| 172 | --stringparam server $SERVER \
|
---|
| 173 | --stringparam family lfs \
|
---|
[9c60012] | 174 | -o ../sources/urls.lst $CODE_DIR/XSL/urls.xsl \
|
---|
[9c9775f] | 175 | $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
|
---|
| 176 | ;;
|
---|
| 177 | esac
|
---|
| 178 |
|
---|
[7db3be7] | 179 | add_extra_urls
|
---|
[9c9775f] | 180 |
|
---|
[7db3be7] | 181 | echo " ...OK"
|
---|
[9c9775f] | 182 |
|
---|
[3470bea] | 183 | cd $BUILDDIR/sources
|
---|
| 184 |
|
---|
[9c9775f] | 185 | }
|
---|
| 186 |
|
---|
[7db3be7] | 187 | #----------------------------# Add download URLs found in user added scripts,
|
---|
| 188 | add_extra_urls() { # blfs-tool-deps scripts, and custom-tools scripts
|
---|
| 189 | #----------------------------#
|
---|
| 190 | local saveIFS=$IFS
|
---|
| 191 | local IFS file line package tarball download md5sum patchurl patchname patchmd5
|
---|
| 192 |
|
---|
| 193 | local BLFS_SERVER="${SERVER}/pub/blfs/conglomeration/"
|
---|
| 194 |
|
---|
| 195 | for file in ${PROGNAME}-commands/*/* ; do
|
---|
| 196 | # Grab the package name, tarball, download URL and MD5SUM
|
---|
| 197 | package=`grep "^PACKAGE=" ${file} | sed -e 's@PACKAGE=@@'`
|
---|
| 198 | tarball=`grep "^TARBALL=" ${file} | sed -e 's@TARBALL=@@'`
|
---|
| 199 | download=`grep "^DOWNLOAD=" ${file} | sed -e 's@DOWNLOAD=@@'`
|
---|
| 200 | md5sum=`grep "^MD5SUM=" ${file} | sed -e 's@MD5SUM=@@'`
|
---|
| 201 |
|
---|
| 202 | # Be sure that we have a download URL and MD5SUM value
|
---|
| 203 | if [ -n "${download}" ] && [ -n "${md5sum}" ] ; then
|
---|
| 204 | # Write the package entry
|
---|
| 205 | echo "${download} ${BLFS_SERVER}${package}/${tarball} ${md5sum}" >> ../sources/urls.lst
|
---|
| 206 | fi
|
---|
| 207 |
|
---|
| 208 | # Handle the patches, if any
|
---|
| 209 | IFS=$'\x0A'
|
---|
| 210 | for line in `grep "^PATCH=" ${file}` ; do
|
---|
| 211 | IFS=$saveIFS
|
---|
| 212 | patchurl=`echo ${line} | sed -e 's@PATCH="@@' -e 's@ .*@@'`
|
---|
| 213 | patchname=${patchurl##*/}
|
---|
| 214 | patchmd5=`echo ${line} | sed -e 's@.* @@' -e 's@"@@'`
|
---|
| 215 |
|
---|
| 216 | # Write the patch entry
|
---|
| 217 | echo "${patchurl} ${BLFS_SERVER}${package}/${patchname} ${patchmd5}" >> ../sources/urls.lst
|
---|
| 218 | done
|
---|
| 219 | done
|
---|
| 220 | }
|
---|