Unverified Commit 0250ad55 authored by Louis Abel's avatar Louis Abel 📺
Browse files

bunch of shellcheck fixes part 2

parent 3b06b9d0
......@@ -28,12 +28,15 @@ function r_checkExitStatus() {
# just having the files named differently, but that seemed more annoying than
# just setting +x
function r_processor() {
# shellcheck disable=SC2068
exec 8< $@
# shellcheck disable=SC2162
while read -u 8 file; do
# shellcheck disable=SC2086
if [[ "$(basename ${file})" =~ README|^\.|^_ ]]; then
continue
fi
[ -x ${file} ] && ${file}
[ -x "${file}" ] && "${file}"
done
return 0
}
......@@ -45,6 +48,7 @@ function r_processor() {
# Args: Any number of $1..X
function p_installPackageNormal() {
r_log "internal" "Attempting install: $*"
# shellcheck disable=SC2086
/usr/bin/dnf --assumeyes --debuglevel ${DNFDEBUG} install "$@"
r_checkExitStatus $?
}
......@@ -54,6 +58,7 @@ function p_installPackageNormal() {
# Args: Any number of $1..X
function p_installPackageNoWeaks() {
r_log "internal" "Attempting install: $*"
# shellcheck disable=SC2086
/usr/bin/dnf --assumeyes --debuglevel ${DNFDEBUG} --setopt install_weak_deps=0 install "$@"
r_checkExitStatus $?
}
......@@ -62,6 +67,7 @@ function p_installPackageNoWeaks() {
# Args: Any number of $1..X
function p_removePackage() {
r_log "internal" "Attempting uninstall: $*"
# shellcheck disable=SC2086
/usr/bin/dnf --assumeyes --debuglevel ${DNFDEBUG} remove "$@"
r_checkExitStatus $?
}
......@@ -70,6 +76,7 @@ function p_removePackage() {
# Args: Any number of $1..X
function p_enableModule() {
r_log "internal" "Enabling module: $*"
# shellcheck disable=SC2086
/usr/bin/dnf --assumeyes --debuglevel ${DNFDEBUG} module enable "$@"
r_checkExitStatus $?
}
......@@ -78,20 +85,21 @@ function p_enableModule() {
# Args: Any number of $1..X
function p_resetModule() {
r_log "internal" "Resetting module: $*"
# shellcheck disable=SC2086
/usr/bin/dnf --assumeyes --debuglevel ${DNFDEBUG} module reset "$@"
r_checkExitStatus $?
}
function p_getPackageRelease() {
rpm -q --queryformat '%{RELEASE}' $1
rpm -q --queryformat '%{RELEASE}' "$1"
}
function p_getPackageArch() {
rpm -q --queryformat '%{ARCH}' $1
rpm -q --queryformat '%{ARCH}' "$1"
}
function p_getDist() {
rpm -q $(rpm -qf /etc/redhat-release) --queryformat '%{version}\n' | cut -d'.' -f1
rpm -q "$(rpm -qf /etc/redhat-release)" --queryformat '%{version}\n' | cut -d'.' -f1
}
################################################################################
......@@ -101,10 +109,13 @@ function p_getDist() {
# prevent potential race conditions.
function m_serviceCycler() {
if [ "$2" = "cycle" ]; then
# shellcheck disable=SC2086
/bin/systemctl stop $1
sleep 3
# shellcheck disable=SC2086
/bin/systemctl start $1
else
# shellcheck disable=SC2086
/bin/systemctl $2 $1
fi
sleep 3
......@@ -113,6 +124,7 @@ function m_serviceCycler() {
function m_checkForPort() {
while true; do
sleep 1
# shellcheck disable=SC2086
if echo > /dev/tcp/localhost/$1 >/dev/null 2>&1; then
r_log "internal" "Waiting for TCP port $1 to start listening"
break
......
......@@ -68,7 +68,7 @@ r_log "archive" "Check that -r functions"
mkdir /var/tmp/gziptest
touch /var/tmp/gziptest/{a,b}
gzip -r /var/tmp/gziptest
[ "$(ls /var/tmp/gziptest/*.gz | wc -l)" -eq "2" ] || r_checkExitStatus 1
[ "$(find /var/tmp/gziptest/*.gz | wc -l)" -eq "2" ] || r_checkExitStatus 1
# check different compression levels
r_log "archive" "Check compression levels"
......
#!/bin/bash
r_log "bc" "Testing simple calculations"
test $(echo "8 + 5 * 2 / 10 - 1" | bc) -eq "8"
test "$(echo "8 + 5 * 2 / 10 - 1" | bc)" -eq "8"
r_checkExitStatus $?
#!/bin/bash
r_log "coreutils" "Testing pathchk"
pathchk -p "<>" 2> /dev/null
# shellcheck disable=SC2181
[ $? -eq 1 ] && pathchk /var/tmp/fakePathAndFile
# shellcheck disable=SC2181
[ $? -eq 0 ] && pathchk /var/tmp
r_checkExitStatus $?
......@@ -6,6 +6,7 @@ touch -t 199104230420 /tmp/touch-1
touch -t 199104240420 /tmp/touch-2
r_log "coreutils" "Verify that the oldest file is last"
# shellcheck disable=SC2012
ls -lt /tmp/touch-? | tail -n 1 | grep -q 'touch-1'
r_checkExitStatus $?
......
......@@ -3,6 +3,7 @@ r_log "coreutils" "Test the yes command"
touch /var/tmp/yes-123
touch /var/tmp/yes-345
# shellcheck disable=SC2216
yes | /bin/rm -i /var/tmp/yes-* || r_checkExitStatus 1
deleted=1
......
......@@ -11,6 +11,7 @@ PASSER=/var/tmp/cpio/pass
r_log "cpio" "Test basic copy out"
mkdir -p "$OUTTER" "$INNER" "$PASSER"
# shellcheck disable=2012
ls /tmp | cpio -o > "$OUTTER"/cpio.out
r_checkExitStatus $?
......
......@@ -7,5 +7,5 @@ if [ -z "$pngFile" ]; then
exit 0
fi
file -i $pngFile | grep -q 'image/png'
file -i "$pngFile" | grep -q 'image/png'
r_checkExitStatus $?
......@@ -5,7 +5,7 @@ TMPDIR=/var/tmp/find
[ -e $TMPDIR ] && rm -rf "$TMPDIR"
mkdir -p "$TMPDIR" || { r_log "findutils" "Can't create $TMPDIR"; exit $FAIL; }
mkdir -p "$TMPDIR" || { r_log "findutils" "Can't create $TMPDIR"; exit "$FAIL"; }
touch "$TMPDIR/file1"
touch "$TMPDIR/file with a space"
r_log "findutils" "Check that find just works(tm)"
......@@ -23,7 +23,7 @@ fi
r_log "findutils" "Prepare for xargs test"
LINES=$(find "$TMPDIR" -print0 | wc -l)
if [ $LINES -eq 0 ]; then
if [ "$LINES" -eq 0 ]; then
r_checkExitStatus 0
else
r_checkExitStatus 1
......@@ -34,8 +34,10 @@ find "$TMPDIR" -type f -print0 | xargs -0 ls &> /dev/null
r_checkExitStatus $?
r_log "findutils" "Perform for xargs test: fails with spaces in the name"
find "$TMPDIR" -type f | xargs ls &> /dev/null && { r_log "findutils" "Why did this get a 0 exit?"; exit $FAIL; }
if [ $? -ne 0 ]; then
# shellcheck disable=SC2038
find "$TMPDIR" -type f | xargs ls &> /dev/null && { r_log "findutils" "Why did this get a 0 exit?"; exit "$FAIL"; }
ret_val=$?
if [ "$ret_val" -ne 0 ]; then
r_checkExitStatus $?
fi
......
......@@ -2,8 +2,8 @@
r_log "gcc" "Ensure gcc can build a simple program"
OUTPUTPROG=$(mktemp)
gcc ./common/files/hello.c -o $OUTPUTPROG
$OUTPUTPROG | grep -q "Hello!"
gcc ./common/files/hello.c -o "$OUTPUTPROG"
"$OUTPUTPROG" | grep -q "Hello!"
r_checkExitStatus $?
rm $OUTPUTPROG
rm "$OUTPUTPROG"
......@@ -2,8 +2,8 @@
r_log "gcc" "Ensure g++ can build a simple program"
OUTPUTPROG=$(mktemp)
g++ -x c++ ./common/files/hello.cpp -o $OUTPUTPROG
$OUTPUTPROG | grep -q "Hello!"
g++ -x c++ ./common/files/hello.cpp -o "$OUTPUTPROG"
"$OUTPUTPROG" | grep -q "Hello!"
r_checkExitStatus $?
rm $OUTPUTPROG
rm "$OUTPUTPROG"
......@@ -2,7 +2,7 @@
r_log "kernel" "Testing the kernel keyring (GPG)"
ARCH=$(uname -m)
KERNEL=$(uname -r | cut -d'-' -f1)
#KERNEL=$(uname -r | cut -d'-' -f1)
if [ "${ARCH}" == "aarch64" ]; then
r_log "kernel" "Architecture not tested: $ARCH"
......
#!/bin/bash
r_log "kernel" "Testing debrand"
kernver=$(uname -r)
strings /boot/vmlinuz-$(uname -r) | grep -qi rhel
strings "/boot/vmlinuz-$(uname -r)" | grep -qi rhel
ret_val=$?
if [ "$ret_val" -eq "0" ]; then
......
......@@ -4,7 +4,7 @@ r_log "network" "Checking that iptraf runs and returns non-zero"
TMPFILE=/var/tmp/iptraf
[ -e ${TMPFILE} ] && rm ${TMPFILE}
[ ${EUID} -eq 0 ] || { r_log "network" "SKIP: Not running as root."; exit $PASS; }
[ ${EUID} -eq 0 ] || { r_log "network" "SKIP: Not running as root."; exit "$PASS"; }
mkdir -p ${TMPFILE}
......@@ -14,7 +14,7 @@ KILL=$(which iptraf-ng)
STAT=$(which iptraf-ng)
for x in $IPTRAF $PING $KILL $STAT; do
[ ! -f "$x" ] && { r_log "network" "$x not found. This is likely a problem."; exit $FAIL; }
[ ! -f "$x" ] && { r_log "network" "$x not found. This is likely a problem."; exit "$FAIL"; }
done
r_log "network" "Run iptraf on all available interfaces"
......@@ -24,6 +24,7 @@ r_log "network" "Do a simple ping for iptraf"
${PING} -c 6 127.0.0.12 &> /dev/null
LOGSIZE=$(stat -c '%s' ${TMPFILE})
# shellcheck disable=SC2086
kill -USR2 "$(pidof $IPTRAF)"
r_log "network" "Verifying that iptraf log has data"
......
......@@ -2,12 +2,13 @@
r_log "network" "Test bridging functionality (non-network manager)"
bridge=dummybr0
# shellcheck disable=SC1091
. "$(dirname "$0")"/imports.sh
r_log "network" "Add a dummy bridge $bridge"
ret_val=$(iproute_add_bridge $bridge)
r_checkExitStatus $ret_val
r_checkExitStatus "$ret_val"
r_log "network" "Clean up/Remove bridge"
ret_val=$(iproute_del_bridge $bridge)
r_checkExitStatus $ret_val
r_checkExitStatus "$ret_val"
......@@ -9,7 +9,7 @@ m_serviceCycler nfs-server restart
r_log "nfs" "Mount NFS share"
mount -t nfs 127.0.0.1:/export/rotest /mnt
ls -la /mnt | grep -q "nfsfile"
find /mnt | grep -q "nfsfile"
r_checkExitStatus $?
umount /mnt
......
......@@ -10,7 +10,7 @@ m_serviceCycler nfs-server restart
r_log "nfs" "Mount NFS share"
mount -t nfs 127.0.0.1:/export/rwtest /mnt
ls -la /mnt | grep -q "nfsfile"
find /mnt | grep -q "nfsfile"
r_checkExitStatus $?
r_log "nfs" "Test that the NFS share is writeable"
......
......@@ -15,7 +15,7 @@ m_serviceCycler nfs-server restart
m_serviceCycler rpcbind restart
m_serviceCycler autofs restart
r_log "nfs" "Attempt to access /export/autotest via autofs"
ls -la /mnt/autofs | grep -q autofile
find /mnt/autofs | grep -q autofile
r_checkExitStatus $?
# Remove unneeded configuration
......
......@@ -46,7 +46,8 @@ else
fi
cp "$DROPDIR/openssl.crt" "$SSLPATH/certs/"
HASH=$(openssl x509 -noout -hash -in $SSLPATH/certs/openssl.crt)
# shellcheck disable=SC2086
HASH="$(openssl x509 -noout -hash -in $SSLPATH/certs/openssl.crt)"
ret_val=$?
if [ $ret_val -ne 0 ]; then
r_log "openssl" "Could not create hash"
......
......@@ -2,7 +2,8 @@
r_log "postfix" "Test basic MTA"
REGEX='250\ 2\.0\.0\ Ok\:\ queued\ as\ ([0-9A-Z]*).*'
mailresp=$(echo -e "helo localhost\nmail from: root@localhost\nrcpt to: root@localhost\ndata\nt_functional test\n.\nquit\n" | nc -w 5 127.0.0.1 25 | grep queued)
if [ $? -eq 0 ]; then
ret_val=$?
if [ "$ret_val" -eq 0 ]; then
r_log "postfix" "Mail queued successfully"
MTA_ACCEPTED=0
else
......@@ -13,7 +14,7 @@ fi
sleep 2
# Verify that /var/log/maillog is working, if not dump it out
mailresp_id=$(echo $mailresp | cut -d' ' -f6)
mailresp_id=$(echo "$mailresp" | cut -d' ' -f6)
grep -q "${mailresp_id}" /var/log/maillog
if [ $? -eq 1 ]; then
journalctl -u postfix >> /var/log/maillog
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment