Déplacé variable GATEWAY dans script de configuration de carte réseau
[hvlinux.git] / functions-update
index 4c67529..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}"
@@ -8,21 +8,28 @@ WGET_LOG_FILE="${LFS_LOG_DIR}/pkg-wget.log"
 
 # URL
 LFS_BASE_URL="http://www.linuxfromscratch.org"
+CLFS_BASE_URL="http://svn.cross-lfs.org/svn/repos/cross-lfs/trunk"
+HV_BASE_URL="http://www.hugovil.com/hvlinux-repository"
+
 LFS_PATCHES_URL="${LFS_BASE_URL}/patches/lfs/development"
-LFS_PACKAGES_URL="ftp://ftp.osuosl.org/pub/lfs/lfs-packages/conglomeration"
 BLFS_PATCHES_URL="${LFS_BASE_URL}/patches/blfs/svn"
-HV_BASE_URL="http://www.hugovil.com/hvlinux-repository"
-HV_PACKAGES_URL="${HV_BASE_URL}/packages"
+CLFS_PATCHES_URL="http://patches.cross-lfs.org/dev"
 HV_PATCHES_URL="${HV_BASE_URL}/patches"
-SOURCEFORGE_URL="http://internap.dl.sourceforge.net/sourceforge"
+
+LFS_PACKAGES_URL="ftp://ftp.osuosl.org/pub/lfs/lfs-packages/conglomeration"
+HV_PACKAGES_URL="${HV_BASE_URL}/packages"
+SOURCEFORGE_URL="http://cdnetworks-us-1.dl.sourceforge.net"
 GNOME_URL="http://ftp.gnome.org/pub/gnome/sources"
 GNU_URL="http://ftp.gnu.org/pub/gnu"
 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=5 --tries=3 -nc -c -o ${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
+CLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-clfs.html
 HV_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-hv.html
 
 # Arg. #1: URL for patches repository.
@@ -33,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}
 }
 
@@ -40,6 +51,10 @@ static_fetch_patches_list()
 #          slash is absolutely necessary for this to work.
 update_packages_init()
 {
+    # Execute a return statement instead of exit, to be able to continue with
+    # downloading other packages
+    export RCMD_NO_EXIT=1
+
     # First create log directory if it does not exists.
     if [ ! -d ${LFS_LOG_DIR} ]; then
        install -m755 -d ${LFS_LOG_DIR} || exit 1
@@ -50,15 +65,25 @@ update_packages_init()
        install -v -m755 -d ${LFS_PKG_DIR} 1> ${LFS_LOG_FILE} 2>&1 || exit 1
     fi
 
-    # Getting list of all patches from LFS server.
-    ##action_checkbox "Fetching LFS patches list"
-    static_fetch_patches_list ${LFS_PATCHES_URL} ${LFS_PATCHES_LIST}
+    if [ -n "${USE_LFS_PATCHES}" ]; then
+        # Getting list of all patches from LFS server.
+        rcmd "Fetching LFS patches list" static_fetch_patches_list ${LFS_PATCHES_URL} ${LFS_PATCHES_LIST}
+    fi
 
-    # Getting list of all patches from BLFS server.
-    action_checkbox "Fetching BLFS patches list" static_fetch_patches_list ${BLFS_PATCHES_URL} ${BLFS_PATCHES_LIST}
+    if [ -n "${USE_BLFS_PATCHES}" ]; then
+        # Getting list of all patches from BLFS server.
+        rcmd "Fetching BLFS patches list" static_fetch_patches_list ${BLFS_PATCHES_URL} ${BLFS_PATCHES_LIST}
+    fi
 
-    # Getting list of all patches from hugovil.com server.
-    action_checkbox "Fetching hugovil.com patches list" static_fetch_patches_list ${HV_PATCHES_URL} ${HV_PATCHES_LIST}
+    if [ -n "${USE_CLFS_PATCHES}" ]; then
+        # Getting list of all patches from CLFS server.
+        rcmd "Fetching CLFS patches list" static_fetch_patches_list ${CLFS_PATCHES_URL} ${CLFS_PATCHES_LIST}
+    fi
+
+    if [ -n "${USE_HV_PATCHES}" ]; then
+        # Getting list of all patches from hugovil.com server.
+        rcmd "Fetching hugovil.com patches list" static_fetch_patches_list ${HV_PATCHES_URL} ${HV_PATCHES_LIST}
+    fi
 }
 
 # Get patch package if it is not in the repository
