2023-06-13 11:09:01 +00:00
|
|
|
#!/usr/bin/env sh
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
2023-06-13 11:09:01 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
|
2023-05-18 12:19:38 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
|
2022-11-14 00:51:12 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2023-05-06 16:15:14 +00:00
|
|
|
name=""
|
2023-05-18 11:34:47 +00:00
|
|
|
revision=""
|
|
|
|
location=""
|
|
|
|
url=""
|
|
|
|
bkup_url=""
|
|
|
|
tmp_dir=""
|
2023-05-06 16:15:14 +00:00
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
main()
|
|
|
|
{
|
|
|
|
if [ -z "${1+x}" ]; then
|
|
|
|
err 'Error: name not set'
|
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
name=${1}
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-18 11:55:34 +00:00
|
|
|
read_config
|
|
|
|
verify_config
|
|
|
|
|
|
|
|
clone_project
|
|
|
|
|
|
|
|
# clean in case of failure
|
2023-05-18 12:01:12 +00:00
|
|
|
rm -rf ${tmp_dir} >/dev/null 2>&1 || exit 1
|
2023-05-18 11:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
read_config()
|
|
|
|
{
|
|
|
|
awkstr=" /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
|
2023-05-18 11:34:47 +00:00
|
|
|
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}
|
|
|
|
;;
|
|
|
|
esac
|
2023-06-13 11:09:01 +00:00
|
|
|
done << EOF
|
|
|
|
$(eval "awk '${awkstr}' resources/git/revisions")
|
|
|
|
EOF
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 11:55:34 +00:00
|
|
|
verify_config()
|
2023-05-18 11:34:47 +00:00
|
|
|
{
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ -z "${revision+x}" ]; then
|
2023-05-18 11:34:47 +00:00
|
|
|
err 'Error: revision not set'
|
2023-05-18 11:56:42 +00:00
|
|
|
elif [ -z "${location+x}" ]; then
|
2023-05-18 11:34:47 +00:00
|
|
|
err 'Error: location not set'
|
2023-05-18 11:56:42 +00:00
|
|
|
elif [ -z "${url+x}" ]; then
|
2023-05-18 11:34:47 +00:00
|
|
|
err 'Error: url not set'
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
clone_project()
|
|
|
|
{
|
2023-05-18 11:55:34 +00:00
|
|
|
tmp_dir=$(mktemp -dt "${name}_XXXXX")
|
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} \
|
|
|
|
|| err "ERROR: could not download ${name}"
|
|
|
|
|
|
|
|
(
|
2023-05-18 12:01:12 +00:00
|
|
|
cd ${tmp_dir} || exit 1
|
|
|
|
git reset --hard ${revision} || err "Cannot reset revision"
|
2023-05-18 11:34:47 +00:00
|
|
|
)
|
2023-05-18 11:55:34 +00:00
|
|
|
|
|
|
|
patch_project
|
2023-05-18 12:03:28 +00:00
|
|
|
|
|
|
|
if [ -d "${location}" ]; then
|
|
|
|
rm -Rf ${location} || exit 1
|
|
|
|
fi
|
2023-05-18 11:34:47 +00:00
|
|
|
mv ${tmp_dir} ${location} && return 0
|
|
|
|
|
|
|
|
printf "ERROR: Could not copy temp file to destination.\n"
|
|
|
|
err " ${tmp_dir} > ${location} check permissions"
|
|
|
|
}
|
|
|
|
|
|
|
|
patch_project()
|
|
|
|
{
|
2023-05-18 11:55:34 +00:00
|
|
|
patchdir="resources/${name}/patches"
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
for patchfile in ${PWD}/${patchdir}/*.patch ; do
|
2023-05-14 10:33:50 +00:00
|
|
|
if [ ! -f "${patchfile}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2023-05-18 11:55:34 +00:00
|
|
|
(
|
2023-05-18 12:01:12 +00:00
|
|
|
cd ${tmp_dir} || exit 1
|
2023-05-18 11:55:34 +00:00
|
|
|
git am ${patchfile} || err "Cannot patch project: $name"
|
2022-11-14 00:51:12 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<- EOF
|
|
|
|
Usage: ./gitclone [name]
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
Options:
|
|
|
|
name: Module name as specified in resources/git/revisions
|
|
|
|
EOF
|
|
|
|
}
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
err()
|
|
|
|
{
|
|
|
|
printf "${@}\n"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-18 11:34:47 +00:00
|
|
|
main $@
|