summaryrefslogtreecommitdiff
path: root/bin
diff options
authorSylvain Pineau <sylvain.pineau@canonical.com>2020-07-23 10:03:31 +0200
committerSylvain Pineau <sylvain.pineau@canonical.com>2020-07-23 10:03:31 +0200
commit7bd397925fbd2dcbb704c74cc5674d79e077455e (patch)
tree7499b85ce0cef350659b5c4337615d4ed0666ca7 /bin
parent93a6134d58edff6194bd06b6c1cfe9d9bd723d40 (diff)
bin:*.sh: Fix all shellcheck errors
Diffstat (limited to 'bin')
-rwxr-xr-xbin/alsa_record_playback.sh8
-rwxr-xr-xbin/audio_bluetooth_loopback_test.sh13
-rwxr-xr-xbin/bluetooth_transfer_stress.sh12
-rwxr-xr-xbin/broadband_info.sh2
-rwxr-xr-xbin/check_is_laptop.sh8
-rwxr-xr-xbin/connect_wireless.sh36
-rwxr-xr-xbin/cycle_vts.sh4
-rwxr-xr-xbin/disk_cpu_load.sh22
-rwxr-xr-xbin/disk_read_performance_test.sh22
-rwxr-xr-xbin/disk_stats_test.sh20
-rwxr-xr-xbin/graphics_env.sh12
-rwxr-xr-xbin/led_hdd_test.sh8
-rwxr-xr-xbin/light_sensor_test.sh8
-rwxr-xr-xbin/maas-version-check.sh8
-rwxr-xr-xbin/network_configs.sh8
-rwxr-xr-xbin/network_printer_test.sh14
-rwxr-xr-xbin/network_wait.sh9
-rwxr-xr-xbin/optical_write_test.sh34
18 files changed, 123 insertions, 125 deletions
diff --git a/bin/alsa_record_playback.sh b/bin/alsa_record_playback.sh
index e86d7d1..30b2fbd 100755
--- a/bin/alsa_record_playback.sh
+++ b/bin/alsa_record_playback.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-OUTPUT=`mktemp -d`
+OUTPUT=$(mktemp -d)
gst_pipeline_test.py -t 5 "autoaudiosrc ! audioconvert ! level name=recordlevel interval=10000000 ! audioconvert ! wavenc ! filesink location=$OUTPUT/test.wav"
-aplay $OUTPUT/test.wav
-rm $OUTPUT/test.wav
-rmdir $OUTPUT
+aplay "$OUTPUT"/test.wav
+rm "$OUTPUT"/test.wav
+rmdir "$OUTPUT"
diff --git a/bin/audio_bluetooth_loopback_test.sh b/bin/audio_bluetooth_loopback_test.sh
index 9661ec4..dac3699 100755
--- a/bin/audio_bluetooth_loopback_test.sh
+++ b/bin/audio_bluetooth_loopback_test.sh
@@ -23,8 +23,8 @@
# human validate that record/playback is working, human can speak into
# microphone and just ensure the speech can be heard instantly in the headset.
-[ -x "`which pactl`" ] || exit 1
-[ -x "`which pacat`" ] || exit 1
+[ -x "$(command -v pactl)" ] || exit 1
+[ -x "$(command -v pacat)" ] || exit 1
SINK=$(pactl list | sed -n '/monitor/d;s/Name: \(bluez_sink\.\)/\1/p')
SOURCE=$(pactl list | sed -n '/monitor/d;s/Name: \(bluez_source\.\)/\1/p')
@@ -33,6 +33,7 @@ SOURCE=$(pactl list | sed -n '/monitor/d;s/Name: \(bluez_source\.\)/\1/p')
if [ -n "$SINK" ] && [ -n "$SOURCE" ]; then
PLAYBACK_LOG=$(mktemp --tmpdir audio_bluetooth_loopback.XXXXX)
RECORD_LOG=$(mktemp --tmpdir audio_bluetooth_loopback.XXXXX)
+ # shellcheck disable=SC2064
trap "rm $PLAYBACK_LOG $RECORD_LOG" EXIT
# ensure we exit with failure if parec fails, and not with pacat
# --playback's error code
@@ -43,14 +44,14 @@ if [ -n "$SINK" ] && [ -n "$SOURCE" ]; then
# time out after 6 seconds, forcibly kill after 8 seconds if pacat didn't
# respond
echo "Recording and playing back, please speak into bluetooth microphone"
- timeout -k 8 6 pacat $LATENCY --record -v -d $SOURCE 2>$RECORD_LOG | \
- pacat $LATENCY --playback -v -d $SINK 2>$PLAYBACK_LOG
+ timeout -k 8 6 pacat $LATENCY --record -v -d "$SOURCE" 2>"$RECORD_LOG" | \
+ pacat $LATENCY --playback -v -d "$SINK" 2>"$PLAYBACK_LOG"
echo "RECORD LOG"
- cat $RECORD_LOG
+ cat "$RECORD_LOG"
echo ""
echo "PLAYBACK LOG"
- cat $PLAYBACK_LOG
+ cat "$PLAYBACK_LOG"
else
echo "No bluetooth audio device found"
exit 1
diff --git a/bin/bluetooth_transfer_stress.sh b/bin/bluetooth_transfer_stress.sh
index 36e4de7..1b86dd1 100755
--- a/bin/bluetooth_transfer_stress.sh
+++ b/bin/bluetooth_transfer_stress.sh
@@ -31,18 +31,18 @@ DESTINATION=$(mktemp --tmpdir bluetooth-stress.XXXXXX)
REMOTE=$RANDOM
SIZEKB=10240
echo "Creating ${SIZEKB}KB file to test transfer"
-dd if=/dev/urandom of=$ORIGIN count=$SIZEKB bs=1024
-ORIGIN_SUM=$(sha256sum $ORIGIN | cut -f 1 -d ' ')
+dd if=/dev/urandom of="$ORIGIN" count=$SIZEKB bs=1024
+ORIGIN_SUM=$(sha256sum "$ORIGIN" | cut -f 1 -d ' ')
set -o pipefail
echo "Sending file using Bluetooth"
-time obexftp -v -b $BTDEVADDR -o $REMOTE --put $ORIGIN 2>&1 | ansi_parser.py
+time obexftp -v -b "$BTDEVADDR" -o $REMOTE --put "$ORIGIN" 2>&1 | ansi_parser.py
sleep 5
echo "Receiving file using Bluetooth"
-time obexftp -v -b $BTDEVADDR -o $DESTINATION --get $REMOTE 2>&1 | ansi_parser.py
+time obexftp -v -b "$BTDEVADDR" -o "$DESTINATION" --get $REMOTE 2>&1 | ansi_parser.py
# Now checksum destination and compare
-DESTINATION_SUM=$(sha256sum $DESTINATION | cut -f 1 -d ' ')
+DESTINATION_SUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ')
# Clean up before reporting
-rm $ORIGIN $DESTINATION
+rm "$ORIGIN" "$DESTINATION"
if [ "$ORIGIN_SUM" = "$DESTINATION_SUM" ]; then
echo "Checksums match, file transfer succeeded"
exit 0
diff --git a/bin/broadband_info.sh b/bin/broadband_info.sh
index aec2ccb..01ec7dc 100755
--- a/bin/broadband_info.sh
+++ b/bin/broadband_info.sh
@@ -2,5 +2,5 @@
for i in $(mmcli --simple-status -L | \
awk '/freedesktop\/ModemManager1\/Modem/ {print $1;}'); do
- mmcli -m $i
+ mmcli -m "$i"
done
diff --git a/bin/check_is_laptop.sh b/bin/check_is_laptop.sh
index 5820a37..b197441 100755
--- a/bin/check_is_laptop.sh
+++ b/bin/check_is_laptop.sh
@@ -2,15 +2,15 @@
# Establish the system type based on DMI info
TYPE=$(dmidecode -t 3 | awk '/Type:/ { print $2 }')
-echo "Type: " $TYPE
+echo "Type: " "$TYPE"
BATTERY="NO"
-for device in `find /sys -name "type"`
+while IFS= read -r -d '' device
do
- if [ "$(cat $device)" == "Battery" ]; then
+ if [ "$(cat "$device")" == "Battery" ]; then
BATTERY="YES"
fi
-done
+done < <(find /sys -name "type" -print0)
echo "Battery: " $BATTERY
diff --git a/bin/connect_wireless.sh b/bin/connect_wireless.sh
index e39f52c..fc696b2 100755
--- a/bin/connect_wireless.sh
+++ b/bin/connect_wireless.sh
@@ -2,8 +2,7 @@
# Check nmcli version
NMCLI_GTE_0_9_10=0
-nmcli general 2>&1 >/dev/null
-if [ $? -eq 0 ]; then
+if nmcli general > /dev/null 2>&1; then
NMCLI_GTE_0_9_10=1
fi
@@ -11,25 +10,23 @@ fi
conn=''
if [ $NMCLI_GTE_0_9_10 -eq 0 ]; then
- active_connection=$(nmcli -f SSID,ACTIVE dev wifi list | grep yes)
- if [ $? -eq 0 ]; then
- ap=$(echo $active_connection | awk -F\' '{print $2}')
- conn=$(nmcli -t -f UUID,TYPE,NAME con list | grep wireless | grep -e "$ap$" | head -n 1 | awk -F\: '{print $1}')
+ if active_connection=$(nmcli -f SSID,ACTIVE dev wifi list | grep yes); then
+ ap=$(echo "$active_connection" | awk -F\' '{print $2}')
+ conn=$(nmcli -t -f UUID,TYPE,NAME con list | grep wireless | grep -e "$ap$" | head -n 1 | awk -F: '{print $1}')
else
- conn=$(nmcli -t -f UUID,TYPE con list | grep wireless | head -n 1 | awk -F\: '{print $1}')
+ conn=$(nmcli -t -f UUID,TYPE con list | grep wireless | head -n 1 | awk -F: '{print $1}')
fi
else
- active_connection=$(nmcli -f SSID,ACTIVE dev wifi | grep yes)
- if [ $? -eq 0 ]; then
- ap=$(echo $active_connection | awk '{print $1}')
- conn=$(nmcli -t -f UUID,TYPE,NAME con show | grep wireless | grep -e "$ap$" | head -n 1 | awk -F\: '{print $1}')
+ if active_connection=$(nmcli -f SSID,ACTIVE dev wifi | grep yes); then
+ ap=$(echo "$active_connection" | awk '{print $1}')
+ conn=$(nmcli -t -f UUID,TYPE,NAME con show | grep wireless | grep -e "$ap$" | head -n 1 | awk -F: '{print $1}')
else
- conn=$(nmcli -t -f UUID,TYPE con show | grep wireless | head -n 1 | awk -F\: '{print $1}')
+ conn=$(nmcli -t -f UUID,TYPE con show | grep wireless | head -n 1 | awk -F: '{print $1}')
fi
fi
#Strip trailing/leading whitespace
-conn=$(echo $conn |sed 's/^[ \t]*//;s/[ \t]*$//')
+conn=$(echo "$conn" |sed 's/^[ \t]*//;s/[ \t]*$//')
# Find out if wireless is enabled
if [ $NMCLI_GTE_0_9_10 -eq 0 ]; then
@@ -37,6 +34,7 @@ if [ $NMCLI_GTE_0_9_10 -eq 0 ]; then
else
nmcli radio wifi | grep -q 'enabled'
fi
+# shellcheck disable=SC2181
if [ $? -ne 0 ]
then
# Find out why
@@ -45,21 +43,21 @@ then
then
blkmessage='Your wireless may be hardware blocked. You may need
to use your wireless key/switch to re-enable it.'
- echo $blkmessage
+ echo "$blkmessage"
fi
fi
# Check if there's a connection already (wireless or otherwise)
-nmcli dev status | grep -q '\<connected\>'
-if [ $? -eq 0 ]
+
+if nmcli dev status | grep -q '\<connected\>';
then
# Disconnect, pause for a short time
- for iface in `(nmcli -f GENERAL dev list 2>/dev/null || nmcli -f GENERAL dev show) | grep 'GENERAL.DEVICE' | awk '{print $2}'`
+ for iface in $( (nmcli -f GENERAL dev list 2>/dev/null || nmcli -f GENERAL dev show) | grep 'GENERAL.DEVICE' | awk '{print $2}')
do
if [ $NMCLI_GTE_0_9_10 -eq 0 ]; then
- nmcli dev disconnect iface $iface
+ nmcli dev disconnect iface "$iface"
else
- nmcli dev disconnect $iface
+ nmcli dev disconnect "$iface"
fi
done
sleep 2
diff --git a/bin/cycle_vts.sh b/bin/cycle_vts.sh
index c5e1677..a42f8c1 100755
--- a/bin/cycle_vts.sh
+++ b/bin/cycle_vts.sh
@@ -4,7 +4,7 @@ set -o errexit
# NB: This script must be run with root privileges in order to have any effect!
-CURRENT_VT=`/bin/fgconsole`
+CURRENT_VT=$(/bin/fgconsole)
if [ "$CURRENT_VT" == "" ]
then
@@ -24,7 +24,7 @@ chvt "$CURRENT_VT"
sleep 2
# make sure we switched back
-END_VT=`/bin/fgconsole`
+END_VT=$(/bin/fgconsole)
if [ "$END_VT" -ne "$CURRENT_VT" ]
then
echo "didn't get back to the original VT" >&2
diff --git a/bin/disk_cpu_load.sh b/bin/disk_cpu_load.sh
index adad55f..a4c45cb 100755
--- a/bin/disk_cpu_load.sh
+++ b/bin/disk_cpu_load.sh
@@ -44,7 +44,6 @@ set -e
get_params() {
disk_device="/dev/sda"
- short_device="sda"
verbose=0
max_load=30
xfer=4096
@@ -59,9 +58,8 @@ get_params() {
--verbose) verbose=1
;;
*) disk_device="/dev/$1"
- disk_device=`echo $disk_device | sed "s/\/dev\/\/dev/\/dev/g"`
- short_device=$(echo $disk_device | sed "s/\/dev//g")
- if [ ! -b $disk_device ] ; then
+ disk_device=$(echo "$disk_device" | sed "s/\/dev\/\/dev/\/dev/g")
+ if [ ! -b "$disk_device" ] ; then
echo "Unknown block device \"$disk_device\""
echo "Usage: $0 [ --max-load <load> ] [ --xfer <mebibytes> ]"
echo " [ device-file ]"
@@ -82,8 +80,8 @@ get_params() {
sum_array() {
local array=("${@}")
total=0
- for i in ${array[@]}; do
- let total+=$i
+ for i in "${array[@]}"; do
+ (( total+=i ))
done
} # sum_array()
@@ -98,10 +96,10 @@ sum_array() {
compute_cpu_load() {
local start_use
local end_use
- IFS=' ' read -r -a start_use <<< $1
- IFS=' ' read -r -a end_use <<< $2
+ IFS=' ' read -r -a start_use <<< "$1"
+ IFS=' ' read -r -a end_use <<< "$2"
local diff_idle
- let diff_idle=${end_use[3]}-${start_use[3]}
+ (( diff_idle=end_use[3]-start_use[3] ))
sum_array "${start_use[@]}"
local start_total=$total
@@ -110,8 +108,8 @@ compute_cpu_load() {
local diff_total
local diff_used
- let diff_total=${end_total}-${start_total}
- let diff_used=$diff_total-$diff_idle
+ (( diff_total=end_total-start_total ))
+ (( diff_used=diff_total-diff_idle ))
if [ "$verbose" == "1" ] ; then
echo "Start CPU time = $start_total"
@@ -136,7 +134,7 @@ get_params "$@"
retval=0
echo "Testing CPU load when reading $xfer MiB from $disk_device"
echo "Maximum acceptable CPU load is $max_load"
-blockdev --flushbufs $disk_device
+blockdev --flushbufs "$disk_device"
start_load="$(grep "cpu " /proc/stat | tr -s " " | cut -d " " -f 2-)"
if [ "$verbose" == "1" ] ; then
echo "Beginning disk read...."
diff --git a/bin/disk_read_performance_test.sh b/bin/disk_read_performance_test.sh
index 7734543..f0b954c 100755
--- a/bin/disk_read_performance_test.sh
+++ b/bin/disk_read_performance_test.sh
@@ -6,17 +6,17 @@
#Default to a lower bound of 15 MB/s
DEFAULT_BUF_READ=${DISK_READ_PERF:-15}
-for disk in $@; do
+for disk in "$@"; do
echo "Beginning $0 test for $disk"
echo "---------------------------------------------------"
- disk_type=`udevadm info --name /dev/$disk --query property | grep "ID_BUS" | awk '{gsub(/ID_BUS=/," ")}{printf $1}'`
- dev_path=`udevadm info --name /dev/$disk --query property | grep "DEVPATH" | awk '{gsub(/DEVPATH=/," ")}{printf $1}'`
+ disk_type=$(udevadm info --name /dev/"$disk" --query property | grep "ID_BUS" | awk '{gsub(/ID_BUS=/," ")}{printf $1}')
+ dev_path=$(udevadm info --name /dev/"$disk" --query property | grep "DEVPATH" | awk '{gsub(/DEVPATH=/," ")}{printf $1}')
# /sys/block/$disk/queue/rotational was added with Linux 2.6.29. If file is
# not present, test below will fail & disk will be considered an HDD, not
# an SSD.
- rotational=`cat /sys/block/$disk/queue/rotational`
+ rotational=$(cat /sys/block/"$disk"/queue/rotational)
if [[ $dev_path =~ dm ]]; then
disk_type="devmapper"
fi
@@ -48,9 +48,9 @@ for disk in $@; do
# Increase MIN_BUF_READ if a USB3 device is plugged in a USB3 hub port
if [[ $dev_path =~ ((.*usb[0-9]+).*\/)[0-9]-[0-9\.:\-]+\/.* ]]; then
- device_version=`cat '/sys/'${BASH_REMATCH[1]}'/version'`
- hub_port_version=`cat '/sys/'${BASH_REMATCH[2]}'/version'`
- if [ $(echo "$device_version >= 3.00"|bc -l) -eq 1 -a $(echo "$hub_port_version >= 3.00"|bc -l) -eq 1 ]; then
+ device_version=$(cat '/sys/'"${BASH_REMATCH[1]}"'/version')
+ hub_port_version=$(cat '/sys/'"${BASH_REMATCH[2]}"'/version')
+ if [ "$(echo "$device_version >= 3.00"|bc -l)" -eq 1 ] && [ "$(echo "$hub_port_version >= 3.00"|bc -l)" -eq 1 ]; then
MIN_BUF_READ=80
fi
fi
@@ -73,8 +73,8 @@ for disk in $@; do
echo "Beginning hdparm timing runs"
echo "---------------------------------------------------"
- for iteration in `seq 1 10`; do
- speed=`hdparm -t /dev/$disk 2>/dev/null | grep "Timing buffered disk reads" | awk -F"=" '{print $2}' | awk '{print $1}'`
+ for iteration in $(seq 1 10); do
+ speed=$(hdparm -t /dev/"$disk" 2>/dev/null | grep "Timing buffered disk reads" | awk -F"=" '{print $2}' | awk '{print $1}')
echo "INFO: Iteration $iteration: Detected speed is $speed MB/sec"
if [ -z "$speed" ]; then
@@ -83,7 +83,7 @@ for disk in $@; do
fi
speed=${speed/.*}
- if [ $speed -gt $max_speed ]; then
+ if [ "$speed" -gt $max_speed ]; then
max_speed=$speed
fi
done
@@ -91,7 +91,7 @@ for disk in $@; do
echo "---------------------------------------------------"
echo ""
result=0
- if [ $max_speed -gt $MIN_BUF_READ ]; then
+ if [ "$max_speed" -gt "$MIN_BUF_READ" ]; then
echo "PASS: $disk Max Speed of $max_speed MB/sec is faster than Minimum Buffer Read Speed of $MIN_BUF_READ MB/sec"
else
echo "FAIL: $disk Max Speed of $max_speed MB/sec is slower than Minimum Buffer Read Speed of $MIN_BUF_READ MB/sec"
diff --git a/bin/disk_stats_test.sh b/bin/disk_stats_test.sh
index 60b48f5..41ef626 100755
--- a/bin/disk_stats_test.sh
+++ b/bin/disk_stats_test.sh
@@ -16,7 +16,7 @@ check_return_code() {
shift
shift
for item in "$@"; do
- echo "output: "$item
+ echo "output: ""$item"
done
fi
fi
@@ -29,19 +29,19 @@ fi
nvdimm="pmem"
if [ -z "${DISK##*$nvdimm*}" ];then
echo "Disk $DISK appears to be an NVDIMM, skipping"
- exit $STATUS
+ exit "$STATUS"
fi
#Check /proc/partitions, exit with fail if disk isn't found
-grep -w -q $DISK /proc/partitions
+grep -w -q "$DISK" /proc/partitions
check_return_code $? "Disk $DISK not found in /proc/partitions"
#Next, check /proc/diskstats
-grep -w -q -m 1 $DISK /proc/diskstats
+grep -w -q -m 1 "$DISK" /proc/diskstats
check_return_code $? "Disk $DISK not found in /proc/diskstats"
#Verify the disk shows up in /sys/block/
-ls /sys/block | grep -w -q $DISK
+ls /sys/block/*"$DISK"* > /dev/null 2>&1
check_return_code $? "Disk $DISK not found in /sys/block"
#Verify there are stats in /sys/block/$DISK/stat
@@ -49,8 +49,8 @@ check_return_code $? "Disk $DISK not found in /sys/block"
check_return_code $? "stat is either empty or nonexistant in /sys/block/$DISK/"
#Get some baseline stats for use later
-PROC_STAT_BEGIN=`grep -w -m 1 $DISK /proc/diskstats`
-SYS_STAT_BEGIN=`cat /sys/block/$DISK/stat`
+PROC_STAT_BEGIN=$(grep -w -m 1 "$DISK" /proc/diskstats)
+SYS_STAT_BEGIN=$(cat /sys/block/"$DISK"/stat)
#Generate some disk activity using hdparm -t
hdparm -t "/dev/$DISK" 2&> /dev/null
@@ -59,8 +59,8 @@ hdparm -t "/dev/$DISK" 2&> /dev/null
sleep 5
#Make sure the stats have changed:
-PROC_STAT_END=`grep -w -m 1 $DISK /proc/diskstats`
-SYS_STAT_END=`cat /sys/block/$DISK/stat`
+PROC_STAT_END=$(grep -w -m 1 "$DISK" /proc/diskstats)
+SYS_STAT_END=$(cat /sys/block/"$DISK"/stat)
[[ "$PROC_STAT_BEGIN" != "$PROC_STAT_END" ]]
check_return_code $? "Stats in /proc/diskstats did not change" \
@@ -73,4 +73,4 @@ if [[ $STATUS -eq 0 ]]; then
echo "PASS: Finished testing stats for $DISK"
fi
-exit $STATUS
+exit "$STATUS"
diff --git a/bin/graphics_env.sh b/bin/graphics_env.sh
index 5160ae6..b3ee60b 100755
--- a/bin/graphics_env.sh
+++ b/bin/graphics_env.sh
@@ -12,15 +12,15 @@ INDEX=$2
# We only want to set the DRI_PRIME env variable on systems with more than
# 1 GPU running the amdgpu/radeon drivers.
if [[ $DRIVER == "amdgpu" || $DRIVER == "radeon" ]]; then
- NB_GPU=`udev_resource.py -l VIDEO | grep -oP -m1 '\d+'`
- if [ $NB_GPU -gt 1 ]; then
- if [ $INDEX -gt 1 ]; then
+ NB_GPU=$(udev_resource.py -l VIDEO | grep -oP -m1 '\d+')
+ if [[ $NB_GPU -gt 1 ]]; then
+ if [[ $INDEX -gt 1 ]]; then
# See https://wiki.archlinux.org/index.php/PRIME
echo "Setting up PRIME GPU offloading for AMD discrete GPU"
if ! cat /var/log/Xorg.0.log ~/.local/share/xorg/Xorg.0.log 2>&1 | grep -q DRI3; then
- PROVIDER_ID=`xrandr --listproviders | grep "Sink Output" | awk {'print $4'} | tail -1`
- SINK_ID=`xrandr --listproviders | grep "Source Output" | awk {'print $4'} | tail -1`
- xrandr --setprovideroffloadsink ${PROVIDER_ID} ${SINK_ID}
+ PROVIDER_ID=$(xrandr --listproviders | grep "Sink Output" | awk '{print $4}' | tail -1)
+ SINK_ID=$(xrandr --listproviders | grep "Source Output" | awk '{print $4}' | tail -1)
+ xrandr --setprovideroffloadsink "${PROVIDER_ID}" "${SINK_ID}"
fi
export DRI_PRIME=1
else
diff --git a/bin/led_hdd_test.sh b/bin/led_hdd_test.sh
index eac6ae2..f3f9808 100755
--- a/bin/led_hdd_test.sh
+++ b/bin/led_hdd_test.sh
@@ -1,20 +1,22 @@
#!/bin/bash
TIMEOUT=3
-TEMPFILE=`mktemp`
+TEMPFILE=$(mktemp)
+# shellcheck disable=SC2064
trap "rm $TEMPFILE" EXIT
+# shellcheck disable=SC2034
for i in $(seq $TIMEOUT); do
#launch background writer
- dd if=/dev/urandom of=$TEMPFILE bs=1024 oflag=direct &
+ dd if=/dev/urandom of="$TEMPFILE" bs=1024 oflag=direct &
WRITE_PID=$!
echo "Writing..."
sleep 1
kill $WRITE_PID
sync
echo "Reading..."
- dd if=$TEMPFILE of=/dev/null bs=1024 iflag=direct
+ dd if="$TEMPFILE" of=/dev/null bs=1024 iflag=direct
done
echo "OK, now exiting"
diff --git a/bin/light_sensor_test.sh b/bin/light_sensor_test.sh
index f413396..cb8fbe9 100755
--- a/bin/light_sensor_test.sh
+++ b/bin/light_sensor_test.sh
@@ -20,18 +20,18 @@ echo -e "\e[92mwaiting for sensor to be covered......\e[0m"
sleep 3
#Output and print light sensor events 5 sec to light_sensor_test.log
-timeout 5 monitor-sensor | tee $PLAINBOX_SESSION_SHARE/light_sensor_test.log &
+timeout 5 monitor-sensor | tee "$PLAINBOX_SESSION_SHARE"/light_sensor_test.log &
#Print backlight value for 5 sec on the screen
for i in {1..10}
do
- echo "Current Backlight Percentage is:" $(gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.freedesktop.DBus.Properties.Get org.gnome.SettingsDaemon.Power.Screen Brightness)| tr -d '()<>,'
+ echo "Current Backlight Percentage is:" "$(gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.freedesktop.DBus.Properties.Get org.gnome.SettingsDaemon.Power.Screen Brightness)"| tr -d '()<>,'
sleep 0.5
done
# Fail when the user didn't wave their hand and no events have been collected.
-if [[ $(cat $PLAINBOX_SESSION_SHARE/light_sensor_test.log | grep "Light changed" | wc -l) -lt 5 ]]; then
+if [[ $(grep -c "Light changed" "$PLAINBOX_SESSION_SHARE"/light_sensor_test.log) -lt 5 ]]; then
echo -e "\e[91mFAIL: Not enough data to be collect, Please rerun the test case and wave your hand around Light Sensor.\e[0m"
exit 1
fi
@@ -40,7 +40,7 @@ fi
#Print 5 values of the Light sensor value form log file
for i in {1..5}
do
- echo "Ambient light sensor value " $i: `grep 'Light' $PLAINBOX_SESSION_SHARE/light_sensor_test.log | awk '{print $3}' | sed -n "$i"p`
+ echo "Ambient light sensor value " $i: "$(grep 'Light' "$PLAINBOX_SESSION_SHARE"/light_sensor_test.log | awk '{print $3}' | sed -n "$i"p)"
done
exit 0
diff --git a/bin/maas-version-check.sh b/bin/maas-version-check.sh
index 678088a..6856354 100755
--- a/bin/maas-version-check.sh
+++ b/bin/maas-version-check.sh
@@ -22,13 +22,13 @@ MIN_VERSION="2.0"
# Is the file there?
if [ -s $MAAS_FILE ]; then
- maas_version=`cat $MAAS_FILE`
- echo $maas_version
+ maas_version=$(cat $MAAS_FILE)
+ echo "$maas_version"
else
echo "ERROR: This system does not appear to have been installed by MAAS"
- echo "ERROR: " $(ls -l $MAAS_FILE 2>&1)
+ echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)"
exit 1
fi
#is the version appropriate
-exit `dpkg --compare-versions $maas_version "ge" $MIN_VERSION`
+exit "$(dpkg --compare-versions "$maas_version" "ge" $MIN_VERSION)"
diff --git a/bin/network_configs.sh b/bin/network_configs.sh
index b2fcc99..4fd354b 100755
--- a/bin/network_configs.sh
+++ b/bin/network_configs.sh
@@ -1,13 +1,13 @@
#!/bin/bash
-if `grep -q "replaced by netplan" /etc/network/interfaces`; then
+if grep -q "replaced by netplan" /etc/network/interfaces; then
# Get our configs from netplan
for directory in "etc" "run" "lib"; do
- for configfile in `find /$directory/netplan -type f -name *.yaml`; do
+ while IFS= read -r -d '' configfile; do
echo "Config File $configfile:"
- cat $configfile
+ cat "$configfile"
echo ""
- done
+ done < <(find /$directory/netplan -type f -name "*.yaml" -print0)
done
else
# get configs from Network Manager instead
diff --git a/bin/network_printer_test.sh b/bin/network_printer_test.sh
index 19d98d2..2633b6c 100755
--- a/bin/network_printer_test.sh
+++ b/bin/network_printer_test.sh
@@ -19,7 +19,7 @@ while [ $# -gt 0 ]
do
case "$1" in
-p)
- if echo ${2} | grep -q -c '^-'; then
+ if echo "${2}" | grep -q -c '^-'; then
usage
exit 1
fi
@@ -27,7 +27,7 @@ do
shift
;;
-s)
- if echo ${2} | grep -q -c '^-'; then
+ if echo "${2}" | grep -q -c '^-'; then
usage
exit 1
fi
@@ -42,16 +42,16 @@ do
shift
done
-if [ -z $server ]; then
+if [ -z "$server" ]; then
echo "Nothing to do with no server defined. (See $0 --usage)"
exit 0
fi
printer=${printer:-PDF}
-lpadmin -E -v ipp://${server}/printers/${printer}
-cupsenable ${printer}
-cupsaccept ${printer}
+lpadmin -E -v ipp://"${server}"/printers/"${printer}"
+cupsenable "${printer}"
+cupsaccept "${printer}"
-lsb_release -a | lp -t "lsb_release" -d ${printer}
+lsb_release -a | lp -t "lsb_release" -d "${printer}"
diff --git a/bin/network_wait.sh b/bin/network_wait.sh
index f0637d0..16d474c 100755
--- a/bin/network_wait.sh
+++ b/bin/network_wait.sh
@@ -2,8 +2,7 @@
x=1
while true; do
- state=$(/usr/bin/nmcli -t -f STATE nm 2>/dev/null)
- if [[ $? != 0 ]]; then
+ if ! state=$(/usr/bin/nmcli -t -f STATE nm 2>/dev/null); then
state=$(/usr/bin/nmcli -t -f STATE general 2>/dev/null)
rc=$?
if [[ $rc != 0 ]]; then
@@ -11,13 +10,13 @@ while true; do
fi
fi
if [ "$state" = "connected" ]; then
- echo $state
+ echo "$state"
exit 0
fi
- x=$(($x + 1))
+ x=$((x + 1))
if [ $x -gt 12 ]; then
- echo $state
+ echo "$state"
exit 1
fi
diff --git a/bin/optical_write_test.sh b/bin/optical_write_test.sh
index b127667..ca1dc79 100755
--- a/bin/optical_write_test.sh
+++ b/bin/optical_write_test.sh
@@ -11,7 +11,7 @@ create_working_dirs(){
# First, create the temp dir and cd there
echo "Creating Temp directory and moving there ..."
mkdir -p $TEMP_DIR || return 1
- cd $TEMP_DIR
+ cd $TEMP_DIR || return 1
echo "Now working in $PWD ..."
}
@@ -26,18 +26,18 @@ generate_md5(){
# Generate the md5sum
echo "Generating md5sums of sample files ..."
CUR_DIR=$PWD
- cd $SAMPLE_FILE
- md5sum * > $TEMP_DIR/$MD5SUM_FILE
+ cd $SAMPLE_FILE || return 1
+ md5sum -- * > $TEMP_DIR/$MD5SUM_FILE
# Check the sums for paranoia sake
check_md5 $TEMP_DIR/$MD5SUM_FILE
rt=$?
- cd $CUR_DIR
+ cd "$CUR_DIR" || exit 1
return $rt
}
check_md5(){
echo "Checking md5sums ..."
- md5sum -c $1
+ md5sum -c "$1"
return $?
}
@@ -55,10 +55,10 @@ burn_iso(){
echo "Beginning image burn ..."
if [ "$OPTICAL_TYPE" == 'cd' ]
then
- wodim -eject dev=$OPTICAL_DRIVE $ISO_NAME
+ wodim -eject dev="$OPTICAL_DRIVE" $ISO_NAME
elif [ "$OPTICAL_TYPE" == 'dvd' ] || [ "$OPTICAL_TYPE" == 'bd' ]
then
- growisofs -dvd-compat -Z $OPTICAL_DRIVE=$ISO_NAME
+ growisofs -dvd-compat -Z "$OPTICAL_DRIVE=$ISO_NAME"
else
echo "Invalid type specified '$OPTICAL_TYPE'"
exit 1
@@ -76,9 +76,9 @@ check_disk(){
echo "Waiting up to 5 minutes for drive to be mounted ..."
while true; do
sleep $INTERVAL
- SLEEP_COUNT=`expr $SLEEP_COUNT + $INTERVAL`
+ SLEEP_COUNT=$((SLEEP_COUNT + INTERVAL))
- mount $OPTICAL_DRIVE 2>&1 |egrep -q "already mounted"
+ mount "$OPTICAL_DRIVE" 2>&1 | grep -E -q "already mounted"
rt=$?
if [ $rt -eq 0 ]; then
echo "Drive appears to be mounted now"
@@ -96,8 +96,8 @@ check_disk(){
echo "Deleting original data files ..."
rm -rf $SAMPLE_FILE
- if [ -n "$(mount | grep $OPTICAL_DRIVE)" ]; then
- MOUNT_PT=$(mount | grep $OPTICAL_DRIVE | awk '{print $3}')
+ if mount | grep -q "$OPTICAL_DRIVE"; then
+ MOUNT_PT=$(mount | grep "$OPTICAL_DRIVE" | awk '{print $3}')
echo "Disk is mounted to $MOUNT_PT"
else
echo "Attempting best effort to mount $OPTICAL_DRIVE on my own"
@@ -105,7 +105,7 @@ check_disk(){
echo "Creating temp mount point: $MOUNT_PT ..."
mkdir $MOUNT_PT
echo "Mounting disk to mount point ..."
- mount $OPTICAL_DRIVE $MOUNT_PT
+ mount "$OPTICAL_DRIVE" $MOUNT_PT
rt=$?
if [ $rt -ne 0 ]; then
echo "ERROR: Unable to re-mount $OPTICAL_DRIVE!" >&2
@@ -120,24 +120,24 @@ check_disk(){
cleanup(){
echo "Moving back to original location"
- cd $START_DIR
+ cd "$START_DIR" || exit 1
echo "Now residing in $PWD"
echo "Cleaning up ..."
umount "$MOUNT_PT"
rm -fr $TEMP_DIR
echo "Ejecting spent media ..."
- eject $OPTICAL_DRIVE
+ eject "$OPTICAL_DRIVE"
}
failed(){
- echo $1
+ echo "$1"
echo "Attempting to clean up ..."
cleanup
exit 1
}
-if [ -e $1 ]; then
- OPTICAL_DRIVE=$(readlink -f $1)
+if [ -e "$1" ]; then
+ OPTICAL_DRIVE=$(readlink -f "$1")
else
OPTICAL_DRIVE='/dev/sr0'
fi