2022-12-28 18:29:18 +00:00
|
|
|
#!/usr/bin/env sh
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
2022-12-28 18:29:18 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
|
2022-11-14 00:51:12 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2023-05-06 16:15:14 +00:00
|
|
|
name=""
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
Print_help(){
|
|
|
|
cat <<- EOF
|
2023-03-17 23:08:12 +00:00
|
|
|
Usage: ./gitclone [name]
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
Options:
|
|
|
|
name: The name of the module as specified in resources/git/revisions file
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
Fail(){
|
|
|
|
printf "${@}\n"
|
|
|
|
Print_help
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
Check_vars(){
|
|
|
|
if [ -z "${revision+x}" ]; then
|
|
|
|
Fail 'Error: revision not set'
|
|
|
|
fi
|
|
|
|
if [ -z "${location+x}" ]; then
|
|
|
|
Fail 'Error: location not set'
|
|
|
|
fi
|
|
|
|
if [ -z "${url+x}" ]; then
|
|
|
|
Fail 'Error: url not set'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
Patch(){
|
|
|
|
for patchfile in ${PWD}/${patchdir}/*.patch ; do
|
2023-05-14 10:33:50 +00:00
|
|
|
if [ ! -f "${patchfile}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
( cd ${tmp_dir}
|
|
|
|
git am ${patchfile} || return 1
|
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
Run(){
|
|
|
|
git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} || Fail "ERROR: couldn't download ${name}\n Check Network connection"
|
|
|
|
( cd ${tmp_dir} && git reset --hard ${revision} )
|
|
|
|
patchdir="resources/${name}/patches"
|
|
|
|
|
|
|
|
if [ -d "${patchdir}" ]; then
|
|
|
|
Patch || Fail "ERROR: Faild to patch ${name}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv ${tmp_dir} ${location} || Fail "ERROR: couldn't copy temp to destination\n ${tmp_dir} > ${location} check permissions"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "${1+x}" ]; then
|
|
|
|
Fail 'Error: name not set'
|
|
|
|
else
|
|
|
|
name=${1}
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
2022-12-28 18:29:18 +00:00
|
|
|
done << EOF
|
|
|
|
$(eval "awk ' /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }' resources/git/revisions")
|
|
|
|
EOF
|
2022-11-14 00:51:12 +00:00
|
|
|
Check_vars
|
|
|
|
tmp_dir=$(mktemp -dt "${name}_XXXXX")
|
|
|
|
|
|
|
|
# clean out old version just in case
|
|
|
|
if [ -d "${location}" ]; then
|
|
|
|
rm -rf ${location}
|
|
|
|
fi
|
|
|
|
|
|
|
|
Run
|
|
|
|
|
|
|
|
# clean in case of failure
|
|
|
|
rm -rf ${tmp_dir} >/dev/null 2>&1
|