diff --git a/scripts/blockdev-perftest b/scripts/blockdev-perftest index db240ef36..a00212cc3 100755 --- a/scripts/blockdev-perftest +++ b/scripts/blockdev-perftest @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ############################################################################ # diff --git a/scripts/generate-patched-kernel b/scripts/generate-patched-kernel index a42990bcc..f24fc534d 100755 --- a/scripts/generate-patched-kernel +++ b/scripts/generate-patched-kernel @@ -24,13 +24,14 @@ function usage { } -script_dir="$(dirname $0)" +script_dir="$(dirname "$0")" if [ "${script_dir#/}" = "${script_dir}" ]; then script_dir="$PWD/$script_dir" fi scriptdir="${scriptdir%/.}" scst_dir="$(dirname "${script_dir}")" +# shellcheck source=./kernel-functions source "${script_dir}/kernel-functions" if [ "$1" = "" ]; then @@ -49,9 +50,9 @@ cd "${target}" || exit $? "${script_dir}/list-source-files" "${scst_dir}" | grep -- "-${kernel_version}.*.patch$" | grep -v /in-tree/ | - while read p; do - if [ "${p/readahead-2.6.32.below11.patch//}" = "$p" \ - -o "${patchlevel:-0}" -lt 11 ]; then + while read -r p; do + if [ "${p/readahead-2.6.32.below11.patch//}" = "$p" ] || + [ "${patchlevel:-0}" -lt 11 ]; then echo "==== $p" patch -p1 <"${scst_dir}/$p" fi diff --git a/scripts/kernel-functions b/scripts/kernel-functions index 0d19ae115..979b2f20f 100644 --- a/scripts/kernel-functions +++ b/scripts/kernel-functions @@ -1,4 +1,4 @@ -# -*- mode: shell-script -*- +#!/bin/bash # Shell functions for parsing the Linux kernel version and for downloading # from kernel.org. @@ -45,8 +45,8 @@ function download_file { # Make sure the kernel tarball and patch file are present in directory # ${kernel_downloads}. Download any missing files from ${kernel_mirror}. function download_kernel { - local kver="$(kernel_version $1)" - local plevel="$(patchlevel $1)" + local kver="$(kernel_version "$1")" + local plevel="$(patchlevel "$1")" local series="$1" case "${series:0:2}" in @@ -57,7 +57,7 @@ function download_kernel { test -w "${kernel_downloads}" || return $? ( cd "${kernel_downloads}" || return $? - if [ "$plevel" = "" -o "$plevel" = "0" ] || + if [ "$plevel" = "" ] || [ "$plevel" = "0" ] || download_file "${kernel_mirror}/v$series/patch-$1.xz" then download_file "${kernel_mirror}/v$series/linux-${kver}.tar.xz" || @@ -70,20 +70,20 @@ function download_kernel { } function extract_kernel_archive { - local kver="$(kernel_version $1)" - local plevel="$(patchlevel $1)" + local kver="$(kernel_version "$1")" + local plevel="$(patchlevel "$1")" local series="$1" if [ -e "${kernel_downloads}/linux-$1.tar.xz" ]; then xz -cd "${kernel_downloads}/linux-$1.tar.xz" | tar xf - elif [ -e "${kernel_downloads}/linux-$kver.tar.xz" ]; then xz -cd "${kernel_downloads}/linux-$kver.tar.xz" | tar xf - && - mv linux-$kver linux-$1 + mv "linux-$kver" "linux-$1" elif [ -e "${kernel_downloads}/linux-$1.tar.bz2" ]; then tar xjf "${kernel_downloads}/linux-$1.tar.bz2" elif [ -e "${kernel_downloads}/linux-$kver.tar.bz2" ]; then tar xjf "${kernel_downloads}/linux-$kver.tar.bz2" && - mv linux-$kver linux-$1 + mv "linux-$kver" "linux-$1" else return 1 fi @@ -92,24 +92,24 @@ function extract_kernel_archive { # Create a linux-$1 tree in the current directory, where $1 is a kernel # version number with either three or four components. function extract_kernel_tree { - local kver="$(kernel_version $1)" - local plevel="$(patchlevel $1)" + local kver="$(kernel_version "$1")" + local plevel="$(patchlevel "$1")" local tmpdir=kernel-tree-tmp-$$ rm -rf "linux-$1" "${tmpdir}" mkdir "${tmpdir}" || return $? ( cd "${tmpdir}" || return $? - if [ "$plevel" != "" -a "$plevel" != "0" -a \ - -e "${kernel_downloads}/patch-$1.xz" ]; then - extract_kernel_archive $kver || return $? - mv linux-$kver linux-$1 - ( cd linux-$1 && xz -cd "${kernel_downloads}/patch-$1.xz" \ + if [ "$plevel" != "" ] && [ "$plevel" != "0" ] && + [ -e "${kernel_downloads}/patch-$1.xz" ]; then + extract_kernel_archive "$kver" || return $? + mv "linux-$kver" "linux-$1" + ( cd "linux-$1" && xz -cd "${kernel_downloads}/patch-$1.xz" \ | patch -p1 -f -s; ) \ || return $? else - extract_kernel_archive $1 || - { extract_kernel_archive $kver && mv linux-$kver linux-$1; } || + extract_kernel_archive "$1" || + { extract_kernel_archive "$kver" && mv "linux-$kver" "linux-$1"; } || return $? fi mv "linux-$1" ".." || return $? @@ -120,7 +120,7 @@ function extract_kernel_tree { # Patch a kernel tree where $1 is the kernel version. function patch_kernel { - if [ "$1" = "2.6.29" -o "$1" = "2.6.29.1" -o "$1" = "2.6.29.2" -o "$1" = "2.6.29.3" ] + if [ "$1" = "2.6.29" ] || [ "$1" = "2.6.29.1" ] || [ "$1" = "2.6.29.2" ] || [ "$1" = "2.6.29.3" ] then patch -f -s -p1 <<'EOF' Make sure that branch profiling does not trigger sparse warnings. @@ -177,7 +177,7 @@ See also http://lkml.org/lkml/2009/9/26/51 do { \ EOF fi - if [ "${1#2.6.32}" != "$1" -o "${1#2.6.33}" != "$1" ] + if [ "${1#2.6.32}" != "$1" ] || [ "${1#2.6.33}" != "$1" ] then patch -f -s -p1 <<'EOF' Get rid of sparse errors on sk_buff.protocol. @@ -451,5 +451,10 @@ function download_and_extract_kernel_tree { else download_kernel "$1" && extract_kernel_tree "$1" fi && - (cd linux-$1 && patch_kernel "$1") + (cd "linux-$1" && patch_kernel "$1") } + +# For shellcheck +if false; then + quiet_download=true +fi diff --git a/scripts/list-source-files b/scripts/list-source-files index f4f00f80d..09550eed8 100755 --- a/scripts/list-source-files +++ b/scripts/list-source-files @@ -17,7 +17,7 @@ list_source_files() { grep -vE '^[D?]|^Performing|^$' | \ cut -c3- | \ while read -r a b c f; do - if [ -f "$f" -o -h "$f" ]; then + if [ -f "$f" ] || [ -h "$f" ]; then echo "$a $b $c" >/dev/null echo "$f" fi @@ -39,7 +39,7 @@ list_source_files() { hg manifest fi else - ( cd "$d" && find -type f -o -type l | sed 's|^\./||' ) + ( cd "$d" && find . -type f -o -type l | sed 's|^\./||' ) fi } diff --git a/scripts/monitor-interrupt-rate b/scripts/monitor-interrupt-rate index cd47a181f..7e81ed9a5 100755 --- a/scripts/monitor-interrupt-rate +++ b/scripts/monitor-interrupt-rate @@ -6,11 +6,11 @@ echo "Interrupts per second:" while true do sum=0 - while read line + while read -r line do for word in $line do - if [ "${word#[0-9]}" != "$word" -a "${word%[0-9]}" != "$word" ]; then + if [ "${word#[0-9]}" != "$word" ] && [ "${word%[0-9]}" != "$word" ]; then sum="$((sum + word))" fi done diff --git a/scripts/monitor-memory-usage b/scripts/monitor-memory-usage index e43cd6b12..eabb74dba 100755 --- a/scripts/monitor-memory-usage +++ b/scripts/monitor-memory-usage @@ -50,7 +50,7 @@ do esac done -if [ "$#" != 0 -o "${interval}" -le 0 ]; then +if [ "$#" != 0 ] || [ "${interval}" -le 0 ]; then usage exit 1 fi @@ -61,20 +61,20 @@ fi #################### printf "%-10s " "Time" -cat /proc/meminfo \ -| while read label number unit +cat /proc/meminfo | + while read -r label number unit do - printf " %10s" ${label%:} + printf " %10s" "${label%:}" done echo while true do - printf "%-10d" $(date +%s) - cat /proc/meminfo \ - | while read label number unit + printf "%-10d" "$(date +%s)" + cat /proc/meminfo | + while read -r label number unit do - printf " %10d" ${number} + printf " %10d" "${number}" done echo sleep "${interval}" diff --git a/scripts/run-regression-tests b/scripts/run-regression-tests index 5b1f34452..0ba6ce7e2 100755 --- a/scripts/run-regression-tests +++ b/scripts/run-regression-tests @@ -55,7 +55,7 @@ ######################## # shellcheck source=./kernel-functions -source $(dirname $0)/kernel-functions +source "$(dirname "$0")/kernel-functions" function usage { echo "Usage: $0 [-c ] [-d ] [-f] [-h] [-j ] [-p ] [-q] ..." @@ -697,7 +697,7 @@ do if [ "${run_smatch}" = "true" ]; then run_smatch "$k" "${subdirs[@]}" fi - if [ "${qla2x00t}" = "true" ] && $(kernel_version_le 2.6.37 $k); then + if [ "${qla2x00t}" = "true" ] && kernel_version_le 2.6.37 "$k"; then subdirs+=(drivers/scsi/qla2xxx) fi compile_kernel "$k" "${subdirs[@]}" diff --git a/scripts/update-version b/scripts/update-version index 7735be978..ab2310ccc 100755 --- a/scripts/update-version +++ b/scripts/update-version @@ -2,11 +2,11 @@ # Update the version number in SCST source files. usage() { - echo "Usage: $(basename $0) []" + echo "Usage: $(basename "$0") []" exit 1 } -if [ $# != 3 -a $# != 4 ]; then +if [ $# != 3 ] && [ $# != 4 ]; then usage fi