also clean up the main scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-08-22 00:34:15 +01:00
parent 62f23123cb
commit 04ee26726a
4 changed files with 37 additions and 77 deletions

54
fetch
View File

@ -15,25 +15,15 @@ depend=""
main() main()
{ {
if [ -z "${1+x}" ]; then [ -z "${1+x}" ] && err 'Error: name not set'
err 'Error: name not set'
fi
name=${1} name=${1}
read_config read_config
verify_config verify_config
clone_project clone_project
[ "${depend}" = "" ] || ./fetch ${depend} || exit 1
# 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 rm -Rf ${tmp_dir} >/dev/null 2>&1 || exit 1
} }
@ -44,20 +34,15 @@ read_config()
set ${line} >/dev/null 2>&1 set ${line} >/dev/null 2>&1
case ${line} in case ${line} in
rev:*) rev:*)
revision=${2} revision=${2} ;;
;;
loc:*) loc:*)
location=${2} location=${2} ;;
;;
url:*) url:*)
url=${2} url=${2} ;;
;;
bkup_url:*) bkup_url:*)
bkup_url=${2} bkup_url=${2} ;;
;;
depend:*) depend:*)
depend=${2} depend=${2} ;;
;;
esac esac
done << EOF done << EOF
$(eval "awk '${awkstr}' resources/git/revisions") $(eval "awk '${awkstr}' resources/git/revisions")
@ -66,32 +51,25 @@ EOF
verify_config() verify_config()
{ {
if [ -z "${revision+x}" ]; then [ -z "${revision+x}" ] && err 'Error: revision not set'
err 'Error: revision not set' [ -z "${location+x}" ] && err 'Error: location not set'
elif [ -z "${location+x}" ]; then [ -z "${url+x}" ] && err 'Error: url not set'
err 'Error: location not set'
elif [ -z "${url+x}" ]; then
err 'Error: url not set'
fi
} }
clone_project() clone_project()
{ {
tmp_dir=$(mktemp -dt "${name}_XXXXX") tmp_dir=$(mktemp -dt "${name}_XXXXX")
git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} \ git clone ${url} ${tmp_dir} || git clone ${bkup_url} ${tmp_dir} || \
|| err "ERROR: could not download ${name}" err "ERROR: could not download ${name}"
( (
cd ${tmp_dir} || err "tmpdir not created" cd ${tmp_dir} || err "tmpdir not created"
git reset --hard ${revision} || err "Cannot reset revision" git reset --hard ${revision} || err "Cannot reset revision"
) )
patch_project patch_project
if [ -d "${location}" ]; then [ ! -d "${location}" ] || \
rm -Rf ${location} || err "Cannot remove directory '${location}'" rm -Rf ${location} || err "Can't remove directory '${location}'"
fi
mv ${tmp_dir} ${location} && return 0 mv ${tmp_dir} ${location} && return 0
printf "ERROR: Could not copy temp file to destination.\n" printf "ERROR: Could not copy temp file to destination.\n"
@ -103,9 +81,7 @@ patch_project()
patchdir="resources/${name}/patches" patchdir="resources/${name}/patches"
for patchfile in ${PWD}/${patchdir}/*.patch ; do for patchfile in ${PWD}/${patchdir}/*.patch ; do
if [ ! -f "${patchfile}" ]; then [ -f "${patchfile}" ] || continue
continue
fi
( (
cd ${tmp_dir} || err "tmpdir not created" cd ${tmp_dir} || err "tmpdir not created"
git am ${patchfile} || err "Cannot patch project: $name" git am ${patchfile} || err "Cannot patch project: $name"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# helper script: create code trees based on git revision, with patches # helper script: create code trees based on git revision, with patches
# (currently used for downloading coreboot and u-boot) # (currently used for downloading coreboot, seabios and u-boot)
# #
# Copyright (C) 2014-2016,2020,2021,2023 Leah Rowe <info@minifree.org> # Copyright (C) 2014-2016,2020,2021,2023 Leah Rowe <info@minifree.org>
# Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com> # Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
@ -72,16 +72,14 @@ download_for_target()
if [ -d "${project}/${tree}" ]; then if [ -d "${project}/${tree}" ]; then
printf "REMARK: download/%s %s: exists. Skipping.\n" \ printf "REMARK: download/%s %s: exists. Skipping.\n" \
${project} ${tree} ${project} ${tree}
[ "${tree}" != "${1}" ] && \ [ "${tree}" != "${_target}" ] && \
printf "(for target: '%s}')\n" ${1} printf "(for target: '%s}')\n" ${_target}
return 0 return 0
fi fi
fetch_from_upstream || exit 1 fetch_from_upstream || exit 1
prepare_new_tree "${_target}" "${tree}" "${rev}" || exit 1
prepare_new_tree "${1}" "${tree}" "${rev}" \
|| exit 1
} }
fetch_config() fetch_config()
@ -135,14 +133,11 @@ check_config_for_target()
fetch_from_upstream() fetch_from_upstream()
{ {
[ ! -d "${project}" ] && \ [ -d "${project}" ] || mkdir -p "${project}"
mkdir -p "${project}" [ -d "${project}" ] || return 1
[ ! -d "${project}" ] && \ [ -d "${project}/${project}" ] && return 0
return 1
[ -d "${project}/${project}" ] && \ ./fetch ${project} || return 1
return 0
./fetch ${project} || \
return 1
} }
prepare_new_tree() prepare_new_tree()
@ -157,16 +152,14 @@ prepare_new_tree()
cp -R "${project}/${project}" "${project}/${tree}" || exit 1 cp -R "${project}/${project}" "${project}/${tree}" || exit 1
( (
cd "${project}/${tree}" \ cd "${project}/${tree}" || err "cannot cd to ${project}/${tree}"
|| err "cannot cd to ${project}/${tree}" git reset --hard ${rev} || \
git reset --hard ${rev} \ err "cannot reset ${project} revision for tree, ${tree}"
|| err "cannot reset ${project} revision for tree, ${tree}" git submodule update --init --checkout || \
git submodule update --init --checkout \ err "cannot update ${project} submodules for tree, ${tree}"
|| err "cannot update ${project} submodules for tree, ${tree}"
for patch in ../../"${cfgsdir}"/"${tree}"/patches/*.patch; do for patch in ../../"${cfgsdir}"/"${tree}"/patches/*.patch; do
[ ! -f "${patch}" ] && \ [ ! -f "${patch}" ] && continue
continue
if ! git am "${patch}"; then if ! git am "${patch}"; then
git am --abort git am --abort
err "cannot patch ${tree}" err "cannot patch ${tree}"

19
lbmk
View File

@ -31,23 +31,15 @@ option=""
main() main()
{ {
if [ "${0##*/}" = "lbmk" ]; then [ "${0##*/}" = "lbmk" ] && die "Don't run this script directly."
die "Do not run the lbmk script directly!" [ $# -lt 1 ] && die "Too few arguments. Try: ${0} help"
elif [ $# -lt 1 ]; then
die "Too few arguments. Try: ${0} help"
fi
buildpath="./resources/scripts/${0##*/}" buildpath="./resources/scripts/${0##*/}"
mode="${1}" mode="${1}"
./.gitcheck ./.gitcheck
if [ "${mode}" = help ]; then [ "${mode}" = "help" ] && usage ${0} && exit 0
usage $0 [ $# -lt 2 ] && usage ${0} && exit 1
exit 0
elif [ $# -lt 2 ]; then
usage $0
exit 1
fi
if [ "${mode}" = "dependencies" ]; then if [ "${mode}" = "dependencies" ]; then
install_dependencies $@ || die "Could not install dependencies" install_dependencies $@ || die "Could not install dependencies"
exit 0 exit 0
@ -61,8 +53,7 @@ main()
case "${option}" in case "${option}" in
list) list)
printf "Options for mode '%s':\n\n" ${mode} printf "Options for mode '%s':\n\n" ${mode}
listoptions "${mode}" listoptions "${mode}" ;;
;;
all) all)
for option in $(listoptions "${mode}"); do for option in $(listoptions "${mode}"); do
"${buildpath}/${mode}/${option}" $@ "${buildpath}/${mode}/${option}" $@

View File

@ -63,7 +63,7 @@ main()
project="${OPTARG}" project="${OPTARG}"
shift shift
done done
[ -z "${mode}" ] && err "mode not given (-m menuconfig or -u oldconfig)" [ -z "${mode}" ] && err "mode not given (-m, -u or -b)"
elfdir="elf/${project}" elfdir="elf/${project}"