From 57adbc6eb1f961ee9116904b667f30efb3f2de4f Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 23 Aug 2023 18:56:31 +0100 Subject: unify err functions across scripts include/err.sh this new handling also does mundane things, such as tell you what script b0rked Signed-off-by: Leah Rowe --- fetch | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'fetch') diff --git a/fetch b/fetch index 4466d4ee..a8ec96de 100755 --- a/fetch +++ b/fetch @@ -5,6 +5,8 @@ # SPDX-FileCopyrightText: 2023 Leah Rowe # SPDX-License-Identifier: GPL-3.0-only +. "include/err.sh" + name="" revision="" location="" @@ -15,7 +17,7 @@ depend="" main() { - [ -z "${1+x}" ] && err 'Error: name not set' + [ -z "${1+x}" ] && fail 'Error: name not set' name=${1} read_config @@ -51,9 +53,9 @@ EOF verify_config() { - [ -z "${revision+x}" ] && err 'Error: revision not set' - [ -z "${location+x}" ] && err 'Error: location not set' - [ -z "${url+x}" ] && err 'Error: url not set' + [ -z "${revision+x}" ] && fail 'Error: revision not set' + [ -z "${location+x}" ] && fail 'Error: location not set' + [ -z "${url+x}" ] && fail 'Error: url not set' } clone_project() @@ -61,19 +63,19 @@ clone_project() tmp_dir=$(mktemp -dt "${name}_XXXXX") git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} || \ - err "ERROR: could not download ${name}" + fail "ERROR: could not download ${name}" ( - cd ${tmp_dir} || err "tmpdir not created" - git reset --hard ${revision} || err "Cannot reset revision" + cd ${tmp_dir} || fail "tmpdir not created" + git reset --hard ${revision} || fail "Cannot reset revision" ) patch_project [ ! -d "${location}" ] || \ - rm -Rf ${location} || err "Can't remove directory '${location}'" + rm -Rf ${location} || fail "Can't remove directory '${location}'" mv ${tmp_dir} ${location} && return 0 printf "ERROR: Could not copy temp file to destination.\n" - err " ${tmp_dir} > ${location} check permissions" + fail " ${tmp_dir} > ${location} check permissions" } patch_project() @@ -83,12 +85,19 @@ patch_project() for patchfile in ${PWD}/${patchdir}/*.patch ; do [ -f "${patchfile}" ] || continue ( - cd ${tmp_dir} || err "tmpdir not created" - git am ${patchfile} || err "Cannot patch project: $name" + cd ${tmp_dir} || fail "tmpdir not created" + git am ${patchfile} || fail "Cannot patch project: $name" ) done } +fail() +{ + usage + rm -Rf "${tmp_dir}" > /dev/null 2>&1 | : + err "${1}" +} + usage() { cat <<- EOF @@ -99,12 +108,4 @@ usage() EOF } -err() -{ - printf "${@}\n" - usage - rm -Rf ${tmp_dir} >/dev/null 2>&1 - exit 1 -} - main $@ -- cgit v1.2.1