@@ -71,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
-               action_checkbox_time "Fetching ${p}" ${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
@@ -93,14 +124,25 @@ static_getpatch()
        return 1
     fi
 
-    # Checking if patch is available from LFS.
-    static_checkpatch ${PACK} ${LFS_PATCHES_LIST} ${LFS_PATCHES_URL}
+    if [ -n "${USE_LFS_PATCHES}" ]; then
+        # Checking if patch is available from LFS.
+        static_checkpatch ${PACK} ${LFS_PATCHES_LIST} ${LFS_PATCHES_URL}
+    fi
 
-    # Checking if patch is available from BLFS.
-    static_checkpatch ${PACK} ${BLFS_PATCHES_LIST} ${BLFS_PATCHES_URL}
+    if [ -n "${USE_BLFS_PATCHES}" ]; then
+        # Checking if patch is available from BLFS.
+        static_checkpatch ${PACK} ${BLFS_PATCHES_LIST} ${BLFS_PATCHES_URL}
+    fi
 
-    # Checking if patch is available from hugovil.com.
-    static_checkpatch ${PACK} ${HV_PATCHES_LIST} ${HV_PATCHES_URL}
+    if [ -n "${USE_CLFS_PATCHES}" ]; then
+        # Checking if patch is available from CLFS.
+        static_checkpatch ${PACK} ${CLFS_PATCHES_LIST} ${CLFS_PATCHES_URL}
+    fi
+
+    if [ -n "${USE_HV_PATCHES}" ]; then
+        # Checking if patch is available from hugovil.com.
+        static_checkpatch ${PACK} ${HV_PATCHES_LIST} ${HV_PATCHES_URL}
+    fi
 }
 
 # Convert multiple compressed gzip files to bzip2.
@@ -155,9 +197,11 @@ detect_file_not_found()
 {
     # HTTP: will return error code 404.
     # FTP: will say "File not found"
-    if grep "404 Not Found" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then
+    if grep "404" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then
+        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
@@ -167,63 +211,111 @@ detect_file_not_found()
 # Get package if it is not in the repository
 # Arg. #1: Package name and version
 # Arg. #2: URL
+# Arg. #3: Optional extension
 static_getpkg()
 {
-    PACK=${1}
-    URL=${2}
+    local PACK=${1}
+    local URL=${2}
+    local MY_ARCH_EXT=${3}
 
     # Checking for correct number of arguments
-    if [ $# -ne 2 ]; then
+    if [ $# -ne 2 -a $# -ne 3 ]; then
        echo "${FUNCNAME}(), wrong number of arguments: ${*}"
        return 1
     fi
 
-    ${WGETCMD} ${URL}/${PACK}.tar.bz2 && return 0
-
-    # 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
+    if [ -z "${MY_ARCH_EXT}" ]; then
+        # List of default archive extensions to try
+        MY_ARCH_EXT="tar.bz2 tar.gz tgz tar.Z"
     fi
 
-    if detect_file_not_found; then
-        # If file was not found, maybe a .tar.gz file exist...
-       ${WGETCMD} ${URL}/${PACK}.tar.gz
-       if [ ${?} -eq 0 ]; then
-           gztobz2 ${LFS_PKG_DIR}/${PACK}.tar.gz || return 1
-            return 0
-       else
-            if detect_file_not_found; then
-                # If file was not found, maybe a .tgz file exist...
-               ${WGETCMD} ${URL}/${PACK}.tgz
-               if [ ${?} -eq 0 ]; then
-                   gztobz2 ${LFS_PKG_DIR}/${PACK}.tgz || return 1
-                    return 0
-               else
-                    if detect_file_not_found; then
-                        # If file was not found, maybe a .tar.Z file exist... (uw-imap...)
-                       ${WGETCMD} ${URL}/${PACK}.tar.Z
-                       if [ ${?} -eq 0 ]; then
-                           gztobz2 ${LFS_PKG_DIR}/${PACK}.tar.Z || return 1
-                            return 0
-                       fi
-                   fi
-                fi
-            fi
+    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=$?
+
+        # 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.
+            continue;
+        fi
+
+        if [ ${wget_status} -ne 0 ]; then
+            echo "Error fetching package ${PACK}.${arch_ext}"
+            return 1
         fi
-    fi
 
-    # Failure...
+        # 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
+        return $?
+    done
+
+    # Failure or file not found
     return 1
 }
 
 # Get package if it is not in the repository
 # Arg. #1: Package name and version
 # Arg. #2: URL
+# Options:
+#   -e     File extension (default is tar.bz2)
+#   -d     Fetch directory (default is LFS_PKG_DIR)
+#   -f     Filename on server (default is PACKAGE)
+#   -h     Display this help and returns
+#   -s     Subdirectory on server
 fpkg()
 {
-    PACK=${1}
-    URL=${2}
+    local FILE_EXT=""
+    local DEST_DIR=""
+    local SRC_FILENAME=""
+    local SRC_DIR=""
+
+    while getopts "e:d:f:hs:" flag ;do
+        case ${flag} in
+           e)
+                # File extension
+                FILE_EXT=${OPTARG}
+               ;;
+           d)
+                # Fetch directory (where to put file)
+                DEST_DIR=${OPTARG}
+               ;;
+           f)
+                # Filename if different than package name
+                SRC_FILENAME=${OPTARG}
+               ;;
+           s)
+               SRC_DIR=${OPTARG}
+                ;;
+           ?)
+               echo "${FUNCNAME}(): Invalid option: ${OPTARG}."
+               return 1
+               ;;
+        esac
+    done
+    shift `expr "${OPTIND}" - 1`
+
+    unset OPTSTRING
+    unset OPTIND
+    unset OPTARG
 
     # Checking for correct number of arguments
     if [ $# -ne 2 ]; then
@@ -231,50 +323,76 @@ fpkg()
        return 1
     fi
 
-    if [ ! -f ${LFS_PKG_DIR}/${PACK}.tar.bz2 ]; then
-       action_checkbox_time "Fetching ${PACK}" static_getpkg ${PACK} ${URL}
+    local PACK=${1}
+    local URL=${2}
+    local FETCH_STRING="Fetching ${PACK}"
+
+    if [ -z "${SRC_FILENAME}" ]; then
+        # Default source filename = name of package
+        SRC_FILENAME=${PACK}
     fi
 
-    # Check if a patch is available.
-    static_getpatch ${PACK}
-}
+    if [ -n "${FILE_EXT}" ]; then
+        FETCH_STRING="${FETCH_STRING}.${FILE_EXT}"
+    fi
 
