MErge en cours x86_64 -> trunk
[hvlinux.git] / functions
index 218df79..b799c51 100644 (file)
--- a/functions
+++ b/functions
@@ -7,27 +7,47 @@ EXIT_SUCCESS=0
 EXIT_WARNING=1
 EXIT_FAILURE=2
 
-# The starting position for displaying the "X" sign inside the check box [ ]
-CHECK_POSITION=2
-SET_CHECK_POSITION="echo -en \\033[${CHECK_POSITION}G"
-
+# Position the cursor at the start of the line
+SET_CURSOR_START_LINE="\033[1G"
 # NORMAL prints text in normal color
-NORMAL="echo -en \\033[0;39m"
+NORMAL="\033[0;39m"
 # SUCCESS prints text in a green colour
-SUCCESS="echo -en \\033[1;32m"
+SUCCESS="\033[1;32m"
 # WARNING prints text in a yellow colour
-WARNING="echo -en \\033[1;33m"
+WARNING="\033[1;33m"
 # FAILURE prints text in a red colour
-FAILURE="echo -en \\033[1;31m"
+FAILURE="\033[1;31m"
+# Brackets are blue
+BRACKET="\033[1;34m"
+
+TAR_OPTS="-b8"
 
 # It seems that when compiling bash-4.0, using
 # "make -j 1" is causing problems...
-if [ "x${MAKEJOBS}" == "x1" ]; then
+if [ "x${MAKEJOBS}" = "x1" ]; then
     HVMAKE="make"
 else
     HVMAKE="make -j ${MAKEJOBS}"
 fi
 
+case "${HVL_TARGET}" in
+    "x86_64")
+       CLFS_BUILDFLAGS="-m64"
+        CLFS_TARGET="${HVL_TARGET}-unknown-linux-gnu"
+       ;;
+    "x86")
+        # No special flags
+       CLFS_BUILDFLAGS=""
+        CLFS_TARGET="i686-unknown-linux-gnu"
+       ;;
+    *)
+       echo "Unsupported target architecture: ${HVL_TARGET}"
+       return ${EXIT_FAILURE}
+       ;;
+esac
+
+CLFS=${LFS}
+
 # Extracting the version number from a complete package name.
 # Arg. #1: Complete package name with version (ex: firefox-3.5.5.source will output 3.5.5)
 get_pkg_ver()
@@ -137,8 +157,8 @@ static_bootscript_add()
     local START_LEVELS=""
     local STOP_LEVELS=""
 
-    if [ "x${RCLEVEL}" = "xS" ]; then
-       START_LEVELS="S"
+    if [ "x${RCLEVEL}" = "xsysinit" ]; then
+       START_LEVELS="sysinit"
        STOP_LEVELS="0 6"
     elif [ "x${RCLEVEL}" = "x3" ]; then
        START_LEVELS="3 4 5"
@@ -149,18 +169,18 @@ static_bootscript_add()
     fi
     
     # Making sure bootscript has correct permissions
-    chmod -v 740 /etc/rc.d/init.d/${SCRIPTNAME} &&
+    chmod -v 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} &&
 
     # Removing any old links
-    for level in S 0 1 2 3 4 5 6; do
-        cd /etc/rc.d/rc${level}.d &&
+    for level in sysinit 0 1 2 3 4 5 6; do
+        cd ${LFS}/etc/rc.d/rc${level}.d &&
        rm -v -f $(find . -name "???${SCRIPTNAME}") || exit 1
     done &&
 
     if [ ${START} -ne 0 ]; then
        # Creating new start links
        for level in ${START_LEVELS}; do
-           cd /etc/rc.d/rc${level}.d &&
+           cd ${LFS}/etc/rc.d/rc${level}.d &&
            ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} || exit 1
        done
     fi &&
@@ -168,7 +188,7 @@ static_bootscript_add()
     if [ ${STOP} -ne 0 ]; then
        # Creating new stop links
        for level in ${STOP_LEVELS}; do
