scripts: Fix multiple shellcheck warnings

git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8564 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2019-08-25 22:51:57 +00:00
parent ee24c6bab2
commit c205138e87
8 changed files with 47 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
############################################################################
#

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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}"

View File

@@ -55,7 +55,7 @@
########################
# shellcheck source=./kernel-functions
source $(dirname $0)/kernel-functions
source "$(dirname "$0")/kernel-functions"
function usage {
echo "Usage: $0 [-c <dir>] [-d <dir>] [-f] [-h] [-j <jobs>] [-p <patchdir>] [-q] <kver1> <kver2> ..."
@@ -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[@]}"

View File

@@ -2,11 +2,11 @@
# Update the version number in SCST source files.
usage() {
echo "Usage: $(basename $0) <major> <minor> <release> [<suffix>]"
echo "Usage: $(basename "$0") <major> <minor> <release> [<suffix>]"
exit 1
}
if [ $# != 3 -a $# != 4 ]; then
if [ $# != 3 ] && [ $# != 4 ]; then
usage
fi