X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions%2Fmain;h=ec42a712b83ec1e0f0adaf2e15b6c4fd5240b422;hb=dff56959345f54833fc1d4490de870737f151e5a;hp=76aa3a057cf8d78ab20b16f2820b3e9466c26dfb;hpb=9b734560ce02e626f7ea58ea9153b5e8daa00831;p=hvlinux.git diff --git a/functions/main b/functions/main index 76aa3a0..ec42a71 100644 --- a/functions/main +++ b/functions/main @@ -372,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 @@ -419,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 @@ -434,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 @@ -447,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 @@ -500,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 @@ -532,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 @@ -556,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 } @@ -573,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 } @@ -650,23 +650,27 @@ static_decompressed_dirname() continue; fi + local DIRNAME="" + 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 \ + DIRNAME=$(tar ${TAR_OPTS} -tf \ ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} 2> /dev/null | \ head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}') - echo ${DIRNAME} ;; zip) - # TODO - echo ${PACKAGE} + DIRNAME=$(unzip -l \ + ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} | head -n4 | \ + sed '$!d' | awk -F " " '{print $4}' | sed 's!/$!!') ;; esac + echo ${DIRNAME} + return $? done @@ -860,8 +864,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 @@ -957,7 +960,7 @@ rscr() 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 @@ -1161,3 +1164,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" +}