From 385eb90c8cd31bfb770a950dd9252a30ccd6955d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 30 Sep 2023 01:31:40 +0100 Subject: [PATCH] update/*/*: unified scanning of revisions/sources update/blobs/download and update/project/repo both use the same logic, for setting variables with awk and a specially formatted configuration file. unify this logic under include/option.sh, and use that. Signed-off-by: Leah Rowe --- include/option.sh | 27 +++++++++++++++- script/update/blobs/download | 26 ++++++--------- script/update/project/repo | 62 ++++++++++-------------------------- 3 files changed, 51 insertions(+), 64 deletions(-) diff --git a/include/option.sh b/include/option.sh index 1f4f290f..98f91c51 100755 --- a/include/option.sh +++ b/include/option.sh @@ -1,4 +1,6 @@ -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2022 Caleb La Grange +# SPDX-FileCopyrightText: 2022 Ferass El Hafidi # SPDX-FileCopyrightText: 2023 Leah Rowe listitems() @@ -16,3 +18,26 @@ listitems() done return ${rval} } + +scan_config() +{ + awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }" + confdir="${2}" + _fail="${3}" + revfile="$(mktemp -t sources.XXXXXXXXXX)" || \ + "${_fail}" "scan_config: Cannot initialise tmpfile" + cat "${confdir}/"* > "${revfile}" || \ + "${_fail}" "scan_config: Cannot concatenate files" + while read -r line ; do + set ${line} 1>/dev/null 2>/dev/null || : + if [ "${1%:}" = "depend" ]; then + depend="${depend} ${2}" + else + eval "${1%:}=\"${2}\"" + fi + done << EOF + $(eval "awk '${awkstr}' \"${revfile}\"") +EOF + rm -f "${revfile}" || \ + "${_fail}" "scan_config: Cannot remove tmpfile" +} diff --git a/script/update/blobs/download b/script/update/blobs/download index 2ccf3b77..51747824 100755 --- a/script/update/blobs/download +++ b/script/update/blobs/download @@ -7,6 +7,7 @@ . "include/err.sh" . "include/blobutil.sh" . "include/mrc.sh" +. "include/option.sh" export PATH="${PATH}:/sbin" @@ -15,10 +16,11 @@ main() [ $# -gt 0 ] || err "No argument given" board="${1}" boarddir="${cbcfgsdir}/${board}" + _b="${board%%_*mb}" # shorthand (avoid duplicating config per rom size) check_defconfig "${boarddir}" || exit 0 detect_firmware && exit 0 - scan_sources_config + scan_config "${_b}" "config/blobs" "err" build_dependencies download_blobs @@ -36,29 +38,19 @@ detect_firmware() printf "Blobs not needed for: %s\n" "${board}" 1>&2 } -scan_sources_config() -{ - _b=${board%%_*mb} # shorthand to avoid duplicating config per rom size - awkstr=" /\{.*${_b}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }" - while read -r line ; do - set ${line} 1>/dev/null 2>/dev/null - eval "${1}=\"${2}\"" - done << EOF - $(eval "awk '${awkstr}' config/blobs/sources") -EOF -} - build_dependencies() { - [ -d ${cbdir} ] || ./update project trees coreboot ${cbdir##*/} || \ - err "build_dependencies: can't fetch ${cbdir}" + [ -d ${cbdir} ] || \ + ./update project trees coreboot ${cbdir##*/} || \ + err "build_dependencies: can't fetch ${cbdir}" for d in uefitool biosutilities bios_extract me_cleaner; do [ -d "${d}" ] && continue ./update project repo "${d}" || \ err "build_dependencies: can't fetch ${d}" done - [ -f uefitool/uefiextract ] || ./handle make file -b uefitool || \ - err "build_dependencies: can't build uefitool" + [ -f uefitool/uefiextract ] || \ + ./handle make file -b uefitool || \ + err "build_dependencies: can't build uefitool" [ -f "${cbdir}/util/kbc1126/kbc1126_ec_dump" ] || \ make -C "${cbdir}/util/kbc1126" || \ err "build_dependencies: can't build kbc1126_ec_dump" diff --git a/script/update/project/repo b/script/update/project/repo index 7e65ef29..4695b52b 100755 --- a/script/update/project/repo +++ b/script/update/project/repo @@ -6,10 +6,11 @@ . "include/err.sh" . "include/git.sh" +. "include/option.sh" name="" -revision="" -location="" +rev="" +loc="" url="" bkup_url="" tmp_dir="${PWD}/tmp/gitclone" @@ -22,7 +23,7 @@ main() [ -z "${1+x}" ] && fail 'main(): name not set' name=${1} - read_config + scan_config "${name}" "config/git" "fail" verify_config clone_project @@ -34,41 +35,10 @@ main() rm -Rf "${tmp_dir}" || fail "cannot remove tmpdir, ${tmp_dir}" } -read_config() -{ - revfile="$(mktemp -t gitrevisions.XXXXXXXXXX)" || \ - fail "read_config: Cannot initialise tmpfile" - - cat config/git/* > "${revfile}" || \ - fail "read_config: Cannot concatenate revision files" - - awkstr=" /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }" - while read -r line ; do - set ${line} || fail "read_config: set line" - case ${line} in - rev:*) - revision=${2} ;; - loc:*) - location=${2} ;; - url:*) - url=${2} ;; - bkup_url:*) - bkup_url=${2} ;; - depend:*) - depend="${depend} ${2} " ;; - esac - done << EOF - $(eval "awk \"${awkstr}\" \"${revfile}\"") -EOF - - rm -f "${revfile}" || \ - fail "read_config: can't remove tmp revfile" -} - verify_config() { - [ -z "${revision+x}" ] && fail 'verify_config: revision not set' - [ -z "${location+x}" ] && fail 'verify_config: location not set' + [ -z "${rev+x}" ] && fail 'verify_config: rev not set' + [ -z "${loc+x}" ] && fail 'verify_config: loc not set' [ -z "${url+x}" ] && fail 'verify_config: url not set' } @@ -79,24 +49,24 @@ clone_project() git clone ${url} "${tmp_dir}" || git clone ${bkup_url} "${tmp_dir}" || \ fail "clone_project: could not download ${name}" - git_reset_rev "${tmp_dir}" "${revision}" "fail" || \ - fail "clone_project ${location}/: cannot reset <- ${revision}" + git_reset_rev "${tmp_dir}" "${rev}" "fail" || \ + fail "clone_project ${loc}/: cannot reset <- ${rev}" git_am_patches "${tmp_dir}" "${PWD}/config/${name}/patches" "fail" || \ - fail "clone_project ${location}/: cannot apply patches" + fail "clone_project ${loc}/: cannot apply patches" - [ ! -d "${location}" ] || \ - rm -Rf "${location}" || \ - fail "clone_project: Can't remove directory '${location}'" - [ "${location}" = "${location%/*}" ] || mkdir -p ${location%/*} || \ + [ ! -d "${loc}" ] || \ + rm -Rf "${loc}" || \ + fail "clone_project: Can't remove directory '${loc}'" + [ "${loc}" = "${loc%/*}" ] || mkdir -p ${loc%/*} || \ fail "clone_project: cannot make directory for ${name}" - mv "${tmp_dir}" "${location}" || \ + mv "${tmp_dir}" "${loc}" || \ fail "clone_project: could not copy temp file to destination" } fail() { - for x in "${location}" "${tmp_dir}"; do - [ -z "${x}" ] || [ ! -d "${x}" ] || rm -Rf "${location}" || : + for x in "${loc}" "${tmp_dir}"; do + [ -z "${x}" ] || [ ! -d "${x}" ] || rm -Rf "${loc}" || : done usage err "${1}"