-# Get package if it is not in the repository.
-# This function is used if the source and target names for the
-# package are different (name mismatch).
-# Arg. #1: Target package name and version (on disk)
-# Arg. #2: Source package name and version (on internet)
-# Arg. #3: URL
-fpkg_mis()
-{
-    TARGET=${1}
-    SOURCE=${2}
-    URL=${3}
+    if [ -z "${FILE_EXT}" -o \
+        "x${FILE_EXT}" = "xtar.gz" -o \
+        "x${FILE_EXT}" = "xtgz" -o \
+        "x${FILE_EXT}" = "xtar.Z" -o \
+        "x${FILE_EXT}" = "xtar.bz2" \
+        ]; then
+        FINAL_EXT=tar.bz2
+    else
+        FINAL_EXT=${FILE_EXT}
+    fi
 
-    # Checking for correct number of arguments
-    if [ $# -ne 3 ]; then
-       echo "${FUNCNAME}(), wrong number of arguments: ${*}"
-       return 1
+    if [ -z "${DEST_DIR}" ]; then
+        # Default destination directory
+        DEST_DIR=${LFS_PKG_DIR}
     fi
 
-    if [ ! -f ${LFS_PKG_DIR}/${TARGET}.tar.bz2 ]; then
-       fpkg ${SOURCE} ${URL}
-       
-       if [ -f ${LFS_PKG_DIR}/${SOURCE}.tar.bz2 ]; then
-           mv ${LFS_PKG_DIR}/${SOURCE}.tar.bz2 ${LFS_PKG_DIR}/${TARGET}.tar.bz2
+    mkdir -v -p ${DEST_DIR} >> ${LFS_LOG_FILE} 2>&1
+
+    if [ -z "${SRC_DIR}" ]; then
+        # Default source subdirectory on server
+        SRC_DIR=""
+    else
+        URL=${URL}/${SRC_DIR}
+    fi
+
+    DEST_FILE=${DEST_DIR}/${PACK}.${FINAL_EXT}
+
+    if [ ! -f ${DEST_FILE} ]; then
+        rcmd "${FETCH_STRING}" static_getpkg ${SRC_FILENAME} ${URL} ${FILE_EXT}
+
+        # Move file if source filename is not equal to package name and/or destination
+        # directory is not the default:
+        DOWNLOADED_FILE=${LFS_PKG_DIR}/${SRC_FILENAME}.${FINAL_EXT}
+
+        if [ "${DEST_FILE}" != "${DOWNLOADED_FILE}" ]; then
+           mv ${DOWNLOADED_FILE} ${DEST_FILE}
        fi
     fi
 
-    # Check for available patches with TARGET name.
-    static_getpatch ${TARGET}
+    # Test integrity of archive if requested
+    if [ -f ${DEST_FILE} -a -n "${TEST_INTEGRITY}" -a "x${FINAL_EXT}" = "xtar.bz2" ]; then
+        rcmd "Testing integrity of ${PACK}.${FINAL_EXT}" bzip2 -t ${DEST_FILE}
+    fi
 
-    # Check for available patches with SOURCE name.
-    static_getpatch ${SOURCE}
+    # Check for available patches with PACKAGE (TARGET) name.
+    static_getpatch ${PACK}
 
-    # Rename any patch fetched (in fpkg call) and replace SOURCE by TARGET in
-    # patch name.
-    if ls ${LFS_PKG_DIR}/${SOURCE}-*.patch 1> /dev/null 2>&1; then
-       rename ${SOURCE} ${TARGET} ${LFS_PKG_DIR}/${SOURCE}-*.patch
+    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
+            echo "CMD=${SRC_FILENAME} ${PACK} ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch"
+           rename ${SRC_FILENAME} ${PACK} ${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch
+        fi
     fi
 }
 
@@ -283,7 +401,7 @@ fpkg_mis()
 # Arg. #2: Directory name (optional)
 fpkg_gnu()
 {
-    PACK=${1}
+    local PACK=${1}
 
     if [ $# -eq 2 ]; then
        NAME=${2}
@@ -384,6 +502,23 @@ fpkg_lfs()
     fi
 }
 
+# Get package if it is not in the repository
+# Arg. #1: Package name and version
+# Arg. #2: Subdirectory name (module name)
+fpkg_xorg()
+{
+    local PACK=${1}
+    local SUBDIR=${2}
+
+    # Checking for correct number of arguments
+    if [ $# -ne 2 ]; then
+       echo "${FUNCNAME}(), wrong number of arguments: ${*}"
+       return 1
+    fi
+
+    fpkg -d ${LFS_PKG_DIR}/${SUBDIR} -s ${SUBDIR} ${PACK} ${XORG_URL}
+}
+
 # Create a symbolic link to a package that is located in another stage
 # repository (to not have the same file twice).
 # Arg. #1: Source stage number (1, 2, 3, etc)
@@ -401,15 +536,15 @@ lpkg()
     fi
 
     if [ ! -h ${LFS_PKG_DIR}/${FILE} ]; then
-       # The link does not exist. First check if source file exist.
+       # Issue a warning if source file doesn't exist.
        if [ ! -f ${LFS_PKG_BASE}/${SRCSTAGE}/${FILE} ]; then
-           echo "${FUNCNAME} ${*}"
-           echo "Missing source file..."
-           exit 1
+            source_link_status=" (missing source file)"
+        else
+            source_link_status=""
        fi
 
        # Create link if it doesn't exist
-       ln -s ../${SRCSTAGE}/${FILE} ${LFS_PKG_DIR}/${FILE}
+       rcmd "Linking ${PACKAGE_NAME}${source_link_status}" ln -s ../${SRCSTAGE}/${FILE} ${LFS_PKG_DIR}/${FILE}
     fi
 
     # Create link for patches corresponding to that package:
@@ -418,7 +553,7 @@ lpkg()
            PATCHFILE=$(basename ${patch})
            if [ ! -h ${LFS_PKG_DIR}/${PATCHFILE} ]; then
                # Create link if it doesn't exist
-               ln -s ../${SRCSTAGE}/${PATCHFILE} ${LFS_PKG_DIR}/${PATCHFILE}
+               rcmd "Linking ${PATCHFILE}" ln -s ../${SRCSTAGE}/${PATCHFILE} ${LFS_PKG_DIR}/${PATCHFILE}
            fi
        done
     fi