X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions;h=89230b9afcffb510a4338dd60240f80789ad403c;hb=f920c7ef750f2163b9e407cc453b192ede2c185a;hp=5d7d083cc24484d73a337d430e61db6d41e0c92a;hpb=aa229d2908422fce286bbd65710e31b086c8a2a2;p=hvlinux.git diff --git a/functions b/functions index 5d7d083..89230b9 100644 --- a/functions +++ b/functions @@ -1,6 +1,6 @@ -#!/bin/sh -# This file is 'sourced' by other scripts, therefore the above line is of no -# use, except when modifying the file in emacs to have syntax highlighting. +#!/bin/bash +set -o errtrace # Let shell functions inherit ERR trap. +set -o errexit # Constants for return codes EXIT_SUCCESS=0 @@ -22,6 +22,17 @@ BRACKET="\033[1;34m" TAR_OPTS="-b8" +# List of default archive extensions to try +MY_ARCH_EXT="tar.bz2 tar.gz tgz tar.Z zip" + +HV_FONTS_PATH="/usr/share/fonts" + +DEFAULT_EDITOR=nano + +DEFAULT_IPKG_SCRIPT="ipkg.def" + +source ./stage.def + # It seems that when compiling bash-4.0, using # "make -j 1" is causing problems... if [ "x${MAKEJOBS}" = "x1" ]; then @@ -31,14 +42,27 @@ else fi case "${HVL_TARGET}" in + arm*) + CLFS_BUILDFLAGS="-mabi=aapcs-linux -mfloat-abi=soft" + CLFS_TARGET="arm-linux-gnueabi" + CLFS_ARCH=$(echo ${CLFS_TARGET} | sed -e 's/-.*//' -e 's/arm.*/arm/g') + CLFS_ENDIAN=$(echo ${CLFS_ARCH} | sed -e 's/armeb/BIG/' -e 's/arm/LITTLE/') + if [ "${CLFS_ENDIAN}" = "LITTLE" ]; then + CLFS_NOT_ENDIAN="BIG" + else + CLFS_NOT_ENDIAN="LITTLE" + fi + ;; "x86_64") CLFS_BUILDFLAGS="-m64" CLFS_TARGET="${HVL_TARGET}-unknown-linux-gnu" + CLFS_ARCH=${HVL_TARGET} ;; "x86") # No special flags CLFS_BUILDFLAGS="" CLFS_TARGET="i686-unknown-linux-gnu" + CLFS_ARCH=${HVL_TARGET} ;; *) echo "Unsupported target architecture: ${HVL_TARGET}" @@ -46,8 +70,40 @@ case "${HVL_TARGET}" in ;; esac +CLFS_HOST="$(echo $MACHTYPE | \ + sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")" + +export CLFS_BUILDFLAGS CLFS_TARGET CLFS_ARCH CLFS_HOST CLFS_ENDIAN CLFS_NOT_ENDIAN + +if [ -z "${LFS_STAGE}" ]; then + echo "LFS_STAGE is undefined (see stage.def)" + return ${EXIT_FAILURE} +fi + +if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ] ;then + LFS="" +fi + CLFS=${LFS} +# Create log directory and log file for current stage if necessary +# This should be done automatically... +init_log_file() +{ + # Scripts directory + export SCRDIR=$(pwd) + + export LFS_PKG_DIR="$(dirname $(pwd))/packages/${LFS_STAGE}" + export LFS_LOG_DIR=${LFS}/var/log/hvlinux-install/${LFS_STAGE} + export LFS_LOG_FILE=${LFS_LOG_DIR}/install.log + export LFS_TMP="${LFS}/tmp" + + mkdir -p ${LFS_LOG_DIR} && + if [ ! -f ${LFS_LOG_FILE} ]; then + touch ${LFS_LOG_FILE} || exit 1 + fi +} + # 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() @@ -97,7 +153,10 @@ get_pkg_name() return 1 fi - echo ${1} | sed "s!^\(.*\)-.*!\1!g" + # SED do not support non-greedy regexp: + # We want to match any characters preceeding a dash followed by a number + # (shortest match -> non-greedy) + echo ${1} | sed "s!\([^-][^0-9]*\)-[0-9].*!\1!" } # Saves the content of CFLAGS and CXXFLAGS environment variables. @@ -131,16 +190,6 @@ restore_flags() return ${EXIT_SUCCESS} } -# Create log directory and log file for current stage if necessary -# This should be done automatically... -init_log_file() -{ - mkdir -p ${LFS_LOG_DIR} && - if [ ! -f ${LFS_LOG_FILE} ]; then - touch ${LFS_LOG_FILE} || exit 1 - fi -} - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: script name @@ -167,29 +216,29 @@ static_bootscript_add() echo "${FUNCNAME}(), invalid level argument : ${*}" return 1 fi - + # Making sure bootscript has correct permissions - chmod -v 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} && + chmod -v 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} # Removing any old links 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 && + cd ${LFS}/etc/rc.d/rc${level}.d + rm -v -f $(find . -name "???${SCRIPTNAME}") + done if [ ${START} -ne 0 ]; then # Creating new start links for level in ${START_LEVELS}; do - cd ${LFS}/etc/rc.d/rc${level}.d && - ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} || exit 1 + cd ${LFS}/etc/rc.d/rc${level}.d + ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} done - fi && + fi if [ ${STOP} -ne 0 ]; then # Creating new stop links for level in ${STOP_LEVELS}; do - cd ${LFS}/etc/rc.d/rc${level}.d && - ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} || exit 1 + cd ${LFS}/etc/rc.d/rc${level}.d + ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} done fi } @@ -208,22 +257,22 @@ bootscript_add_manual() local STOP=${4} # Making sure bootscript has correct permissions - chmod 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} && + chmod 740 ${LFS}/etc/rc.d/init.d/${SCRIPTNAME} # Removing any old links - cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d && - rm -v -f $(find . -name "???${SCRIPTNAME}") && + cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d + rm -v -f $(find . -name "???${SCRIPTNAME}") if [ ${START} -ne 0 ]; then # Creating new start link - cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d && - ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} || exit 1 - fi && + cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d + ln -v -s ../init.d/${SCRIPTNAME} S${START}${SCRIPTNAME} + fi if [ ${STOP} -ne 0 ]; then # Creating new stop link - cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d && - ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} || exit 1 + cd ${LFS}/etc/rc.d/rc${RCLEVEL}.d + ln -v -s ../init.d/${SCRIPTNAME} K${STOP}${SCRIPTNAME} fi } @@ -261,7 +310,7 @@ var_export() echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi - + # Checking if file exists if [ ! -f ${FILE} ]; then echo "${FUNCNAME}(), file not found: ${FILE}" @@ -308,7 +357,7 @@ var_add() echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi - + # Checking if file exists if [ ! -f ${FILE} ]; then echo "${FUNCNAME}(), file not found: ${FILE}" @@ -333,10 +382,10 @@ 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} || exit 1 + sed -i "s!\(^${VARIABLE}=\".*\)\(\"\)!\1${SEP}${VALUE}\"!" ${FILE} else # Variable value is NOT enclosed by double-quotes - sed -i "s!\(^${VARIABLE}=.*\)!\1${SEP}${VALUE}!" ${FILE} || exit 1 + sed -i "s!\(^${VARIABLE}=.*\)!\1${SEP}${VALUE}!" ${FILE} fi # Adding new value to variable (case with export before) @@ -351,7 +400,7 @@ var_add() # Variable value is NOT enclosed by double-quotes sed -i "s!\(^export ${VARIABLE}=.*\)!\1${SEP}${VALUE}!" ${FILE} fi - + return $? } @@ -389,7 +438,7 @@ string_add() echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi - + # Checking if file exists if [ ! -f ${FILE} ]; then echo "${FUNCNAME}(), file not found: ${FILE}" @@ -401,7 +450,7 @@ string_add() echo "${FUNCNAME}(), string already defined: ${STRING}" return 0 fi - + echo "${STRING}" >> ${FILE} } @@ -421,7 +470,7 @@ var_add_shadow() echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi - + # Checking if file exists if [ ! -f ${FILE} ]; then echo "${FUNCNAME}(), file not found: ${FILE}" @@ -447,23 +496,14 @@ hv_groupadd() { arguments=${*} - set +e - + # The last argument is the group name while [ $# -ne 0 ]; do - last_argument=${*} + groupname=${*} shift done - - groupadd ${arguments} - error=$? - set -e - - if [ ${error} -eq 0 -o ${error} -eq 9 ]; then - # 9 means the group already exists - return ${EXIT_SUCCESS} - else - exit ${EXIT_FAILURE} + if ! cat /etc/group | egrep "^${groupname}:" 1> /dev/null 2>&1; then + groupadd ${arguments} fi } @@ -473,49 +513,16 @@ hv_useradd() { arguments="${*}" - set +e - - # The last argument is the username + # The last argument is the user name while [ $# -ne 0 ]; do - last_argument=${*} + username=${*} shift done - useradd ${arguments} - error=$? - - set -e - - if [ ${error} -eq 0 -o ${error} -eq 9 ]; then - # 9 means the user already exists - return ${EXIT_SUCCESS} - else - exit ${EXIT_FAILURE} + if ! cat /etc/passwd | egrep "^${username}:" 1> /dev/null 2>&1; then + useradd ${arguments} fi } - -# Evaluates the return value of the process that was run just before this -# function was called. -eval_retval() -{ - if [ $? -ne 0 ]; then - print_status failure - exit ${EXIT_FAILURE} - fi -} - -# Obtain the name of the base directory for the decompressed package. -# First argument: package name -static_decompressed_dirname() -{ - local PACKAGE=${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 @@ -559,27 +566,62 @@ apply_patches() echo "Usage: ${FUNCNAME} PACKAGE-NAME" exit ${EXIT_FAILURE} fi - + if [ $# -eq 2 ]; then TARGET_DIR=${2} else TARGET_DIR=${PACKAGE} fi - + # Checking if we can find at least one patch. if ls ${LFS_PKG_DIR}/${1}-*.patch 1> /dev/null 2>&1; then cd ${LFS_PKG_DIR} for patch in ${1}-*.patch; do - apply_patch ${patch} ${TARGET_DIR} || exit 1 + apply_patch ${patch} ${TARGET_DIR} done fi return $? } +# Obtain the name of the base directory for the decompressed package. +# First argument: package name +static_decompressed_dirname() +{ + local PACKAGE=${1} + + for arch_ext in ${MY_ARCH_EXT}; do + if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ]; then + # Try next archive extension. + continue; + fi + + case ${arch_ext} in + tar.bz2|tar.gz|tgz|tar.Z) + # Remove optional "./" leading component with sed + # and extract base directory name with awk. + # tar 1.23 reports an error when using pipes, so + # remove error message with "2> /dev/null" + local DIRNAME=$(tar ${TAR_OPTS} -tf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 2> /dev/null | head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}') + echo ${DIRNAME} + ;; + zip) + # TODO + echo ${PACKAGE} + ;; + esac + + return $? + done + + # Failure or file not found + echo "${FUNCNAME}(): Missing source package for \"${PACKAGE}\"" > /dev/stderr + return ${EXIT_FAILURE} +} + # Decompression of a package # First argument: package name -# Second argument: directory where decompressing (optional) +# Second argument: directory where decompressing (optional, defaults to LFS_TMP) decompress_package() { # Checking for correct number of arguments @@ -594,38 +636,167 @@ decompress_package() local PACKAGE=${1} - if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 ]; then - echo "${FUNCNAME}(): Missing source package: \"${PACKAGE}.tar.bz2\"" > /dev/stderr - return ${EXIT_FAILURE} - fi - - if [ -d ${TOPDIR}/${PACKAGE} ]; then - # Removing old source directory (if any) - rm -v -rf ${TOPDIR}/${PACKAGE} || exit 1 - fi + for arch_ext in ${MY_ARCH_EXT}; do + if [ ! -f ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ]; then + # Try next archive extension. + continue; + fi + + if [ -d ${TOPDIR}/${PACKAGE} ]; then + # Removing old source directory (if any) + rm -rf ${TOPDIR}/${PACKAGE} + fi + + # Decompressing package + case ${arch_ext} in + tar.bz2) + tar -C ${TOPDIR} ${TAR_OPTS} -jxf \ + ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} + ;; + tar.gz|tgz|tar.Z) + tar -C ${TOPDIR} ${TAR_OPTS} -zxf \ + ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} + ;; + zip) + unzip -qq -d ${TOPDIR} ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} + ;; + esac + + return $? + done + + # Failure or file not found + echo "${FUNCNAME}(): Missing source package for \"${PACKAGE}\"" > /dev/stderr + return ${EXIT_FAILURE} +} - # Decompressing package - # Option 'U' of tar is to remove each file prior to extracting over it - cd ${TOPDIR} && - tar ${TAR_OPTS} -jxvf ${LFS_PKG_DIR}/${PACKAGE}.tar.bz2 && - cd - 1> /dev/null 2>&1 +hvtrap_setup() +{ + # Setting ERR trap does implicit `set -o errexit'. + trap hvtrap_err ERR + trap hvtrap_int INT +} + +hvtrap_err() +{ + echo + echo "*** An error occured during ${LFS_STAGE}" + exit 1 +} + +hvtrap_int() +{ + echo + echo "*** Installation interrupted during ${LFS_STAGE}" + exit 1 +} + +ipkg_trap_setup() +{ + exec 6>&1 # Save current "value" of stdout. + trap ipkg_trap_handler INT TERM EXIT ERR +} + +ipkg_trap_end() +{ + trap - INT TERM EXIT ERR + + # Restore global trap + hvtrap_setup +} + +ipkg_trap_handler() +{ + exec 1>&6 6>&- # Restore stdout and close file descriptor #6. + print_status failure + + ipkg_trap_end + exit 1 +} + +ipkg_display_build_infos() +{ + echo "hvlinux: configure options:" + for opt in ${CONFIGURE_OPTS}; do + echo " ${opt}" + done + echo "hvlinux: environment variables:" + echo " HOST: ${CLFS_HOST}" + echo " TARGET: ${CLFS_TARGET}" + echo " BUILD64: ${BUILD64}" + echo " CFLAGS: ${CFLAGS}" + echo " CPPFLAGS: ${CPPFLAGS}" + echo " CXXFLAGS: ${CFLAGS}" + echo " LDFLAGS: ${LDFLAGS}" + echo " RANLIB: ${RANLIB}" + echo " CC: ${CC}" + echo " CXX: ${CXX}" + echo " AR: ${AR}" + echo " AS: ${AS}" + echo " PATH: ${PATH}" } # Installation of a package -# -# First argument: Real package name -# Second argument: Installation script name -# Third argument: Unique identification label in 'install.log' +# Arg. #1: Package name and version (ex: gcc-4.5.1) # Remaining arguments: Additional configure options +# Options: +# -h Display this help and returns +# -l Unique identification label in 'install.log' +# (default is package name and version) +# -m Installation mode: +# ac Standard autoconf package, build in separate dir (default) +# acnb Standard autoconf package, build in source dir +# noac No autoconf (configure) +# gnome +# xorg +# pm +# -s Name of script to source (default is from name of package) ipkg() { START_TIME=$(echo `date +%s`) - local PACKAGE_NAME=${1} - local SCRIPT=./${2} - local LABEL=${3} - + + unset ALT_SCRIPT_NAME + export IPKG_MODE="ac" + export HVLABEL="" # Global variable + + while getopts "hl:m:s:" flag ;do + case ${flag} in + l) + # Alternate label + HVLABEL=${OPTARG} + ;; + m) + # Installation mode + case ${OPTARG} in + ac|acnb|noac|gnome|xorg|pm) + IPKG_MODE=${OPTARG} + ;; + *) + echo "${FUNCNAME}(): Unsupported mode: ${OPTARG}." + return 1 + ;; + esac + ;; + s) + # Alternate script name + ALT_SCRIPT_NAME=${OPTARG} + ;; + ?) + echo "${FUNCNAME}(): Invalid option: ${OPTARG}." + return 1 + ;; + esac + done + shift `expr "${OPTIND}" - 1` + + unset OPTSTRING + unset OPTIND + unset OPTARG + + export PACKAGE=${1} + # Checking for correct number of arguments - if [ $# -lt 3 ]; then + if [ $# -lt 1 ]; then echo echo "${FUNCNAME}(): Missing argument" echo " command was: \"${FUNCNAME}() $*\"" @@ -633,201 +804,158 @@ ipkg() fi shift - shift - shift - local CONFIGURE_OPTS=${*} + export CONFIGURE_OPTS=${*} - # Checking if script is valid and executable - if [ ! -x ${SCRIPT} ]; then - echo - echo "${FUNCNAME}(): script not found: ${SCRIPT}" - exit ${EXIT_FAILURE} + if [ -z "${HVLABEL}" ]; then + # Default label = package name and version + HVLABEL=${PACKAGE} fi - PACKAGE_LOG=${LFS_LOG_DIR}/${LABEL}.log + PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log # Checking if package was previously successfully installed - if grep "^${LABEL} successfully installed" ${LFS_LOG_FILE} \ - 1> /dev/null 2>&1; then + if grep "^${HVLABEL} successfully installed" ${LFS_LOG_FILE} \ + 1> /dev/null 2>&1; then return $EXIT_SUCCESS fi - + # Displaying label - MSGSTRING="Installing ${LABEL}" + MSGSTRING="Installing ${HVLABEL}" display_checkbox_msg ${MSGSTRING} + ipkg_trap_setup + echo "------------------------" 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_retval + exec 7>&1 # Save current "value" of stdout. + # All output from commands in this block sent to file $LFS_LOG_FILE. + exec >> ${LFS_LOG_FILE} 2>&1 + ipkg_display_build_infos + exec 1>&7 7>&- # Restore stdout and close file descriptor #7. - local DECOMPRESSED_DIRNAME=$(static_decompressed_dirname ${PACKAGE_NAME}) + # All output from commands in this block sent to file $PACKAGE_LOG. + exec > ${PACKAGE_LOG} 2>&1 - # 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} - eval_retval - fi + # Sourcing standard ac script. + source ${SCRDIR}/../functions-ipkg + source ${SCRDIR}/${DEFAULT_IPKG_SCRIPT} + ipkg_script ${ALT_SCRIPT_NAME} - # Displaying package source size in log file - echo " Source size:" $(du -h -s ${LFS_TMP}/${PACKAGE_NAME} | awk '{ print $1 }') 1>> ${LFS_LOG_FILE} + # Make sure we are at a known location + cd ${SCRDIR} - # Removing old build directory (if any) - 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_retval - fi - - # Creating build directory - mkdir -v ${LFS_TMP}/${PACKAGE_NAME}-build 1>> ${PACKAGE_LOG} 2>&1 - eval_retval - - # Executing script. - ${SCRIPT} ${PACKAGE_NAME} ${CONFIGURE_OPTS} 1>> ${PACKAGE_LOG} 2>&1 - 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 }') - echo " Build size : ${BUILD_SIZE}" 1>> ${LFS_LOG_FILE} - - # Some scripts need to preserve the source or build directory. They can - # do so by renaming them. - if [ -d ${LFS_TMP}/${PACKAGE_NAME} ]; then - # 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_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_retval - fi + exec 1>&6 # Restore stdout. # Writing success string to the end of the log file - echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE} + echo "${HVLABEL} successfully installed" 1>> ${LFS_LOG_FILE} # Displaying build time after the package name print_status success + ipkg_trap_end + return $EXIT_SUCCESS } -# 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() +# 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: "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 - echo "${FUNCNAME}(): Wrong number of arguments" - echo " command was: \"${FUNCNAME}() $*\"" + if [ $# -lt 3 ]; then + echo "${FUNCNAME}(): Missing argument(s)" exit ${EXIT_FAILURE} fi - local PACKAGE=${1} - local CUSTOM_SCRIPT=${2} - local LABEL=${PACKAGE} + SCRMODE=${1} + MSGSTRING=${2} + SCRIPT=${3} + HVLABEL=${SCRIPT} shift shift - local CONFIGURE_OPTS=${*} + SCRIPT_ARGS=${*} - ipkg ${PACKAGE} ${CUSTOM_SCRIPT} ${LABEL} ${CONFIGURE_OPTS} -} + # Make sure we are at a known location + cd ${SCRDIR} -# 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}() $*\"" + # 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 - local PACKAGE=${1} - local LABEL=${PACKAGE} - shift - local CONFIGURE_OPTS=${*} + # Checking if script is valid and executable + if [ ! -x ${SCRDIR}/${SCRIPT} ]; then + echo "${FUNCNAME}(): script not found: ${SCRIPT}" + exit ${EXIT_FAILURE} + fi - ipkg ${PACKAGE} cis-ac ${LABEL} ${CONFIGURE_OPTS} -} + PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log -# 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} + if [ "x${SCRMODE}" = "xonce" ]; then + # Checking if package was previously successfully installed + if grep "^${HVLABEL} successfully installed" ${LFS_LOG_FILE} 1> /dev/null 2>&1; then + return $EXIT_SUCCESS + fi fi - local PACKAGE=${1} - local LABEL=${PACKAGE} - shift - local CONFIGURE_OPTS=${*} + display_checkbox_msg ${MSGSTRING} - ipkg ${PACKAGE} cis-ac-nobuild ${LABEL} ${CONFIGURE_OPTS} -} + ipkg_trap_setup -# Installation of a GNOME package. -# -# First argument: package name -# Remaining arguments: additional configure options -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} + echo "------------------------" 1>> ${LFS_LOG_FILE} + echo ${HVLABEL} 1>> ${LFS_LOG_FILE} + + # Executing script + ${SCRDIR}/${SCRIPT} ${SCRIPT_ARGS} 1>> ${PACKAGE_LOG} 2>&1 + + if [ "x${SCRMODE}" = "xonce" ]; then + # Writing success string to the end of the log file + echo "${HVLABEL} successfully installed" 1>> ${LFS_LOG_FILE} fi - local PACKAGE=${1} - local LABEL=${PACKAGE} - shift - local CONFIGURE_OPTS=${*} + # Displaying build time after the package name + print_status success - ipkg ${PACKAGE} cis-gnome ${LABEL} ${CONFIGURE_OPTS} + ipkg_trap_end + + return $EXIT_SUCCESS } -# Installation of a PERL module -# -# First argument: package name -ipkg_pm() +rcmd_trap_setup() { - # 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 + exec 6>&1 # Save current "value" of stdout. + trap rcmd_trap_handler INT TERM EXIT ERR +} - local PACKAGE=${1} - local LABEL=${PACKAGE} +rcmd_trap_end() +{ + trap - INT TERM EXIT ERR - ipkg ${PACKAGE} cis-pm ${LABEL} + # We do not restore global trap +} + +rcmd_trap_handler() +{ + exec 1>&6 6>&- # Restore stdout to fd #6, where it had been saved, + # and close file descriptor #6. + print_status failure + + rcmd_trap_end + if [ -n "${RCMD_NO_EXIT}" ]; then + return ${EXIT_FAILURE} + else + exit ${EXIT_FAILURE} + fi } # Run command, no log @@ -849,12 +977,15 @@ rcmd() local CMD_WITH_ARGS=${*} display_checkbox_msg ${MSGSTRING} + + rcmd_trap_setup + echo ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE} # Executing command ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE} 2>&1 + if [ $? -ne 0 ]; then - print_status failure if [ -n "${RCMD_NO_EXIT}" ]; then return ${EXIT_FAILURE} else @@ -865,71 +996,7 @@ rcmd() # Displaying build time after the package name print_status success - return $EXIT_SUCCESS -} - -# 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: "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 3 ]; then - echo "${FUNCNAME}(): Missing argument(s)" - exit ${EXIT_FAILURE} - fi - - SCRMODE=${1} - MSGSTRING=${2} - SCRIPT=${3} - LABEL=${SCRIPT} - shift - shift - SCRIPT_ARGS=${*} - - # 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 - - # 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} - - # Executing script - ./${SCRIPT} ${SCRIPT_ARGS} 1>> ${PACKAGE_LOG} 2>&1 - eval_retval - - if [ "x${SCRMODE}" = "xonce" ]; then - # Writing success string to the end of the log file - echo "${LABEL} successfully installed" 1>> ${LFS_LOG_FILE} - fi - - # Displaying build time after the package name - print_status success + rcmd_trap_end return $EXIT_SUCCESS } @@ -1030,6 +1097,7 @@ print_status() # Reposition cursor at start of line echo -en "${SET_CURSOR_START_LINE}" + # Display colored 'X' echo -en "${BRACKET}[${COLOR}X${BRACKET}]${NORMAL} ${MSGSTRING}" if [ "x${MSGSTRING}" != "x" ]; then