Skip to content

Commit beb3e54

Browse files
committed
fix(TEST BASIC): shellcheck
1 parent d174e18 commit beb3e54

File tree

4 files changed

+46
-133
lines changed

4 files changed

+46
-133
lines changed

test/TEST-01-BASIC/.shchkdir

Whitespace-only changes.

test/TEST-01-BASIC/create-root.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# don't let udev and this script step on eachother's toes
33
for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
4-
> "/etc/udev/rules.d/$x"
4+
: > "/etc/udev/rules.d/$x"
55
done
66
rm -f -- /etc/lvm/lvm.conf
77
udevadm control --reload

test/TEST-01-BASIC/test-init.sh

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,12 @@
11
#!/bin/sh
2-
> /dev/watchdog
3-
getcmdline() {
4-
while read -r _line || [ -n "$_line" ]; do
5-
printf "%s" "$_line"
6-
done < /proc/cmdline
7-
}
2+
: > /dev/watchdog
83

9-
_dogetarg() {
10-
local _o _val _doecho
11-
unset _val
12-
unset _o
13-
unset _doecho
14-
CMDLINE=$(getcmdline)
4+
. /lib/dracut-lib.sh
155

16-
for _o in $CMDLINE; do
17-
if [ "${_o%%=*}" = "${1%%=*}" ]; then
18-
if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
19-
# if $1 has a "=<value>", we want the exact match
20-
if [ "$_o" = "$1" ]; then
21-
_val="1"
22-
unset _doecho
23-
fi
24-
continue
25-
fi
26-
27-
if [ "${_o#*=}" = "$_o" ]; then
28-
# if cmdline argument has no "=<value>", we assume "=1"
29-
_val="1"
30-
unset _doecho
31-
continue
32-
fi
33-
34-
_val="${_o#*=}"
35-
_doecho=1
36-
fi
37-
done
38-
if [ -n "$_val" ]; then
39-
[ "x$_doecho" != "x" ] && echo "$_val"
40-
return 0
41-
fi
42-
return 1
43-
}
44-
45-
getarg() {
46-
local _deprecated _newoption
47-
while [ $# -gt 0 ]; do
48-
case $1 in
49-
-d)
50-
_deprecated=1
51-
shift
52-
;;
53-
-y)
54-
if _dogetarg $2 > /dev/null; then
55-
if [ "$_deprecated" = "1" ]; then
56-
[ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated."
57-
fi
58-
echo 1
59-
return 0
60-
fi
61-
_deprecated=0
62-
shift 2
63-
;;
64-
-n)
65-
if _dogetarg $2 > /dev/null; then
66-
echo 0
67-
if [ "$_deprecated" = "1" ]; then
68-
[ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated."
69-
fi
70-
return 1
71-
fi
72-
_deprecated=0
73-
shift 2
74-
;;
75-
*)
76-
if [ -z "$_newoption" ]; then
77-
_newoption="$1"
78-
fi
79-
if _dogetarg $1; then
80-
if [ "$_deprecated" = "1" ]; then
81-
[ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated."
82-
fi
83-
return 0
84-
fi
85-
_deprecated=0
86-
shift
87-
;;
88-
esac
89-
done
90-
return 1
91-
}
92-
93-
getargbool() {
94-
local _b
95-
unset _b
96-
local _default
97-
_default="$1"
98-
shift
99-
_b=$(getarg "$@")
100-
[ $? -ne 0 -a -z "$_b" ] && _b="$_default"
101-
if [ -n "$_b" ]; then
102-
[ $_b = "0" ] && return 1
103-
[ $_b = "no" ] && return 1
104-
[ $_b = "off" ] && return 1
105-
fi
106-
return 0
107-
}
1086
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
109-
strstr() { [ "${1##*"$2"*}" != "$1" ]; }
110-
CMDLINE=$(while read line || [ -n "$line" ]; do echo $line; done < /proc/cmdline)
111-
plymouth --quit
7+
command -v plymouth > /dev/null 2>&1 && plymouth --quit
1128
exec > /dev/console 2>&1
9+
11310
echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdb
11411
export TERM=linux
11512
export PS1='initramfs-test:\w\$ '
@@ -123,4 +20,5 @@ if getargbool 0 rd.shell; then
12320
fi
12421
echo "Powering down."
12522
mount -n -o remount,ro /
23+
sync
12624
poweroff -f

test/TEST-01-BASIC/test.sh

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2034
23
TEST_DESCRIPTION="root filesystem on a ext3 filesystem"
34

45
KVERSION=${KVERSION-$(uname -r)}
@@ -7,29 +8,31 @@ KVERSION=${KVERSION-$(uname -r)}
78
# DEBUGFAIL="rd.shell rd.break"
89

910
test_run() {
10-
dd if=/dev/zero of=$TESTDIR/result bs=1M count=1
11-
$testdir/run-qemu \
12-
-drive format=raw,index=0,media=disk,file=$TESTDIR/root.ext3 \
13-
-drive format=raw,index=1,media=disk,file=$TESTDIR/result \
11+
dd if=/dev/zero of="$TESTDIR"/result bs=1M count=1
12+
"$testdir"/run-qemu \
13+
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
14+
-drive format=raw,index=1,media=disk,file="$TESTDIR"/result \
1415
-watchdog i6300esb -watchdog-action poweroff \
1516
-append "panic=1 systemd.crash_reboot \"root=LABEL= rdinit=/bin/sh\" rw systemd.log_level=debug systemd.log_target=console rd.retry=3 rd.debug console=ttyS0,115200n81 rd.shell=0 $DEBUGFAIL" \
16-
-initrd $TESTDIR/initramfs.testing || return 1
17-
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success $TESTDIR/result || return 1
17+
-initrd "$TESTDIR"/initramfs.testing || return 1
18+
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/result || return 1
1819
}
1920

