X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions%2Fmain;h=720715753ca337327e367a56d8b06511b41be475;hb=b44c5a7a1987bdd5ac4cd1eea625d0539c0c9afd;hp=ae0d16303d5b6ba962f18b0b9d868db5cc29c1a9;hpb=fd7d0d6a1ec9d227e64d48ab65849a8061fc2fe2;p=hvlinux.git diff --git a/functions/main b/functions/main index ae0d163..7207157 100644 --- a/functions/main +++ b/functions/main @@ -49,6 +49,8 @@ source ./stage.def # Load functions source ../functions/fpkg +source ../functions/lpkg +source ../functions/version # Constants for return codes EXIT_SUCCESS=0 @@ -118,7 +120,7 @@ if [ -z "${LFS_STAGE}" ]; then return ${EXIT_FAILURE} fi -if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ] ;then +if [ "x${LFS_STAGE}" != "xstage0" -a "x${LFS_STAGE}" != "xstage1" ]; then LFS="" fi @@ -168,6 +170,20 @@ get_pkg_ver_base() echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\).*!\1!g" } +# Extracting the 3-digit version number from a complete package name. +# Arg. #1: Complete package name with version +# (ex: linux-2.6.37.1 will output 2.6.37) +get_pkg_ver3() +{ + # Checking for correct number of arguments + if [ $# -ne 1 ]; then + echo "${FUNCNAME}(), wrong number of arguments: ${*}" + return 1 + fi + + echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\.[0-9]*\).*!\1!g" +} + # Extracting the base version number from a complete package name. # Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3) get_pkg_ver_major() @@ -356,20 +372,20 @@ var_export() fi # Checking if variable exists - if ! grep "${VARIABLE}=" ${FILE} 1> /dev/null 2>&1; then + if ! grep -q "${VARIABLE}=" ${FILE}; then echo "${FUNCNAME}(), variable not found: ${VARIABLE}" return 1 fi # Checking if variable is already exported when it is defined - if grep "${VARIABLE}=" ${FILE} | grep "export " 1> /dev/null 2>&1; then + if grep "${VARIABLE}=" ${FILE} | grep -q "export "; then echo "${FUNCNAME}(), variable already exported in definition: ${VARIABLE}" return 0 fi # Checking if variable is already exported, in # a "export VARIABLE1 VARIABLE2..." statement - if grep "export " ${FILE} | grep " ${VARIABLE}" 1> /dev/null 2>&1; then + if grep "export " ${FILE} | grep -q " ${VARIABLE}"; then echo "${FUNCNAME}(), variable already exported in export list: ${VARIABLE}" return 0 fi @@ -403,13 +419,13 @@ var_add() fi # Checking if variable exists - if ! grep "${VARIABLE}=" ${FILE} 1> /dev/null 2>&1; then + if ! grep -q "${VARIABLE}=" ${FILE}; then echo "${VARIABLE}=\"${VALUE}\"" >> ${FILE} return $? fi # Checking if variable contains the new value - if grep "${VARIABLE}=" ${FILE} | grep "${VALUE}" 1> /dev/null 2>&1; then + if grep "${VARIABLE}=" ${FILE} | grep -q "${VALUE}"; then echo "${FUNCNAME}(), variable ${VARIABLE} already contains value: ${VALUE}" return 0 fi @@ -418,7 +434,7 @@ var_add() # We search for the variable name starting at the beginning of the line # For example, this ensures that if the variable name is PATH, then # PATH=... matches but not MANPATH=... - if grep "^${VARIABLE}=\"" ${FILE} 1> /dev/null 2>&1; then + if grep -q "^${VARIABLE}=\"" ${FILE}; then # Variable value is enclosed by double-quotes sed -i "s!\(^${VARIABLE}=\".*\)\(\"\)!\1${SEP}${VALUE}\"!" ${FILE} else @@ -431,7 +447,7 @@ var_add() # at the beginning of a line. # For example, this ensures that if the variable name is PATH, then # PATH=... matches but not MANPATH=... - if grep "^export ${VARIABLE}=\"" ${FILE} 1> /dev/null 2>&1; then + if grep -q "^export ${VARIABLE}=\"" ${FILE}; then # Variable value is enclosed by double-quotes sed -i "s!\(^export ${VARIABLE}=\".*\)\(\"\)!\1${SEP}${VALUE}\"!" ${FILE} else @@ -484,7 +500,7 @@ string_add() fi # Checking if string exists - if grep "${STRING}" ${FILE} 1> /dev/null 2>&1; then + if grep -q "${STRING}" ${FILE}; then echo "${FUNCNAME}(), string already defined: ${STRING}" return 0 fi @@ -516,7 +532,7 @@ var_add_shadow() fi # Checking if variable contains the new value - if egrep "^${VARIABLE}" ${FILE} | grep "${VALUE}" 1> /dev/null 2>&1; then + if egrep "^${VARIABLE}" ${FILE} | grep -q "${VALUE}"; then echo "${FUNCNAME}(), variable ${VARIABLE} already contains value: ${VALUE}" return 0 fi @@ -540,7 +556,7 @@ hv_groupadd() shift done - if ! cat /etc/group | egrep "^${groupname}:" 1> /dev/null 2>&1; then + if ! cat /etc/group | egrep -q "^${groupname}:"; then groupadd ${arguments} fi } @@ -557,7 +573,7 @@ hv_useradd() shift done - if ! cat /etc/passwd | egrep "^${username}:" 1> /dev/null 2>&1; then + if ! cat /etc/passwd | egrep -q "^${username}:"; then useradd ${arguments} fi } @@ -844,8 +860,7 @@ ipkg() PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log # Checking if package was previously successfully installed - if grep "^${HVLABEL} successfully installed" ${LFS_LOG_FILE} \ - 1> /dev/null 2>&1; then + if grep -q "^${HVLABEL} successfully installed" ${LFS_LOG_FILE}; then return $EXIT_SUCCESS fi @@ -926,17 +941,22 @@ rscr() exit ${EXIT_FAILURE} fi - # Checking if script is valid and executable - if [ ! -x ${SCRDIR}/${SCRIPT} ]; then + # Checking if script file is found + if [ ! -f ${SCRDIR}/${SCRIPT} ]; then echo "${FUNCNAME}(): script not found: ${SCRIPT}" exit ${EXIT_FAILURE} fi + # ... and make sure it is executable + if [ ! -x ${SCRDIR}/${SCRIPT} ]; then + echo "${FUNCNAME}(): execute bit not set: ${SCRIPT}" + exit ${EXIT_FAILURE} + fi PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log 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 + if grep -q "^${HVLABEL} successfully installed" ${LFS_LOG_FILE}; then return $EXIT_SUCCESS fi fi @@ -1106,7 +1126,8 @@ print_status() if [ $# -ne 1 ]; then # If no parameters are given to the print_status function, print usage # information. - echo "Usage: ${FUNCNAME}() {success|warning|failure} [STRING] [TIME]" + echo "Usage: ${FUNCNAME}() {success|warning|failure}" + echo " got: \"${*}\"" return ${EXIT_FAILURE} fi @@ -1139,3 +1160,24 @@ print_status() echo } + +# This function will exit if the stage is already completed +check_completed_stage() +{ + if [ -f ${LFS_LOG_DIR}/stage-completed ]; then + echo "${LFS_STAGE} completed" + exit 0 + else + return 0 + fi +} + +write_completed_stage() +{ + touch ${LFS_LOG_DIR}/stage-completed +} + +display_stage_build_stats() +{ + echo "Total build time: $(get_total_build_time ${LFS_LOG_FILE})h" +}