summaryrefslogtreecommitdiff
path: root/gitclone
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-05-18 12:55:34 +0100
committerLeah Rowe <leah@libreboot.org>2023-05-18 12:55:34 +0100
commitfd2ca12e9e9b6eb476033bf6db37d6c27436b97b (patch)
treecda915f259ae2cd8b811bebaf3c34c47f97e9d84 /gitclone
parent08ad9eb15f17c29c148c212e0c995a5eda1eba49 (diff)
gitclone: split logic out of main()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'gitclone')
-rwxr-xr-xgitclone50
1 files changed, 27 insertions, 23 deletions
diff --git a/gitclone b/gitclone
index 0d16301c..779597b4 100755
--- a/gitclone
+++ b/gitclone
@@ -18,8 +18,19 @@ main()
fi
name=${1}
- awkstr=" /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
+ read_config
+ verify_config
+
+ clone_project
+
+ # clean in case of failure
+ rm -rf ${tmp_dir} >/dev/null 2>&1
+}
+
+read_config()
+{
+ awkstr=" /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
while read -r line ; do
set ${line} >/dev/null 2>&1
case ${line} in
@@ -39,22 +50,9 @@ main()
done << EOF
$(eval "awk '${awkstr}' resources/git/revisions")
EOF
-
- check_project
- tmp_dir=$(mktemp -dt "${name}_XXXXX")
-
- # clean out old version just in case
- if [ -d "${location}" ]; then
- rm -rf ${location}
- fi
-
- clone_project
-
- # clean in case of failure
- rm -rf ${tmp_dir} >/dev/null 2>&1
}
-check_project()
+verify_config()
{
if [ -z "${revision+x}" ]; then
err 'Error: revision not set'
@@ -69,6 +67,13 @@ check_project()
clone_project()
{
+ tmp_dir=$(mktemp -dt "${name}_XXXXX")
+
+ # clean out old version just in case
+ if [ -d "${location}" ]; then
+ rm -rf ${location}
+ fi
+
git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} \
|| err "ERROR: could not download ${name}"
@@ -76,12 +81,8 @@ clone_project()
cd ${tmp_dir} || err "Could not access tmp directory."
git reset --hard ${revision}
)
- patchdir="resources/${name}/patches"
-
- if [ -d "${patchdir}" ]; then
- patch_project || err "ERROR: errd to patch ${name}"
- fi
-
+
+ patch_project
mv ${tmp_dir} ${location} && return 0
printf "ERROR: Could not copy temp file to destination.\n"
@@ -90,12 +91,15 @@ clone_project()
patch_project()
{
+ patchdir="resources/${name}/patches"
+
for patchfile in ${PWD}/${patchdir}/*.patch ; do
if [ ! -f "${patchfile}" ]; then
continue
fi
- ( cd ${tmp_dir}
- git am ${patchfile} || return 1
+ (
+ cd ${tmp_dir}
+ git am ${patchfile} || err "Cannot patch project: $name"
)
done
}