diff options
author | Leah Rowe <leah@libreboot.org> | 2023-08-17 11:41:58 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-08-17 11:50:06 +0100 |
commit | 0848622799b8c627cd650d848ffa7d592d80b26d (patch) | |
tree | 54c9c187d704abb83ba5c7a40f4bce2355b0e165 /fetch | |
parent | 8459e33bbcbe70cc08f449c3d46f1310c65680a1 (diff) |
remove download scripts, consolidate into script
most of them were just calling the gitclone script,
so remove them.
the grub script was treating gnulib as a dependency.
i've now added the ability to grab 1 dependency, in
the gitclone script (it should be expanded later to
support multiple dependencies)
the gitclone script has been renamed to "fetch".
the "fetch_trees" script does more or less the same
thing, but calls "fetch" and handles multiple revisions
if a project needs that
this is more efficient, and slightly reduces the code
size of lbmk!
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'fetch')
-rwxr-xr-x | fetch | 134 |
1 files changed, 134 insertions, 0 deletions
@@ -0,0 +1,134 @@ +#!/usr/bin/env sh + +# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com> +# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com> +# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org> +# SPDX-License-Identifier: GPL-3.0-only + +name="" +revision="" +location="" +url="" +bkup_url="" +tmp_dir="" +depend="" + +main() +{ + if [ -z "${1+x}" ]; then + err 'Error: name not set' + fi + + name=${1} + + read_config + verify_config + + clone_project + + # dependencies are downloaded *after* + # to account for cases like gnulib in grub where + # the dependency (gnulib) goes inside the main repo (grub) + if [ "${depend}" != "" ]; then + ./fetch ${depend} || exit 1 + fi + + # clean in case of failure + rm -Rf ${tmp_dir} >/dev/null 2>&1 || exit 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 + rev:*) + revision=${2} + ;; + loc:*) + location=${2} + ;; + url:*) + url=${2} + ;; + bkup_url:*) + bkup_url=${2} + ;; + depend:*) + depend=${2} + ;; + esac + done << EOF + $(eval "awk '${awkstr}' resources/git/revisions") +EOF +} + +verify_config() +{ + if [ -z "${revision+x}" ]; then + err 'Error: revision not set' + elif [ -z "${location+x}" ]; then + err 'Error: location not set' + elif [ -z "${url+x}" ]; then + err 'Error: url not set' + fi +} + +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}" + + ( + cd ${tmp_dir} || err "tmpdir not created" + git reset --hard ${revision} || err "Cannot reset revision" + ) + + patch_project + + if [ -d "${location}" ]; then + rm -Rf ${location} || err "Cannot remove directory '${location}'" + fi + mv ${tmp_dir} ${location} && return 0 + + printf "ERROR: Could not copy temp file to destination.\n" + err " ${tmp_dir} > ${location} check permissions" +} + +patch_project() +{ + patchdir="resources/${name}/patches" + + for patchfile in ${PWD}/${patchdir}/*.patch ; do + if [ ! -f "${patchfile}" ]; then + continue + fi + ( + cd ${tmp_dir} || err "tmpdir not created" + git am ${patchfile} || err "Cannot patch project: $name" + ) + done +} + +usage() +{ + cat <<- EOF + Usage: ./fetch [name] + + Options: + name: Module name as specified in resources/git/revisions + EOF +} + +err() +{ + printf "${@}\n" + usage + rm -Rf ${tmp_dir} >/dev/null 2>&1 + exit 1 +} + +main $@ |