From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CD7FC138334 for ; Sat, 23 Mar 2019 09:52:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B5223E09F8; Sat, 23 Mar 2019 09:52:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6BAD3E09F1 for ; Sat, 23 Mar 2019 09:52:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 14CC5335D08 for ; Sat, 23 Mar 2019 09:52:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BBC5357B for ; Sat, 23 Mar 2019 09:52:41 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1553328377.c8dc95cfa1dc79f1b3790ba35fb4233b6a444b90.whissi@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_funcs.sh X-VCS-Directories: / X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: c8dc95cfa1dc79f1b3790ba35fb4233b6a444b90 X-VCS-Branch: master Date: Sat, 23 Mar 2019 09:52:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 4deb11b8-e61c-430e-8c12-33bfe6b0c1d2 X-Archives-Hash: 486adcb2a870b61f525a84a702ac088e commit: c8dc95cfa1dc79f1b3790ba35fb4233b6a444b90 Author: Thomas Deutschmann gentoo org> AuthorDate: Sat Mar 23 01:27:42 2019 +0000 Commit: Thomas Deutschmann gentoo org> CommitDate: Sat Mar 23 08:06:17 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=c8dc95cf gen_funcs.sh: reformat code Signed-off-by: Thomas Deutschmann gentoo.org> gen_funcs.sh | 137 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/gen_funcs.sh b/gen_funcs.sh index c5eb28e..3f06584 100755 --- a/gen_funcs.sh +++ b/gen_funcs.sh @@ -23,22 +23,22 @@ isTrue() { } setColorVars() { -if isTrue "${USECOLOR}" -then - GOOD=$'\e[32;01m' - WARN=$'\e[33;01m' - BAD=$'\e[31;01m' - NORMAL=$'\e[0m' - BOLD=$'\e[0;01m' - UNDER=$'\e[4m' -else - GOOD='' - WARN='' - BAD='' - NORMAL='' - BOLD='' - UNDER='' -fi + if isTrue "${USECOLOR}" + then + GOOD=$'\e[32;01m' + WARN=$'\e[33;01m' + BAD=$'\e[31;01m' + NORMAL=$'\e[0m' + BOLD=$'\e[0;01m' + UNDER=$'\e[4m' + else + GOOD='' + WARN='' + BAD='' + NORMAL='' + BOLD='' + UNDER='' + fi } setColorVars @@ -154,13 +154,11 @@ print_info() { return 0 } -print_error() -{ +print_error() { GOOD=${BAD} print_info "$@" } -print_warning() -{ +print_warning() { GOOD=${WARN} print_info "$@" } @@ -169,29 +167,28 @@ print_warning() # $2 = variable value # $3 = string -var_replace() -{ - # Escape '\' and '.' in $2 to make it safe to use - # in the later sed expression - local SAFE_VAR - SAFE_VAR=`echo "${2}" | sed -e 's/\([\/\.]\)/\\\\\\1/g'` +var_replace() { + # Escape '\' and '.' in $2 to make it safe to use + # in the later sed expression + local SAFE_VAR + SAFE_VAR=`echo "${2}" | sed -e 's/\([\/\.]\)/\\\\\\1/g'` - echo "${3}" | sed -e "s/%%${1}%%/${SAFE_VAR}/g" - + echo "${3}" | sed -e "s/%%${1}%%/${SAFE_VAR}/g" - } arch_replace() { - var_replace "ARCH" "${ARCH}" "${1}" + var_replace "ARCH" "${ARCH}" "${1}" } cache_replace() { - var_replace "CACHE" "${CACHE_DIR}/${GK_V}" "${1}" + var_replace "CACHE" "${CACHE_DIR}/${GK_V}" "${1}" } clear_log() { - if [ -f "${LOGFILE}" ] - then - (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}." - fi + if [ -f "${LOGFILE}" ] + then + (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}." + fi } gen_die() { @@ -208,7 +205,7 @@ gen_die() { if isTrue "${USECOLOR}" then GREP_COLOR='1' grep -B5 -E --colour=always "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} \ - | sed -s "s|^\(*\)\?|${BAD}*${NORMAL}|" + | sed -s "s|^\(*\)\?|${BAD}*${NORMAL}|" else grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} fi @@ -227,8 +224,8 @@ gen_die() { print_error 1 '' # Cleanup temp dirs and caches if requested - isTrue "${CMD_DEBUGCLEANUP}" && cleanup - exit 1 + isTrue "${CMD_DEBUGCLEANUP}" && cleanup + exit 1 } getIndent() { @@ -248,40 +245,35 @@ getIndent() { echo "${_indent}" } -isBootRO() -{ +isBootRO() { return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts); } -setup_cache_dir() -{ - -[ ! -d "${CACHE_DIR}/${GK_V}" ] && mkdir -p "${CACHE_DIR}/${GK_V}" - -if isTrue "${CLEAR_CACHE_DIR}" -then - print_info 1 "Clearing cache dir contents from ${CACHE_DIR}" - while read i - do - print_info 1 "$(getIndent 1)>> removing ${i}" - rm "${i}" - done < <(find "${CACHE_DIR}" -maxdepth 2 -type f -name '*.tar.*' -o -name '*.bz2') -fi +setup_cache_dir() { + [ ! -d "${CACHE_DIR}/${GK_V}" ] && mkdir -p "${CACHE_DIR}/${GK_V}" + if isTrue "${CLEAR_CACHE_DIR}" + then + print_info 1 "Clearing cache dir contents from ${CACHE_DIR} ..." + while read i + do + print_info 1 "$(getIndent 1)>> removing ${i}" + rm "${i}" + done < <(find "${CACHE_DIR}" -maxdepth 2 -type f -name '*.tar.*' -o -name '*.bz2') + fi } -clear_tmpdir() -{ -if isTrue "${CMD_INSTALL}" -then - TMPDIR_CONTENTS=`ls ${TMPDIR}` - print_info 1 "Removing tmp dir contents" - for i in ${TMPDIR_CONTENTS} - do - print_info 1 " >> removing ${i}" - rm -r ${TMPDIR}/${i} - done -fi +clear_tmpdir() { + if isTrue "${CMD_INSTALL}" + then + TMPDIR_CONTENTS=`ls ${TMPDIR}` + print_info 1 "Removing tmp dir contents" + for i in ${TMPDIR_CONTENTS} + do + print_info 1 "$(getIndent 1)>> removing ${i}" + rm -r ${TMPDIR}/${i} + done + fi } # @@ -328,6 +320,7 @@ copy_image_with_preserve() { print_info 5 " Current ${symlinkName} symlink did not exist." print_info 5 " Defaulted to: ${currDestImage}" fi + if [ -e "${BOOTDIR}/${currDestImage}" ] then currDestImageExists=1 @@ -346,6 +339,7 @@ copy_image_with_preserve() { print_info 5 " Old ${symlinkName} symlink did not exist." print_info 5 " Defaulted to: ${prevDestImage}" fi + if [ -e "${BOOTDIR}/${prevDestImage}" ] then prevDestImageExists=1 @@ -358,7 +352,7 @@ copy_image_with_preserve() { fi # When symlinks are not being managed by genkernel, old symlinks might - # still be useful. Leave 'em alone unless managed. + # still be useful. Leave 'em alone unless managed. if isTrue "${SYMLINK}" then print_info 5 " Deleting old symlinks, if any." @@ -375,7 +369,7 @@ copy_image_with_preserve() { # # Case for new and currrent of the same base version. # - print_info 5 " Same base version. May have to delete old image to make room." + print_info 5 " Same base version. May have to delete old image to make room." if [ "${currDestImageExists}" = '1' ] then @@ -387,7 +381,7 @@ copy_image_with_preserve() { print_info 5 " Moving ${BOOTDIR}/${currDestImage}" print_info 5 " to ${BOOTDIR}/${currDestImage}.old" mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" || - gen_die "Could not rename the old ${symlinkName} image!" + gen_die "Could not rename the old ${symlinkName} image!" prevDestImage="${currDestImage}.old" prevDestImageExists=1 fi @@ -395,7 +389,7 @@ copy_image_with_preserve() { # # Case for new / current not of the same base version. # - print_info 5 " Different base version. Do not delete old images." + print_info 5 " Different base version. Do not delete old images." prevDestImage="${currDestImage}" currDestImage="${fullDestName}" fi @@ -403,7 +397,7 @@ copy_image_with_preserve() { print_info 5 " Copying ${symlinkName}: ${newSrceImage}" print_info 5 " to ${BOOTDIR}/${currDestImage}" cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" || - gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!" + gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!" if isTrue "${SYMLINK}" then @@ -411,12 +405,13 @@ copy_image_with_preserve() { print_info 5 " ${symlinkName} -> ${currDestImage}" pushd ${BOOTDIR} >/dev/null ln -s "${currDestImage}" "${symlinkName}" || - gen_die "Could not create the ${symlinkName} symlink!" + gen_die "Could not create the ${symlinkName} symlink!" + if [ "${prevDestImageExists}" = '1' ] then print_info 5 " ${symlinkName}.old -> ${prevDestImage}" ln -s "${prevDestImage}" "${symlinkName}.old" || - gen_die "Could not create the ${symlinkName}.old symlink!" + gen_die "Could not create the ${symlinkName}.old symlink!" fi popd >/dev/null fi