summaryrefslogtreecommitdiff
path: root/fetch
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-08-23 18:56:31 +0100
committerLeah Rowe <leah@libreboot.org>2023-08-23 19:12:00 +0100
commit57adbc6eb1f961ee9116904b667f30efb3f2de4f (patch)
tree73cff95e43ecbab6db374160ec5657b2853c6826 /fetch
parentb3fbcdf66eb6225128e2578788e085e1b1eedf34 (diff)
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 <leah@libreboot.org>
Diffstat (limited to 'fetch')
-rwxr-xr-xfetch39
1 files changed, 20 insertions, 19 deletions
diff --git a/fetch b/fetch
index 4466d4ee..a8ec96de 100755
--- a/fetch
+++ b/fetch
@@ -5,6 +5,8 @@
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
# 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 $@