From 1eb4df6748f94a08d44c623a56417199b99b371d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 16 Dec 2023 07:56:26 +0000 Subject: [PATCH] fix several shellcheck warnings lbmk didn't quote certain arguments in commands, or used ! -z instead of -n, things like that. simple fixes. Signed-off-by: Leah Rowe --- include/err.sh | 12 ++++++------ include/git.sh | 2 +- script/build/grub | 2 +- script/build/roms | 8 ++++---- script/build/serprog | 10 +++++----- script/update/release | 12 ++++++------ script/update/trees | 16 ++++++++-------- script/vendor/download | 12 ++++++------ script/vendor/inject | 11 ++++++----- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/include/err.sh b/include/err.sh index 595d6c77..3699d6ce 100755 --- a/include/err.sh +++ b/include/err.sh @@ -36,23 +36,23 @@ git_err() check_project() { - read projectname < projectname || : + read -r projectname < projectname || : - [ ! -f version ] || read version < version || : + [ ! -f version ] || read -r version < version || : version_="${version}" [ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \ version="git-$(git rev-parse HEAD 2>&1)" || version="${version_}" - [ ! -f versiondate ] || read versiondate < versiondate || : + [ ! -f versiondate ] || read -r versiondate < versiondate || : versiondate_="${versiondate}" [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ --pretty='%ct' HEAD)" || versiondate="${versiondate_}" - [ ! -z ${versiondate} ] || fail "Unknown version date" || \ + [ -n "${versiondate}" ] || fail "Unknown version date" || \ err "Unknown version date" - [ ! -z ${version} ] || fail "Unknown version" || \ + [ -n "${version}" ] || fail "Unknown version" || \ err "Unknown version" - [ ! -z ${projectname} ] || fail "Unknown project" || \ + [ -n "${projectname}" ] || fail "Unknown project" || \ err "Unknown project" xx_ printf "%s\n" "${version}" > version || \ diff --git a/include/git.sh b/include/git.sh index 811b298a..9a73bd92 100755 --- a/include/git.sh +++ b/include/git.sh @@ -123,7 +123,7 @@ clone_project() [ "${patchfail}" = "y" ] && err "PATCH FAIL" x_ rm -Rf "${loc}" - [ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*} + [ "${loc}" = "${loc%/*}" ] || x_ mkdir -p "${loc%/*}" mv "${tmp_git_dir}" "${loc}" || \ err "clone_project: !mv ${tmp_git_dir} ${loc}" } diff --git a/script/build/grub b/script/build/grub index 5fa47c00..dc489838 100755 --- a/script/build/grub +++ b/script/build/grub @@ -45,7 +45,7 @@ build_keymap_configs() { for keylayoutfile in "${grubcfgsdir}/keymap/"*.gkb; do [ -f "${keylayoutfile}" ] || continue - keymap="${keylayoutfile##${grubcfgsdir}/keymap/}" + keymap="${keylayoutfile##"${grubcfgsdir}/keymap/"}" keymap="${keymap%.gkb}" printf "keymap %s\n" "${keymap}" > \ "${elfdir}/keymap_${keymap}.cfg" || err "!insert keymap" diff --git a/script/build/roms b/script/build/roms index a96ad89b..c1bca851 100755 --- a/script/build/roms +++ b/script/build/roms @@ -64,7 +64,7 @@ main() [ -z "${targets}" ] && err "No ROM images were compiled" printf "\nROM images available in these directories:\n" - printf "${targets}^^ ROM images available in these directories.\n\n" + printf "%s^^ ROM images available in these directories.\n\n" "${targets}" printf "DO NOT flash ROM images from elf/ - please use bin/ instead.\n" } @@ -230,7 +230,7 @@ build_roms() _cbrom="elf/coreboot_nopayload_DO_NOT_FLASH/${board}/${initmode}_${displaymode}" [ "${initmode}" = "normal" ] && \ - _cbrom="${_cbrom%_${displaymode}}" + _cbrom="${_cbrom%"_${displaymode}"}" _cbrom="${_cbrom}/coreboot.rom" cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)" x_ cp "${_cbrom}" "${cbrom}" @@ -349,7 +349,7 @@ mkSeabiosRom() { x_ cp "${_cbrom}" "${tmprom}" x_ "${cbfstool}" "${tmprom}" add-payload -f "${_seabioself}" \ - -n ${_seabios_cbfs_path} -c lzma + -n "${_seabios_cbfs_path}" -c lzma x_ "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup z="2"; [ "${initmode}" = "vgarom" ] && z="0" @@ -405,7 +405,7 @@ mkUbootRom() { x_ cp "${_cbrom}" "${tmprom}" x_ "${cbfstool}" "${tmprom}" add-payload -f "${_ubootelf}" \ - -n ${_uboot_cbfs_path} -c lzma + -n "${_uboot_cbfs_path}" -c lzma printf "%s\n" "${tmprom}" } diff --git a/script/build/serprog b/script/build/serprog index 7f8664a9..33319de6 100755 --- a/script/build/serprog +++ b/script/build/serprog @@ -50,24 +50,24 @@ main() build_rp2040_rom() { board=${1} - printf "Building pico-serprog for ${board}\n" + printf "Building pico-serprog for %s\n" "${board}" x_ cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \ -B "${pico_src_dir}/build" "${pico_src_dir}" x_ cmake --build "${pico_src_dir}/build" x_ mv ${pico_src_dir}/build/pico_serprog.uf2 \ bin/serprog_rp2040/serprog_${board}.uf2 - printf "output to bin/serprog_rp2040/serprog_${board}.uf2\n" + printf "output to bin/serprog_rp2040/serprog_%s.uf2\n" "${board}" } build_stm32_rom() { board=${1} - printf "Building stm32-vserprog for ${board}\n" + printf "Building stm32-vserprog for %s\n" "${board}" x_ make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board} x_ make -C ${stm32_src_dir} BOARD=${board} x_ mv ${stm32_src_dir}/stm32-vserprog.hex \ bin/serprog_stm32/serprog_${board}.hex - printf "output to bin/serprog_stm32/serprog_${board}.hex\n" + printf "output to bin/serprog_stm32/serprog_%s.hex\n" "${board}" } print_boards() @@ -78,7 +78,7 @@ print_boards() list_boards() { - basename -a -s .h ${1}/*.h + basename -a -s .h "${1}/"*.h } main $@ diff --git a/script/update/release b/script/update/release index 447d93ce..7dafbe32 100755 --- a/script/update/release +++ b/script/update/release @@ -209,12 +209,12 @@ nukerom() touch "${romdir}/vendorhashes" || err "!touch ${romdir}/vendorhashes" ( cd "${romdir}" || err "!cd romdir ${romdir}, nukerom" - sha512sum *.rom >> vendorhashes || err "!create vendorhashes, nukerom" + sha512sum ./*.rom >> vendorhashes || err "!create vendorhashes, nukerom" ) || err "can't create vendor hashes" for romfile in "${romdir}"/*.rom; do [ -f "${romfile}" ] || continue - ./vendor inject -r "${romfile}" -b ${target} -n nuke || \ + ./vendor inject -r "${romfile}" -b "${target}" -n nuke || \ err "!vendor inject (nuke) ${romfile}, nukerom" done } @@ -255,13 +255,13 @@ mkrom_tarball() f="release/${version}/roms/${archivename}" mkdir -p "${f%/*}" || err "mkrom_tarball: !mkdir -p ${f%/*}" ( - cd "${romdir%/bin/${target}}" || err "!cd ${romdir%/bin/${target}}" + cd "${romdir%"/bin/${target}"}" || err "!cd ${romdir%"/bin/${target}"}" mktarball "bin/${target}" "${archivename}.tar.xz" ) || err "can't create rom tarball" - mv "${romdir%/bin/${target}}/${archivename}.tar.xz"* "${f%/*}" || \ - err "!mktarball, rom, ${f%/*}/${romdir%/bin/${target}}/${archivename}.tar.xz" + mv "${romdir%"/bin/${target}"}/${archivename}.tar.xz"* "${f%/*}" || \ + err "!mktarball, rom, ${f%/*}/${romdir%"/bin/${target}"}/${archivename}.tar.xz" - printf "Created ROM archive: ${f%/*}/${archivename}.tar.xz" + printf "Created ROM archive: %s" "${f%/*}/${archivename}.tar.xz" } insert_version_files() diff --git a/script/update/trees b/script/update/trees index 1719aab9..0810c625 100755 --- a/script/update/trees +++ b/script/update/trees @@ -99,7 +99,7 @@ handle_targets() target="${x}" printf "Running 'make %s' for project '%s, target '%s''\n" \ "${mode}" "${project}" "${target}" - [ "${project}" != "coreboot" ] || [ ! -z ${mode} ] || \ + [ "${project}" != "coreboot" ] || [ -n "${mode}" ] || \ x_ ./vendor download ${target} x_ handle_defconfig done @@ -121,14 +121,14 @@ handle_defconfig() for y in "${target_dir}/config"/*; do [ -f "${y}" ] || continue config="${y}" - config_name="${config#${target_dir}/config/}" + config_name="${config#"${target_dir}/config/"}" printf "handle/make/config %s %s: handling config %s\n" \ "${project}" "${target}" "${config_name}" - [ ! -z ${mode} ] || check_config || continue + [ -n "${mode}" ] || check_config || continue handle_makefile - [ ! -z ${mode} ] || copy_elf + [ -n "${mode}" ] || copy_elf done } @@ -235,7 +235,7 @@ handle_makefile() { x_ make clean -C "${codedir}" x_ cp "${config}" "${codedir}/.config" - [ ! -z ${mode} ] || make -C "${codedir}" silentoldconfig || \ + [ -n "${mode}" ] || make -C "${codedir}" silentoldconfig || \ make -C "${codedir}" oldconfig || : run_make_command || err "handle_makefile ${codedir}: no makefile!" @@ -256,7 +256,7 @@ run_make_command() [ -f "${codedir}/Makefile" ] || [ -f "${codedir}/makefile" ] || \ [ -f "${codedir}/GNUmakefile" ] || return 1 [ "${project}" = "coreboot" ] && [ -z "${mode}" ] && \ - x_ printf "%s\n" "${version%%-*}" >"${codedir}/.coreboot-version" + x_ printf "%s\n" "${version%%-*}" >"$codedir/.coreboot-version" x_ make ${mode} -j$(nproc) -C "${codedir}" @@ -266,10 +266,10 @@ run_make_command() copy_elf() { - while read f; do + while read -r f; do [ ! -f "${codedir}/$f" ] || \ x_ cp "${codedir}/${f}" "${dest_dir}/" - done < ${listfile} + done < "${listfile}" x_ make clean -C "${codedir}" } diff --git a/script/vendor/download b/script/vendor/download index eada2e91..9431c441 100755 --- a/script/vendor/download +++ b/script/vendor/download @@ -54,7 +54,7 @@ detect_firmware() build_dependencies() { - [ -d ${cbdir} ] || \ + [ -d "${cbdir}" ] || \ x_ ./update trees -f coreboot ${cbdir##*/} for d in uefitool biosutilities bios_extract; do [ -d "src/${d}" ] && continue @@ -132,7 +132,7 @@ fetch() vendor_checksum() { - [ "$(sha512sum ${2} | awk '{print $1}')" != "${1}" ] || return 0 + [ "$(sha512sum "${2}" | awk '{print $1}')" != "${1}" ] || return 0 printf "Bad checksum for file: %s\n" "${2}" 1>&2 rm -f "${2}" || : return 1 @@ -141,7 +141,7 @@ vendor_checksum() mkdirs() { if [ -f "${1}" ]; then - printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 + printf "mkdirs %s %s: already downloaded\n" "${1}" "${2}" 1>&2 return 1 fi mkdir -p "${1%/*}" || err "mkdirs: !mkdir -p ${1%/*}" @@ -188,7 +188,7 @@ extract_intel_me() fi cdir="${1}" [ "${cdir#/a}" != "${cdir}" ] && cdir="${cdir#/}" - cd "${cdir}" + cd "${cdir}" || : done ) rm -Rf "${sdir}" || err "extract_intel_me: !rm -Rf ${sdir}" @@ -227,9 +227,9 @@ extract_kbc1126ec() extract_e6400vga() { - [ "${E6400_VGA_offset}" = "" ] && \ + [ -z "${E6400_VGA_offset}" ] && \ err "extract_e6400vga: E6400 VGA offset not defined" - [ "${E6400_VGA_romname}" = "" ] && \ + [ -z "${E6400_VGA_romname}" ] && \ err "extract_e6400vga: E6400 VGA ROM name not defined" tail -c +${E6400_VGA_offset} "${_dl}" | \ gunzip >"${appdir}/bios.bin" || : diff --git a/script/vendor/inject b/script/vendor/inject index 2e125f4f..e740704a 100755 --- a/script/vendor/inject +++ b/script/vendor/inject @@ -28,6 +28,7 @@ main() b) board=${OPTARG} ;; m) modifygbe=true new_mac=${OPTARG} ;; + *) : ;; esac done @@ -48,7 +49,7 @@ check_board() err "check_board: \"${rom}\" is not a valid path" [ -z "${rom+x}" ] && \ err "check_board: no rom specified" - [ ! -z ${board+x} ] || \ + [ -n "${board+x}" ] || \ board=$(detect_board "${rom}") else release="y" @@ -72,7 +73,7 @@ check_release() detect_board() { path="${1}" - filename=$(basename ${path}) + filename=$(basename "${path}") case ${filename} in grub_*) board=$(echo "${filename}" | cut -d '_' -f2-3) ;; @@ -185,12 +186,12 @@ patch_rom() "${CONFIG_KBC1126_FW1_OFFSET}" && \ inject "ecfw2.bin" "$CONFIG_KBC1126_FW2" "raw" \ "${CONFIG_KBC1126_FW2_OFFSET}" - [ ! -z "${CONFIG_VGA_BIOS_FILE}" ] && \ - [ ! -z "${CONFIG_VGA_BIOS_ID}" ] && \ + [ -n "${CONFIG_VGA_BIOS_FILE}" ] && \ + [ -n "${CONFIG_VGA_BIOS_ID}" ] && \ inject "pci${CONFIG_VGA_BIOS_ID}.rom" \ "${CONFIG_VGA_BIOS_FILE}" "optionrom" [ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" = "y" ] && \ - [ ! -z "${CONFIG_SMSC_SCH5545_EC_FW_FILE}" ] && \ + [ -n "${CONFIG_SMSC_SCH5545_EC_FW_FILE}" ] && \ inject "sch5545_ecfw.bin" "$CONFIG_SMSC_SCH5545_EC_FW_FILE" raw [ "${modifygbe}" = "true" ] && ! [ "${release}" = "y" ] && \ inject "IFD" "${CONFIG_GBE_BIN_PATH}" "GbE"