2021
test_setup() {
21-
rm -f -- $TESTDIR/root.ext3
22+
rm -f -- "$TESTDIR"/root.ext3
2223
# Create the blank file to use as a root filesystem
23-
dd if=/dev/zero of=$TESTDIR/root.ext3 bs=1M count=80
24+
dd if=/dev/zero of="$TESTDIR"/root.ext3 bs=1M count=80
2425

2526
kernel=$KVERSION
2627
# Create what will eventually be our root filesystem onto an overlay
2728
(
29+
# shellcheck disable=SC2030
2830
export initdir=$TESTDIR/overlay/source
29-
mkdir -p $initdir
30-
. $basedir/dracut-init.sh
31+
mkdir -p "$initdir"
32+
# shellcheck disable=SC1090
33+
. "$basedir"/dracut-init.sh
3134
(
32-
cd "$initdir"
35+
cd "$initdir" || exit
3336
mkdir -p -- dev sys proc etc var/run tmp
3437
mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
3538
for i in bin sbin lib lib64; do
@@ -38,25 +41,34 @@ test_setup() {
3841
)
3942
inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
4043
mount dmesg dhclient mkdir cp ping dhclient \
41-
umount strace less setsid dd
44+
umount strace less setsid dd sync
4245
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
4346
[ -f ${_terminfodir}/l/linux ] && break
4447
done
4548
inst_multiple -o ${_terminfodir}/l/linux
4649
inst "$basedir/modules.d/35network-legacy/dhclient-script.sh" "/sbin/dhclient-script"
4750
inst "$basedir/modules.d/35network-legacy/ifup.sh" "/sbin/ifup"
51+
52+
inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
53+
inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
54+
ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
55+
ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
56+
4857
inst_multiple grep
4958
inst_simple /etc/os-release
5059
inst ./test-init.sh /sbin/init
5160
find_binary plymouth > /dev/null && inst_multiple plymouth
52-
cp -a /etc/ld.so.conf* $initdir/etc
61+
cp -a /etc/ld.so.conf* "$initdir"/etc
5362
ldconfig -r "$initdir"
5463
)
5564

5665
# second, install the files needed to make the root filesystem
5766
(
67+
# shellcheck disable=SC2031
68+
# shellcheck disable=SC2030
5869
export initdir=$TESTDIR/overlay
59-
. $basedir/dracut-init.sh
70+
# shellcheck disable=SC1090
71+
. "$basedir"/dracut-init.sh
6072
inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd
6173
inst_hook initqueue 01 ./create-root.sh
6274
inst_hook initqueue/finished 01 ./finished-false.sh
@@ -66,34 +78,36 @@ test_setup() {
6678
# create an initramfs that will create the target root filesystem.
6779
# We do it this way so that we do not risk trashing the host mdraid
6880
# devices, volume groups, encrypted partitions, etc.
69-
$basedir/dracut.sh -l -i $TESTDIR/overlay / \
81+
"$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
7082
-m "dash udev-rules base rootfs-block fs-lib kernel-modules fs-lib qemu" \
7183
-d "piix ide-gd_mod ata_piix ext3 sd_mod" \
7284
--nomdadmconf \
7385
--no-hostonly-cmdline -N \
74-
-f $TESTDIR/initramfs.makeroot $KVERSION || return 1
75-
rm -rf -- $TESTDIR/overlay
86+
-f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
87+
rm -rf -- "$TESTDIR"/overlay
7688
# Invoke KVM and/or QEMU to actually create the target filesystem.
7789

78-
$testdir/run-qemu \
79-
-drive format=raw,index=0,media=disk,file=$TESTDIR/root.ext3 \
90+
"$testdir"/run-qemu \
91+
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
8092
-append "root=/dev/dracut/root rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
81-
-initrd $TESTDIR/initramfs.makeroot || return 1
82-
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created $TESTDIR/root.ext3 || return 1
93+
-initrd "$TESTDIR"/initramfs.makeroot || return 1
94+
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/root.ext3 || return 1
8395

8496
(
97+
# shellcheck disable=SC2031
8598
export initdir=$TESTDIR/overlay
86-
. $basedir/dracut-init.sh
99+
# shellcheck disable=SC1090
100+
. "$basedir"/dracut-init.sh
87101
inst_multiple poweroff shutdown dd
88102
inst_hook shutdown-emergency 000 ./hard-off.sh
89103
inst_hook emergency 000 ./hard-off.sh
90104
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
91105
)
92-
$basedir/dracut.sh -l -i $TESTDIR/overlay / \
106+
"$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
93107
-a "debug watchdog" \
94108
-d "piix ide-gd_mod ata_piix ext3 sd_mod i6300esb ib700wdt" \
95109
--no-hostonly-cmdline -N \
96-
-f $TESTDIR/initramfs.testing $KVERSION || return 1
110+
-f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
97111

98112
# -o "plymouth network md dmraid multipath fips caps crypt btrfs resume dmsquash-live dm"
99113
}
@@ -102,4 +116,5 @@ test_cleanup() {
102116
return 0
103117
}
104118

105-
. $testdir/test-functions
119+
# shellcheck disable=SC1090
120+
. "$testdir"/test-functions

0 commit comments

Comments
 (0)