general code cleanup in shell scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-03 12:59:35 +01:00
parent 334aa1f7c9
commit 5de8eda21c
9 changed files with 29 additions and 61 deletions

View File

@ -29,11 +29,8 @@ scan_config()
"${_fail}" "scan_config ${confdir}: Cannot concatenate files" "${_fail}" "scan_config ${confdir}: Cannot concatenate files"
while read -r line ; do while read -r line ; do
set ${line} 1>/dev/null 2>/dev/null || : set ${line} 1>/dev/null 2>/dev/null || :
if [ "${1%:}" = "depend" ]; then [ "${1%:}" = "depend" ] && depend="${depend} ${2}" && continue
depend="${depend} ${2}" eval "${1%:}=\"${2}\""
else
eval "${1%:}=\"${2}\""
fi
done << EOF done << EOF
$(eval "awk '${awkstr}' \"${revfile}\"") $(eval "awk '${awkstr}' \"${revfile}\"")
EOF EOF

View File

@ -20,22 +20,21 @@ main()
if [ "${1}" = "rp2040" ]; then if [ "${1}" = "rp2040" ]; then
platform="rp2040" platform="rp2040"
boards_dir=${pico_sdk_dir}/src/boards/include/boards boards_dir=${pico_sdk_dir}/src/boards/include/boards
[ -d "${pico_src_dir}/" ] || fetch_repo rpi-pico-serprog [ -d "${pico_src_dir}/" ] || \
x_ ./update project repo "rpi-pico-serprog"
elif [ "${1}" = "stm32" ]; then elif [ "${1}" = "stm32" ]; then
platform="stm32" platform="stm32"
boards_dir=${stm32_src_dir}/boards boards_dir=${stm32_src_dir}/boards
[ -d "${stm32_src_dir}/" ] || fetch_repo stm32-vserprog [ -d "${stm32_src_dir}/" ] || \
x_ ./update project repo "stm32-vserprog"
else else
err "${usage}" err "${usage}"
fi fi
x_ mkdir -p "bin/serprog_${platform}" x_ mkdir -p "bin/serprog_${platform}"
if [ $# -gt 1 ] ; then if [ $# -gt 1 ] ; then
if [ "${2}" = "list" ] ; then [ "${2}" = "list" ] && print_boards ${boards_dir} && return 0
print_boards ${boards_dir} build_${platform}_rom "${2}"
else
build_${platform}_rom "${2}"
fi
else else
printf "Building all serprog targets\n" printf "Building all serprog targets\n"
list_boards "${boards_dir}" | while read board; do list_boards "${boards_dir}" | while read board; do
@ -44,11 +43,6 @@ main()
fi fi
} }
fetch_repo()
{
x_ ./update project repo "${1}"
}
build_rp2040_rom() build_rp2040_rom()
{ {
board=${1} board=${1}

View File

@ -31,10 +31,8 @@ main()
init_check() init_check()
{ {
[ -f version ] && \ [ -f version ] && read version < version
read version < version [ -f versiondate ] && read versiondate < versiondate
[ -f versiondate ] && \
read versiondate < versiondate
[ ! -d "bin/" ] && \ [ ! -d "bin/" ] && \
err "init_check: no ROMs built yet (error)" err "init_check: no ROMs built yet (error)"
[ -d "release/" ] || \ [ -d "release/" ] || \
@ -106,9 +104,9 @@ make_archive()
strip_archive() strip_archive()
{ {
romdir=${1} romdir=${1}
[ -d "coreboot/${tree}" ] || \ [ -d "coreboot/${tree}" ] || \
x_ ./update project trees coreboot ${tree} x_ ./update project trees coreboot ${tree}
x_ ./build coreboot utils ${tree} x_ ./build coreboot utils ${tree}
if [ "${microcode_required}" = "n" ]; then if [ "${microcode_required}" = "n" ]; then
@ -125,12 +123,10 @@ strip_archive()
# Hash the rom before removing blobs # Hash the rom before removing blobs
x_ rm -f "${romdir}/blobhashes" x_ rm -f "${romdir}/blobhashes"
x_ touch "${romdir}/blobhashes" x_ touch "${romdir}/blobhashes"
( (
x_ cd "${romdir}" x_ cd "${romdir}"
x_ sha512sum *.rom >> blobhashes x_ sha512sum *.rom >> blobhashes
) )
for romfile in "${romdir}"/*.rom; do for romfile in "${romdir}"/*.rom; do
[ -f "${romfile}" ] || continue [ -f "${romfile}" ] || continue
strip_rom_image "${romfile}" strip_rom_image "${romfile}"

View File

@ -109,7 +109,7 @@ purge_files()
done done
x_ ./handle make file -c bios_extract flashrom grub uefitool \ x_ ./handle make file -c bios_extract flashrom grub uefitool \
util-fw/stm32-vserprog util-fw/stm32-vserprog/libopencm3 \ util-fw/stm32-vserprog util-fw/stm32-vserprog/libopencm3 \
memtest86plus/build* util/* \ memtest86plus/build* util/*
x_ rm -Rf .git* */.git* */*/.git* */*/*/.git* */*/*/*/.git* \ x_ rm -Rf .git* */.git* */*/.git* */*/*/.git* */*/*/*/.git* \
*/*/*/*/*/.git* */*/*/*/*/*/.git* */*/*/*/*/*/*/.git* */*/*/*/*/.git* */*/*/*/*/*/.git* */*/*/*/*/*/*/.git*

View File

@ -227,7 +227,6 @@ run_make_command()
copy_elf() copy_elf()
{ {
[ "${project}" != "coreboot" ] || xx_ modify_coreboot_rom [ "${project}" != "coreboot" ] || xx_ modify_coreboot_rom
while read f; do while read f; do
[ ! -f "${codedir}/$f" ] || \ [ ! -f "${codedir}/$f" ] || \
xx_ cp "${codedir}/${f}" "${dest_dir}/" xx_ cp "${codedir}/${f}" "${dest_dir}/"

View File

@ -46,12 +46,9 @@ run_make_command()
{ {
[ -f "${project}/Makefile" ] || [ -f "${project}/makefile" ] || \ [ -f "${project}/Makefile" ] || [ -f "${project}/makefile" ] || \
[ -f "${project}/GNUmakefile" ] || return 0 [ -f "${project}/GNUmakefile" ] || return 0
if [ -z "${mode}" ]; then [ -z "${mode}" ] && x_ make -C "${project}" -j$(nproc) && return 0
x_ make -C "${project}" -j$(nproc) x_ make -C "${project}" clean
else make -C "${project}" distclean 2>/dev/null || :
x_ make -C "${project}" clean
make -C "${project}" distclean 2>/dev/null || :
fi
} }
main $@ main $@

View File

@ -147,7 +147,7 @@ extract_e6400vga()
[ -f "${E6400_VGA_romname}" ] || \ [ -f "${E6400_VGA_romname}" ] || \
err "extract_e6400vga: can't extract vga rom from bios.bin" err "extract_e6400vga: can't extract vga rom from bios.bin"
) )
x_ cp "${appdir}"/"${E6400_VGA_romname}" "${_dest}" x_ cp "${appdir}/${E6400_VGA_romname}" "${_dest}"
} }
extract_sch5545ec() extract_sch5545ec()

View File

@ -96,13 +96,10 @@ build_dependencies()
inject_blobs() inject_blobs()
{ {
release_archive="n" release_archive="n"
if [ "${release}" = "true" ]; then [ "${release}" != "true" ] && x_ patch_rom "${rom}" && return 0
printf "patching release file\n" printf "patching release file\n"
release_archive="y" release_archive="y"
patch_release_roms patch_release_roms
else
x_ patch_rom "${rom}"
fi
} }
patch_release_roms() patch_release_roms()
@ -240,11 +237,9 @@ inject_blob_hp_kbc1126_ec()
if [ "${_ec1_offset}" = "" ] || [ "${_ec1_offset}" = "" ]; then if [ "${_ec1_offset}" = "" ] || [ "${_ec1_offset}" = "" ]; then
err "inject_blob_hp_kbc1126_ec: ${board}: offset not declared" err "inject_blob_hp_kbc1126_ec: ${board}: offset not declared"
fi elif [ "${_ec1_location}" = "" ] || [ "${_ec2_location}" = "" ]; then
if [ "${_ec1_location}" = "" ] || [ "${_ec2_location}" = "" ]; then
err "inject_blob_hp_kbc1126_ec: ${board}: EC path not declared" err "inject_blob_hp_kbc1126_ec: ${board}: EC path not declared"
fi elif [ ! -f "${_ec1_location}" ] || [ ! -f "${_ec2_location}" ]; then
if [ ! -f "${_ec1_location}" ] || [ ! -f "${_ec2_location}" ]; then
err "inject_blob_hp_kbc1126_ec: ${board}: ecfw not downloaded" err "inject_blob_hp_kbc1126_ec: ${board}: ecfw not downloaded"
fi fi

View File

@ -18,10 +18,9 @@ main()
printf "Downloading %s and applying patches\n" ${project} printf "Downloading %s and applying patches\n" ${project}
[ -z "${1}" ] && err "project name not specified" [ -z "${1}" ] && err "project name not specified"
project="${1}" project="${1}" && shift 1
cfgsdir="config/${project}" cfgsdir="config/${project}"
[ -d "${cfgsdir}" ] || err "unsupported project name" [ -d "${cfgsdir}" ] || err "unsupported project name"
shift 1
targets=$(listitems "${cfgsdir}") targets=$(listitems "${cfgsdir}")
[ $# -gt 0 ] && targets=$@ [ $# -gt 0 ] && targets=$@
@ -39,21 +38,16 @@ download_for_target()
tree="undefined" tree="undefined"
rev="undefined" rev="undefined"
fetch_config "${_target}" fetch_config
[ -d "${project}/${tree}" ] && printf "download/%s %s (%s): exists\n" \
"${project}" "${tree}" "${_target}" 1>&2 && return 0
if [ -d "${project}/${tree}" ]; then fetch_from_upstream
printf "REMARK: download/%s %s (%s): exists. Skipping.\n" \ prepare_new_tree
"${project}" "${tree}" "${_target}" 1>&2
else
fetch_from_upstream
prepare_new_tree
fi
} }
fetch_config() fetch_config()
{ {
_target=${1}
while true; do while true; do
eval "$(setvars "" rev tree)" eval "$(setvars "" rev tree)"
_xm="fetch_config ${project}/${_target}" _xm="fetch_config ${project}/${_target}"
@ -64,10 +58,7 @@ fetch_config()
. "${cfgsdir}/${_target}/target.cfg" || \ . "${cfgsdir}/${_target}/target.cfg" || \
err "fetch_config: no \"${cfgsdir}/${_target}/target.cfg\"" err "fetch_config: no \"${cfgsdir}/${_target}/target.cfg\""
if [ "${_target}" != "${tree}" ]; then [ "${_target}" != "${tree}" ] && _target="${tree}" && continue
_target="${tree}"
continue
fi
[ -z ${tree} ] && err "${_xm}: tree undefined" [ -z ${tree} ] && err "${_xm}: tree undefined"
[ -z ${rev} ] && err "${_xm}: revision undefined" [ -z ${rev} ] && err "${_xm}: revision undefined"
break break
@ -78,7 +69,6 @@ check_config_for_target()
{ {
[ -f "${cfgsdir}/${1}/target.cfg" ] || \ [ -f "${cfgsdir}/${1}/target.cfg" ] || \
err "${_xm} check: target.cfg does not exist" err "${_xm} check: target.cfg does not exist"
[ -f "${cfgsdir}/${1}/seen" ] && \ [ -f "${cfgsdir}/${1}/seen" ] && \
err "${_xm} check: infinite loop in tree definitions" err "${_xm} check: infinite loop in tree definitions"