-           cd /etc/rc.d/rc${level}.d &&
+           cd ${LFS}/etc/rc.d/rc${level}.d &&
            ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} || exit 1
        done
     fi
@@ -188,21 +208,21 @@ bootscript_add_manual()
     local STOP=${4}
 
     # Making sure bootscript has correct permissions
-    chmod 740 /etc/rc.d/init.d/${SCRIPTNAME} &&
+    chmod 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} &&
 
     # Removing any old links
-    cd /etc/rc.d/rc${RCLEVEL}.d &&
+    cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d &&
     rm -v -f $(find . -name "???${SCRIPTNAME}") &&
 
     if [ ${START} -ne 0 ]; then
        # Creating new start link
-       cd /etc/rc.d/rc${RCLEVEL}.d &&
+       cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d &&
        ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} || exit 1
     fi &&
 
     if [ ${STOP} -ne 0 ]; then
        # Creating new stop link
-       cd /etc/rc.d/rc${RCLEVEL}.d &&
+       cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d &&
        ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} || exit 1
     fi
 }
@@ -222,9 +242,9 @@ bootscript_add_rc3()
 # Arg #1: script name
 # Arg #2: start number
 # Arg #3: stop number
-bootscript_add_rcS()
+bootscript_add_rcsysinit()
 {
-    static_bootscript_add ${*} S
+    static_bootscript_add ${*} sysinit
 }
 
 # Add "export" before the variable name
@@ -313,12 +333,11 @@ var_add()
     # PATH=... matches but not MANPATH=...
     if grep "^${VARIABLE}=\"" ${FILE} 1> /dev/null 2>&1; then
        # Variable value is enclosed by double-quotes
-       sed -i "s!\(^${VARIABLE}=\".*\)\(\"\)!\1${SEP}${VALUE}\"!" ${FILE}
+       sed -i "s!\(^${VARIABLE}=\".*\)\(\"\)!\1${SEP}${VALUE}\"!" ${FILE} || exit 1
     else
        # Variable value is NOT enclosed by double-quotes
-       sed -i "s!\(^${VARIABLE}=.*\)!\1${SEP}${VALUE}!" ${FILE}
+       sed -i "s!\(^${VARIABLE}=.*\)!\1${SEP}${VALUE}!" ${FILE} || exit 1
     fi
-    evaluate_retval
 
     # Adding new value to variable (case with export before)
     # We search for the variable name starting after an export statement,
