Completed transition to new ipkg method (ipkg.def), successfully booting after stage 1
[hvlinux.git] / functions-update
index 2f2359f..d56e2bf 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 LFS_PKG_BASE="$(dirname $(pwd))/packages"
 LFS_PKG_DIR="${LFS_PKG_BASE}/${LFS_STAGE}"
@@ -25,7 +25,7 @@ TETEX_URL="http://www.tug.org/ftp/tex-archive/systems/unix/teTeX"
 BLFS_XORG_URL="http://anduin.linuxfromscratch.org/files/BLFS/svn/xorg"
 XORG_URL="http://xorg.freedesktop.org/releases/individual"
 
-WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=15 --tries=3 -nc --continue --no-check-certificate -${WGET_LOG_FILE}"
+WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=15 --tries=3 -nc --continue --no-check-certificate --no-verbose --output-file=${WGET_LOG_FILE}"
 
 LFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-lfs.html
 BLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-blfs.html
@@ -40,6 +40,10 @@ static_fetch_patches_list()
     PATCHES_LIST_FILENAME=${2}
 
     ${WGETCMD} "${PATCHES_URL}/" &&
+
+    # Append log to global log file
+    cat ${WGET_LOG_FILE} >> ${LFS_LOG_FILE} &&
+
     mv ${LFS_PKG_DIR}/index.html ${PATCHES_LIST_FILENAME}
 }
 
@@ -92,11 +96,17 @@ static_checkpatch()
     local PATCHES_LIST=${2}
     local PATCHES_URL=${3}
 
-    local PATCHES_FOUND=$(cat ${PATCHES_LIST} | grep "${PACK}-" | sed "s/.*\(${PACK}-.*\.patch\).*/\1/")
+    # Remplace les "+" par "%2B"
+    local PACK_URL=$(echo $PACK | sed s!\+!%2B!g)
+
+    local PATCHES_FOUND=$(cat ${PATCHES_LIST} | grep "${PACK_URL}-" | sed "s/.*\(${PACK_URL}-.*\.patch\).*/\1/")
     if [ -n "${PATCHES_FOUND}" ]; then
        for p in ${PATCHES_FOUND}; do
-           if [ ! -f ${LFS_PKG_DIR}/${p} ]; then
-               rcmd "Fetching ${p} from ${PATCHES_URL}" ${WGETCMD} ${PATCHES_URL}/${p}
+            # Remplace les "%2B" par "+"
+            PATCH_NAME=$(echo ${p} | sed s!%2B!\+!g)
+
+           if [ ! -f ${LFS_PKG_DIR}/${PATCH_NAME} ]; then
+               rcmd "Fetching ${PATCH_NAME} from ${PATCHES_URL}" ${WGETCMD} ${PATCHES_URL}/${p}
            fi
        done
     fi
@@ -191,6 +201,7 @@ detect_file_not_found()
         echo "404 NOTFOUND"
         return 0
     elif grep "No such file" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then
+        echo "No such file"
         return 0
     else
         return 1
@@ -218,28 +229,39 @@ static_getpkg()
         MY_ARCH_EXT="tar.bz2 tar.gz tgz tar.Z"
     fi
 
-    echo "  MY_ARCH_EXT=${MY_ARCH_EXT}"
-
     for arch_ext in ${MY_ARCH_EXT}; do
         # Don't take any chance: remove any partially downloaded file.
         # If we arrive here, it means the final destination file was not found
         # so we can safely remove any file prior to trying to download it.
         rm -f ${LFS_PKG_DIR}/${PACK}.${arch_ext}
 
+        echo "Trying to fetch ${PACK}.${arch_ext}"
+
         ${WGETCMD} ${URL}/${PACK}.${arch_ext}
+        wget_status=$?
 
-        # Failure: if it was a connection timeout, don't try for other file extensions.
+        # Append log to global log file
+        cat ${WGET_LOG_FILE} >> ${LFS_LOG_FILE}
+
+        # Failure: if it was a connection timeout, don't try for other file
+        # extensions.
         if grep "failed: Connection timed out" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then
             echo "Error, wget reported: Connection timed out"
             return 1
         fi
 
         if detect_file_not_found; then
-            # Try next archive extension if web server reported that file is not found.
+            # Try next archive extension if web server reported that file is not
+            # found.
             continue;
         fi
 
-        # If we arrive here, it means we were able to download the file.
+        if [ ${wget_status} -ne 0 ]; then
+            echo "Error fetching package ${PACK}.${arch_ext}"
+            return 1
+        fi
+
+        # If we arrive here, it means we were able to successfully download the file.
         if [ "x${arch_ext}" = "xtar.gz" -o "x${arch_ext}" = "xtgz" -o "x${arch_ext}" = "xtar.Z" ]; then
            gztobz2 ${LFS_PKG_DIR}/${PACK}.${arch_ext}
         fi
@@ -256,7 +278,7 @@ static_getpkg()
 # Options:
 #   -e     File extension (default is tar.bz2)
 #   -d     Fetch directory (default is LFS_PKG_DIR)
-#   -f     Filename (default is PACKAGE)
+#   -f     Filename on server (default is PACKAGE)
 #   -h     Display this help and returns
 #   -s     Subdirectory on server
 fpkg()
@@ -361,13 +383,16 @@ fpkg()
     # Check for available patches with PACKAGE (TARGET) name.
     static_getpatch ${PACK}
 
-    # Check for available patches with SRC_FILENAME name.
-    static_getpatch ${SRC_FILENAME}
+    if [ ${SRC_FILENAME} != ${PACK} ]; then
+        # Check for available patches with SRC_FILENAME name.
+        static_getpatch ${SRC_FILENAME}
 
-    # Rename any patch fetched (in fpkg call) and replace SOURCE by TARGET in
-    # patch name.
-    if ls ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch 1> /dev/null 2>&1; then
-       rename ${SRC_FILENAME} ${PACK} ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch
+        # Rename any patch fetched (in fpkg call) and replace SOURCE by TARGET
+        # in patch name.
+        if ls ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch 1> /dev/null 2>&1; then
+            echo "CMD=${SRC_FILENAME} ${PACK} ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch"
+           rename ${SRC_FILENAME} ${PACK} ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch
+        fi
     fi
 }