From 7f250ed1b02587aeb2cf6d27e515951ab9d923db Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Thu, 23 May 2024 08:16:01 -0400 Subject: [PATCH] fix: make sure all use of head and tail is portable. close #1238 --- quickemu | 6 +++--- quickget | 38 +++++++++++++++++++------------------- quickreport | 10 +++++----- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/quickemu b/quickemu index 44bd32f..497d3b7 100755 --- a/quickemu +++ b/quickemu @@ -336,7 +336,7 @@ function configure_cpu() { SMM="off" else if [ -r /sys/class/dmi/id/sys_vendor ]; then - MANUFACTURER=$(head -1 /sys/class/dmi/id/sys_vendor) + MANUFACTURER=$(head -n 1 /sys/class/dmi/id/sys_vendor) fi CPU_KVM_UNHALT=",kvm_pv_unhalt" GUEST_TWEAKS+=" -global kvm-pit.lost_tick_policy=discard" @@ -1895,7 +1895,7 @@ if [ "${OS_KERNEL}" == "Darwin" ]; then display="cocoa" fi -QEMU_VER_LONG=$(${QEMU_IMG} --version | head -1 | awk '{print $3}') +QEMU_VER_LONG=$(${QEMU_IMG} --version | head -n 1 | awk '{print $3}') QEMU_VER_SHORT=$(echo "${QEMU_VER_LONG//./}" | cut -c1-2) if [ "${QEMU_VER_SHORT}" -lt 60 ]; then echo "ERROR! QEMU 6.0.0 or newer is required, detected ${QEMU_VER_LONG}." @@ -2094,7 +2094,7 @@ fileshare_param_check # Check if vm is already run VM_PID="" if [ -r "${VMDIR}/${VMNAME}.pid" ]; then - VM_PID=$(head -1 "${VMDIR}/${VMNAME}.pid") + VM_PID=$(head -n 1 "${VMDIR}/${VMNAME}.pid") if ! kill -0 "${VM_PID}" > /dev/null 2>&1; then # VM is not running, cleaning up. VM_PID="" diff --git a/quickget b/quickget index a736564..88fb68f 100755 --- a/quickget +++ b/quickget @@ -414,7 +414,7 @@ function test_all() { if [[ $(type -t "editions_${OS}") == function ]]; then for EDITION in $(editions_"${OS}"); do validate_release releases_"${OS}" - URL=$(get_"${OS}" | cut -d' ' -f1 | head -1) + URL=$(get_"${OS}" | cut -d' ' -f1 | head -n 1) if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" elif [ "${OPERATION}" == "test" ]; then @@ -443,7 +443,7 @@ function test_all() { (get_ubuntu) else validate_release releases_"${OS}" - URL=$(get_"${OS}" | cut -d' ' -f1 | head -1) + URL=$(get_"${OS}" | cut -d' ' -f1 | head -n 1) if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" elif [ "${OPERATION}" == "test" ]; then @@ -610,7 +610,7 @@ function editions_arcolinux() { function releases_artixlinux() { #shellcheck disable=SC2046,SC2005 - echo $(web_pipe "https://mirror1.artixlinux.org/iso/" | grep "artix-" | cut -d'"' -f2 | grep -v sig | cut -d'-' -f 4 | sort -ru | tail -1) + echo $(web_pipe "https://mirror1.artixlinux.org/iso/" | grep "artix-" | cut -d'"' -f2 | grep -v sig | cut -d'-' -f 4 | sort -ru | tail -n 1) } function editions_artixlinux() { @@ -625,7 +625,7 @@ function releases_athenaos() { function releases_batocera() { #shellcheck disable=SC2046,SC2005 - echo $(web_pipe "https://mirrors.o2switch.fr/batocera/x86_64/stable/" | grep ^\' -f3 | cut -d'<' -f1 | tail -1)" + HASH="$(web_pipe "https://sourceforge.net/projects/nwg-iso/rss?path=/" | grep "${ISO}" | cut -d'>' -f3 | cut -d'<' -f1 | tail -n 1)" echo "${URL}/${ISO} ${HASH}" } @@ -2459,7 +2459,7 @@ function get_sparkylinux() { minimalgui) URL="https://sourceforge.net/projects/sparkylinux/files/base";; *) URL="https://sourceforge.net/projects/sparkylinux/files/${EDITION}";; esac - HASH=$(web_pipe "${URL}/${ISO}.allsums.txt" | head -2 | grep 'iso' | cut -d' ' -f1) + HASH=$(web_pipe "${URL}/${ISO}.allsums.txt" | head -n 2 | grep 'iso' | cut -d' ' -f1) echo "${URL}/${ISO}" "${HASH}" } @@ -2627,7 +2627,7 @@ function get_vanillaos() { local HASH="" local HASH_URL="" local ISO="" - ISO=$(web_pipe "https://api.github.com/repos/Vanilla-OS/live-iso/releases" | grep 'download_url' | grep "${RELEASE}" | head -1 | cut -d'"' -f4) + ISO=$(web_pipe "https://api.github.com/repos/Vanilla-OS/live-iso/releases" | grep 'download_url' | grep "${RELEASE}" | head -n 1 | cut -d'"' -f4) HASH_URL="${ISO//.iso/.sha256.txt}" HASH=$(web_pipe "${HASH_URL}" | cut -d' ' -f1) echo "${ISO} ${HASH}" @@ -3394,7 +3394,7 @@ if [ ! -x "${CURL}" ]; then echo "ERROR! curl not found. Please install curl" exit 1 fi -CURL_VERSION=$("${CURL}" --version | head -1 | cut -d' ' -f2) +CURL_VERSION=$("${CURL}" --version | head -n 1 | cut -d' ' -f2) QEMU_IMG=$(command -v qemu-img) if [ ! -x "${QEMU_IMG}" ]; then diff --git a/quickreport b/quickreport index 556b712..4280206 100755 --- a/quickreport +++ b/quickreport @@ -43,11 +43,11 @@ quick_report() { VERSION=$(curl --version) echo \ "---------------------------------- - curl $(echo "${VERSION}" | head -1 | cut -d' ' -f2) + curl $(echo "${VERSION}" | head -n 1 | cut -d' ' -f2) ----------------------------------" - echo -e "Libraries:$(echo "${VERSION}" | head -1 | cut -d')' -f2-)" - echo -e "Protocols:$(echo "${VERSION}" | tail +3 | head -1 | cut -d':' -f2-)" - echo -e "Features: $(echo "${VERSION}" | tail +4 | head -1 | cut -d':' -f2-)" + echo -e "Libraries:$(echo "${VERSION}" | head -n 1 | cut -d')' -f2-)" + echo -e "Protocols:$(echo "${VERSION}" | tail -n +3 | head -n 1 | cut -d':' -f2-)" + echo -e "Features: $(echo "${VERSION}" | tail -n +4 | head -n 1 | cut -d':' -f2-)" else echo \ "---------------------------------- @@ -56,7 +56,7 @@ quick_report() { fi if command -v qemu-system-"$(uname -m)" &> /dev/null; then - VERSION=$(qemu-system-"$(uname -m)" -version | head -1 | cut -d' ' -f4) + VERSION=$(qemu-system-"$(uname -m)" -version | head -n 1 | cut -d' ' -f4) echo \ "---------------------------------- QEMU ${VERSION}