@@ -428,14 +447,19 @@ hv_groupadd()
 {
     arguments=${*}
 
+    set +e
+
     while [ $# -ne 0 ]; do
        last_argument=${*}
        shift
     done
     
     groupadd ${arguments}
+    error=$?
 
-    if [ $? -eq 0 -o $? -eq 9 ]; then
+    set -e
+
+    if [ ${error} -eq 0 -o ${error} -eq 9 ]; then
         # 9 means the group already exists
         return ${EXIT_SUCCESS}
     else
@@ -449,6 +473,8 @@ hv_useradd()
 {
     arguments="${*}"
 
+    set +e
+
     # The last argument is the username
     while [ $# -ne 0 ]; do
        last_argument=${*}
@@ -456,8 +482,11 @@ hv_useradd()
     done
 
     useradd ${arguments}
+    error=$?
+
+    set -e
 
-    if [ $? -eq 0 -o $? -eq 9 ]; then
+    if [ ${error} -eq 0 -o ${error} -eq 9 ]; then
         # 9 means the user already exists
         return ${EXIT_SUCCESS}
     else
@@ -467,24 +496,10 @@ hv_useradd()
     
 # Evaluates the return value of the process that was run just before this
 # function was called.
-evaluate_retval()
+eval_retval()
 {
     if [ $? -ne 0 ]; then
-       echo "*************"
-       echo "*   ERROR   *"
-       echo "*************"
-       exit 1
-    fi
-}
-
-# Evaluates the return value of the process that was run just before this
-# function was called.
-eval_retval2()
-{
-    if [ $? -ne 0 ]; then
-        ${SET_CHECK_POSITION}
        print_status failure
-       echo
        exit ${EXIT_FAILURE}
     fi
 }
@@ -495,11 +510,37 @@ static_decompressed_dirname()
 {
     local PACKAGE=${1}
 
-    local DIRNAME=$(tar -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1 | awk -F \/ '{print $1}')
+    # Remove optional "./" leading component with sed
+    # and extract base directory name with awk.
+    local DIRNAME=$(tar ${TAR_OPTS} -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 | head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}')
 
     echo ${DIRNAME}
 }
 
+# Applying patch
+# First argument is the name of the patch
+# Second argument is the package name (target dir in $LFS_TMP)
+apply_patch()
+{
+    local PATCH_FILE=${1}
+    local TARGET_DIR=${2}
+
+    if [ -z "${PATCH_FILE}" ]; then
+        echo
+       echo "apply_patch(): no patch specified."
+       return ${EXIT_FAILURE}
+    fi
+
+    if [ ! -f ${LFS_PKG_DIR}/${PATCH_FILE} ]; then
+        echo
+       echo "${FUNCNAME}(): patch file '${PATCH_FILE}' not found."
+       return ${EXIT_FAILURE}
+    fi
+
+    echo "Applying patch: ${PATCH_FILE}"
+    patch -Np1 -d ${LFS_TMP}/${TARGET_DIR} -i ${LFS_PKG_DIR}/${PATCH_FILE}
+}
+
 # Applying any patch(es) found for the current package.
 # Will work only if patches have the same base name as
 # the package, followed by a dash:
@@ -529,40 +570,13 @@ apply_patches()
     if ls ${LFS_PKG_DIR}/${1}-*.patch 1> /dev/null 2>&1; then
        cd ${LFS_PKG_DIR}
        for patch in ${1}-*.patch; do
-           echo "Applying patch: ${patch}:"
-           patch -Np1 -d ${LFS_TMP}/${TARGET_DIR} -i ${LFS_PKG_DIR}/${patch} || exit 1
+            apply_patch ${patch} ${TARGET_DIR} || exit 1
        done
     fi
 
     return $?
 }
 
-# Applying patch
-# First argument is the name of the patch
-# Second argument is the package name
-apply_patch()
-{
-    PATCH_FILE=${1}
-    PACKAGE=${2}
-
-    if [ -z "${PATCH_FILE}" ]; then
-        echo
-       echo "apply_patch(): no patch specified."
-       return ${EXIT_FAILURE}
-    fi
-
-    if [ ! -f ${LFS_PKG_DIR}/${PATCH_FILE} ]; then
-        echo
-       echo "${FUNCNAME}(): patch file '${PATCH_FILE}' not found."
-       return ${EXIT_FAILURE}
-    fi
-
-    echo "******************************"
-    echo "* Applying patch: ${PATCH_FILE}"
-    echo "******************************"
-    patch -Np1 -d ${LFS_TMP}/${PACKAGE} -i ${LFS_PKG_DIR}/${PATCH_FILE}
-}
-
 # Decompression of a package
 # First argument: package name
 # Second argument: directory where decompressing (optional)
@@ -593,140 +607,19 @@ decompress_package()
     # Decompressing package
     # Option 'U' of tar is to remove each file prior to extracting over it
     cd ${TOPDIR} &&
-    tar -jxvf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 &&
+    tar ${TAR_OPTS} -jxvf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 &&
     cd - 1> /dev/null 2>&1
 }
 
-# Installation of a package, removing source and build directories after.
-#
-# First argument:  package name
-# Second argument: script name
-# Remaining arguments: additional configure options
-ipkg()
-{
-    # Checking for correct number of arguments
-    if [ $# -lt 2 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    local PACKAGE=${1}
-    shift
-    local CUSTOM_SCRIPT=${1}
-    shift
-    local CONFIGURE_OPTS=${*}
-
-    static_ipkg ${PACKAGE} ${CUSTOM_SCRIPT} ${PACKAGE} ${CONFIGURE_OPTS}
-}
-
-# Installation of a package conforming to GNU autotools.
-# The package must be able to be built outside the
-# source directory.
-#
-# First argument:      package name
-# Remaining arguments: additional configure options
-ipkg_ac()
-{
-    # Checking for correct number of arguments
-    if [ $# -lt 1 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    local PACKAGE=${1}
-    shift
-    local CONFIGURE_OPTS=${*}
-
-    static_ipkg ${PACKAGE} cis-ac ${PACKAGE} ${CONFIGURE_OPTS}
-}
-
-# Installation of a package conforming to GNU autotools,
-# but that must be built inside the source directory.
-#
-# First argument:      package name
-# Remaining arguments: additional configure options
-ipkg_ac_nb()
-{
-    # Checking for correct number of arguments
-    if [ $# -lt 1 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    local PACKAGE=${1}
-    shift
-    local CONFIGURE_OPTS=${*}
-
-    static_ipkg ${PACKAGE} cis-ac-nobuild ${PACKAGE} ${CONFIGURE_OPTS}
-}
-
-# Installation of a GNOME package.
-#
-# First argument:  package name
-ipkg_gnome()
-{
-    # Checking for correct number of arguments
-    if [ $# -ne 1 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    static_ipkg ${1} cis-gnome ${1}
-}
-
-# Installation of a PERL module
-#
-# First argument:  package name
-ipkg_pm()
-{
-    # Checking for correct number of arguments
-    if [ $# -ne 1 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    static_ipkg ${1} cis-pm ${1}
-}
-
-# Multiple installation of a package. This is usefull for packages
-# that may need to be installed multiple times, at different
-# times of the build process, like for GCC pas 1 and GCC pass 2.
-#
-# First argument:  Real package name
-# Second argument: Installation script name
-# Third argument:  Unique identification label in 'install.log'
-ipkg_mult()
-{
-    # Checking for correct number of arguments
-    if [ $# -ne 3 ]; then
-        echo
-       echo "${FUNCNAME}(): Wrong number of arguments"
-       echo "  command was: \"${FUNCNAME}() $*\""
-       exit ${EXIT_FAILURE}
-    fi
-
-    static_ipkg ${1} ${2} ${3}
-}
-
 # Installation of a package
 #
 # First argument:      Real package name
 # Second argument:     Installation script name
 # Third argument:      Unique identification label in 'install.log'
 # Remaining arguments: Additional configure options
-static_ipkg()
+ipkg()
 {
-    local START_TIME=$(echo `date +%s`)
+    START_TIME=$(echo `date +%s`)
     local PACKAGE_NAME=${1}
     local SCRIPT=./${2}
     local LABEL=${3}
@@ -760,20 +653,22 @@ static_ipkg()
     fi
     
     # Displaying label
-    echo -n "[ ] Installing" ${LABEL}" "
+    MSGSTRING="Installing ${LABEL}"
+    display_checkbox_msg ${MSGSTRING}
 
     echo "------------------------" 1>> ${LFS_LOG_FILE}
-    echo "Installing" ${LABEL} 1>> ${LFS_LOG_FILE}
+    echo "${MSGSTRING}" 1>> ${LFS_LOG_FILE}
 
     echo "Decompressing package" 1>> ${PACKAGE_LOG} 2>&1 &&
     decompress_package ${PACKAGE_NAME} 1> /dev/null 2>> ${PACKAGE_LOG}
-    eval_retval2
+    eval_retval
 
     local DECOMPRESSED_DIRNAME=$(static_decompressed_dirname ${PACKAGE_NAME})
 
     # Rename the decompressed package as per the package name if necessary
     if [ "x${DECOMPRESSED_DIRNAME}" != "x${PACKAGE_NAME}" ]; then
-        mv ${LFS_TMP}/${DECOMPRESSED_DIRNAME} ${LFS_TMP}/${PACKAGE_NAME} || exit 1
+        mv ${LFS_TMP}/${DECOMPRESSED_DIRNAME} ${LFS_TMP}/${PACKAGE_NAME}
+        eval_retval
     fi
 
     # Displaying package source size in log file
@@ -783,16 +678,16 @@ static_ipkg()
     if [ -d ${LFS_TMP}/${PACKAGE_NAME}-build ]; then
         echo "Removing old build directory" 1>> ${PACKAGE_LOG} 2>&1 &&
        rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1> /dev/null 2>> ${PACKAGE_LOG}
-        eval_retval2
+        eval_retval
     fi
 
     # Creating build directory
     mkdir -v ${LFS_TMP}/${PACKAGE_NAME}-build 1>> ${PACKAGE_LOG} 2>&1
-    eval_retval2
+    eval_retval
 
     # Executing script.
     ${SCRIPT} ${PACKAGE_NAME} ${CONFIGURE_OPTS} 1>> ${PACKAGE_LOG} 2>&1
-    eval_retval2
+    eval_retval
 
     # Displaying package build size in log file
     BUILD_SIZE=$(du -h -s -c ${LFS_TMP}/${PACKAGE_NAME} ${LFS_TMP}/${PACKAGE_NAME}-build | grep total | awk '{ print $1 }')
@@ -804,134 +699,163 @@ static_ipkg()
        # Removing source directory
         echo "Removing source directory" 1>> ${PACKAGE_LOG} 2>&1 &&
        rm -v -rf ${LFS_TMP}/${PACKAGE_NAME} 1> /dev/null 2>> ${PACKAGE_LOG}
-        eval_retval2
+        eval_retval
     fi
     if [ -d ${LFS_TMP}/${PACKAGE_NAME}-build ]; then
        # Removing build directory
         echo "Removing build directory" 1>> ${PACKAGE_LOG} 2>&1 &&
        rm -v -rf ${LFS_TMP}/${PACKAGE_NAME}-build 1> /dev/null 2>> ${PACKAGE_LOG}
-        eval_retval2
+        eval_retval
     fi
 
     # Writing success string to the end of the log file
     echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE}
 
     # Displaying build time after the package name
-    display_build_time ${START_TIME}
-
-    ${SET_CHECK_POSITION}
     print_status success
 
     return $EXIT_SUCCESS
 }
 
-# Display the action name, run a command, log its output and display it's
-# status
-# First argument: action name (string)
-# Remaining arguments: command name with it's options
-action_checkbox()
+# Installation of a package, removing source and build directories after.
+#
+# First argument:  package name
+# Second argument: script name
+# Remaining arguments: additional configure options
+ipkg_cust()
 {
-    # Displaying script name
-    echo -n "[ ]" $1
-    $SET_CHECK_POSITION
-    shift
-    echo $* 1>> ${LFS_LOG_FILE}
-
-    # Executing command
-    $* 1>> ${LFS_LOG_FILE} 2>&1
-    if [ $? -ne 0 ]; then
-       print_status failure
-       echo
+    # Checking for correct number of arguments
+    if [ $# -lt 2 ]; then
+        echo
+       echo "${FUNCNAME}(): Wrong number of arguments"
+       echo "  command was: \"${FUNCNAME}() $*\""
        exit ${EXIT_FAILURE}
     fi
 
-    print_status success
+    local PACKAGE=${1}
+    local CUSTOM_SCRIPT=${2}
+    local LABEL=${PACKAGE}
+    shift
+    shift
+    local CONFIGURE_OPTS=${*}
 
-    return $EXIT_SUCCESS
+    ipkg ${PACKAGE} ${CUSTOM_SCRIPT} ${LABEL} ${CONFIGURE_OPTS}
 }
 
-# Display the action name, run a command, log its output and display it's
-# status and the time it took to execute.
-# Note: In case of errors, this function returns an error code instead
-#       of exiting.
-# First argument: action name (string)
-# Remaining arguments: command name with it's options
-action_checkbox_time()
+# Installation of a package conforming to GNU autotools.
+# The package must be able to be built outside the
+# source directory.
+#
+# First argument:      package name
+# Remaining arguments: additional configure options
+ipkg_ac()
 {
-    START_TIME=$(echo `date +%s`)
+    # Checking for correct number of arguments
+    if [ $# -lt 1 ]; then
+        echo
+       echo "${FUNCNAME}(): Wrong number of arguments"
+       echo "  command was: \"${FUNCNAME}() $*\""
+       exit ${EXIT_FAILURE}
+    fi
 
-    # Displaying script name
-    echo -n "[ ]" $1" "
+    local PACKAGE=${1}
+    local LABEL=${PACKAGE}
     shift
-    echo $* 1>> ${LFS_LOG_FILE}
+    local CONFIGURE_OPTS=${*}
 
-    # Executing command
-    $* 1>> ${LFS_LOG_FILE} 2>&1
-    if [ $? -ne 0 ]; then
-       ${SET_CHECK_POSITION}
-       print_status failure
+    ipkg ${PACKAGE} cis-ac ${LABEL} ${CONFIGURE_OPTS}
+}
 
-       return ${EXIT_FAILURE}
-    else
-       # Displaying build time after the package name
-       display_build_time ${START_TIME}
-       
-       ${SET_CHECK_POSITION}
-       print_status success
-       
-       return $EXIT_SUCCESS
+# Installation of a package conforming to GNU autotools,
+# but that must be built inside the source directory.
+#
+# First argument:      package name
+# Remaining arguments: additional configure options
+ipkg_ac_nb()
+{
+    # Checking for correct number of arguments
+    if [ $# -lt 1 ]; then
+        echo
+       echo "${FUNCNAME}(): Wrong number of arguments"
+       echo "  command was: \"${FUNCNAME}() $*\""
+       exit ${EXIT_FAILURE}
     fi
+
+    local PACKAGE=${1}
+    local LABEL=${PACKAGE}
+    shift
+    local CONFIGURE_OPTS=${*}
+
+    ipkg ${PACKAGE} cis-ac-nobuild ${LABEL} ${CONFIGURE_OPTS}
 }
 
-# Display the action name, run a command, log its output and display it's
-# status. Write to install log file when successfully completed so it
-# won't be called again after a successfull installation.
-# First argument:  Message to display during action
-# Second argument: script name (will be label)
-run_script_log()
+# Installation of a GNOME package.
+#
+# First argument:  package name
+# Remaining arguments: additional configure options
+ipkg_gnome()
 {
-    MSGSTRING=${1}
-    SCRIPT=${2}
-    LABEL=${SCRIPT}
-
     # Checking for correct number of arguments
-    if [ $# -lt 2 ]; then
-       echo "${FUNCNAME}(): Missing argument"
+    if [ $# -ne 1 ]; then
+        echo
+       echo "${FUNCNAME}(): Wrong number of arguments"
+       echo "  command was: \"${FUNCNAME}() $*\""
        exit ${EXIT_FAILURE}
     fi
 
+    local PACKAGE=${1}
+    local LABEL=${PACKAGE}
     shift
-    shift
-    SCRIPT_ARGS=${*}
+    local CONFIGURE_OPTS=${*}
 
-    # Checking if script is valid and executable
-    if [ ! -x ./${SCRIPT} ]; then
-       echo "${FUNCNAME}(): script not found: ${SCRIPT}"
+    ipkg ${PACKAGE} cis-gnome ${LABEL} ${CONFIGURE_OPTS}
+}
+
+# Installation of a PERL module
+#
+# First argument:  package name
+ipkg_pm()
+{
+    # Checking for correct number of arguments
+    if [ $# -ne 1 ]; then
+        echo
+       echo "${FUNCNAME}(): Wrong number of arguments"
+       echo "  command was: \"${FUNCNAME}() $*\""
        exit ${EXIT_FAILURE}
     fi
 
-    PACKAGE_LOG=${LFS_LOG_DIR}/${LABEL}.log
+    local PACKAGE=${1}
+    local LABEL=${PACKAGE}
 
-    # Checking if package was previously successfully installed
-    if grep "^${LABEL} successfully installed" ${LFS_LOG_FILE} 1> /dev/null 2>&1;
-       then
-       return $EXIT_SUCCESS
+    ipkg ${PACKAGE} cis-pm ${LABEL}
+}
+
+# Run command, no log
+# First  argument: Message to display during script
+# Second argument: command + arguments
+rcmd()
+{
+    START_TIME=$(echo `date +%s`)
+
+    # Checking for correct number of arguments
+    if [ $# -lt 2 ]; then
+       echo "${FUNCNAME}(): Missing argument(s)"
+       exit ${EXIT_FAILURE}
     fi
-    
-    # Displaying script name
-    echo -n "[ ] ${MSGSTRING}"
-    echo "------------------------" 1>> ${LFS_LOG_FILE}
-    echo "Running " ${LABEL} 1>> ${LFS_LOG_FILE}
-    echo 1>> ${LFS_LOG_FILE}
 
-    # Executing command
-    ./${SCRIPT} ${SCRIPT_ARGS} 1>> ${PACKAGE_LOG} 2>&1
-    eval_retval2
+    local MSGSTRING=${1}
+    local CMD=${2}
+    shift
+    local CMD_WITH_ARGS=${*}
 
-    # Writing success string to the end of the log file
-    echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE}
+    display_checkbox_msg ${MSGSTRING}
+    echo ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE}
 
-    $SET_CHECK_POSITION
+    # Executing command
+    ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE} 2>&1
+    eval_retval
+
+    # Displaying build time after the package name
     print_status success
 
     return $EXIT_SUCCESS
@@ -940,40 +864,64 @@ run_script_log()
 # Display the action name, run a command, log its output and display it's
 # status. Write to install log file when successfully completed so it
 # won't be called again after a successfull installation.
-# First argument:  label (string)
-# Second argument: script name
-run_cmd_log()
+
+# First  argument: "once" -> script is run only once
+#                  "mult" -> script can be run more than once
+# Second argument: Message to display during script
+# Third  argument: script name (will be label)
+rscr()
 {
+    START_TIME=$(echo `date +%s`)
+
     # Checking for correct number of arguments
-    if [ $# -lt 2 ]; then
-       echo "${FUNCNAME}(): Missing argument"
+    if [ $# -lt 3 ]; then
+       echo "${FUNCNAME}(): Missing argument(s)"
        exit ${EXIT_FAILURE}
     fi
 
-    LABEL=${1}
+    SCRMODE=${1}
+    MSGSTRING=${2}
+    SCRIPT=${3}
+    LABEL=${SCRIPT}
+    shift
     shift
-    SCRIPT=${*}
+    SCRIPT_ARGS=${*}
 
-    # Checking if package was previously successfully installed
-    if grep "^${LABEL} successfully installed" ${LFS_LOG_FILE} 1> /dev/null 2>&1;
-       then
-       return $EXIT_SUCCESS
+    # Checking script mode:
+    if [ "x${SCRMODE}" != "xonce" -a "x${SCRMODE}" != "xmult" ]; then
+       echo "${FUNCNAME}(): First argument invalid, must be \"once\" or \"mult\" (\"${SCRMODE}\" given)"
+       exit ${EXIT_FAILURE}
     fi
-    
-    # Displaying script name
-    echo -n "[ ] ${LABEL}"
+
+    # Checking if script is valid and executable
+    if [ ! -x ./${SCRIPT} ]; then
+       echo "${FUNCNAME}(): script not found: ${SCRIPT}"
+       exit ${EXIT_FAILURE}
+    fi
+
+    PACKAGE_LOG=${LFS_LOG_DIR}/${LABEL}.log
+
+    if [ "x${SCRMODE}" = "xonce" ]; then
+        # Checking if package was previously successfully installed
+        if grep "^${LABEL} successfully installed" ${LFS_LOG_FILE} 1> /dev/null 2>&1; then
+           return $EXIT_SUCCESS
+        fi
+    fi
+
+    display_checkbox_msg ${MSGSTRING}
     echo "------------------------" 1>> ${LFS_LOG_FILE}
-    echo "${LABEL}" 1>> ${LFS_LOG_FILE}
-    echo 1>> ${LFS_LOG_FILE}
+    echo ${LABEL} 1>> ${LFS_LOG_FILE}
 
-    # Executing command
-    ${SCRIPT} 1>> ${LFS_LOG_FILE} 2>&1
-    eval_retval2
+    # Executing script
+    ./${SCRIPT} ${SCRIPT_ARGS} 1>> ${PACKAGE_LOG} 2>&1
+    eval_retval
 
-    # Writing success string to the end of the log file
-    echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE}
+    if [ "x${SCRMODE}" = "xonce" ]; then
+        # Writing success string to the end of the log file
+        echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE}
+    fi
 
-    $SET_CHECK_POSITION
+    # Displaying build time after the package name
     print_status success
 
     return $EXIT_SUCCESS
@@ -1006,12 +954,13 @@ get_total_build_time()
     echo "${HOURS}.${MIN}"
 }
 
+# Global variable: START_TIME
 display_build_time()
 {
     END_TIME=$(echo `date +%s`)
 
     HOURS=$(( ( ${END_TIME} - ${START_TIME} ) / 3600 ))
-    echo -n "("${HOURS}"."
+    echo -n " ("${HOURS}"."
     echo -n "  Build time: ${HOURS}." 1>> ${LFS_LOG_FILE}
 
     # Time is inferior to 1 hour...
@@ -1034,48 +983,51 @@ display_build_time()
     echo "h" 1>> ${LFS_LOG_FILE}
 }
 
+# Global variable: MSGSTRING
+display_checkbox_msg()
+{
+    echo -en "${BRACKET}[ ${BRACKET}]${NORMAL} ${MSGSTRING}"
+}
+
 # The print_status prints a coloured "X" letter inside the checkbox to the left
-# of the screen (the checkbox is displayed with the action_checkbox function).
+# of the screen (the checkbox is already displayed, and the cursor must have
+# been saved to where to put the mark).
+# 1st arg: status: success, warning or failure
+# Global variables: MSGSTRING and START_TIME
 print_status()
 {
-    if [ $# = 0 ]; then
+    if [ $# -ne 1 ]; then
         # If no parameters are given to the print_status function, print usage
         # information.
-       echo "Usage: ${FUNCNAME}() {success|warning|failure}"
+       echo "Usage: ${FUNCNAME}() {success|warning|failure} [STRING] [TIME]"
        return ${EXIT_FAILURE}
     fi
-    
-    case "$1" in
+
+    local COLOR=""
+
+    case "${1}" in
        success)
-           $SUCCESS
+           COLOR=$SUCCESS
            ;;
        warning)
-           $WARNING
+           COLOR=$WARNING
            ;;
        failure)
-           $FAILURE
+           COLOR=$FAILURE
            ;;
        *)
            echo "Usage: ${FUNCNAME}() {success|warning|failure}"
            return ${EXIT_FAILURE}
            ;;
     esac
-    echo "X"
-    $NORMAL 
-}
 
-# Testing GCC toolchain
-gcc_toolchain_test_stage1()
-{
-    cd ${LFS_TMP} &&
-    echo 'main(){}' > dummy.c &&
-    cc dummy.c &&
-    readelf -l a.out | grep ': /tools' 1> /dev/null 2>&1
+    # Reposition cursor at start of line
+    echo -en "${SET_CURSOR_START_LINE}"
+    echo -en "${BRACKET}[${COLOR}X${BRACKET}]${NORMAL} ${MSGSTRING}"
 
-    if [ $? -ne 0 ]; then
-        echo "Testing toolchain failed..."
-        exit 1
+    if [ "x${MSGSTRING}" != "x" ]; then
+        display_build_time
     fi
 
-    rm dummy.c a.out
+    echo
 }