X Tutup
Skip to content

Commit 437e889

Browse files
committed
src: shellcheck-ify shell scripts
1 parent 0084d4f commit 437e889

File tree

11 files changed

+98
-85
lines changed

11 files changed

+98
-85
lines changed

src/basic/generate-af-list.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
$1 -E -dM -include sys/socket.h -include "$2" -include "$3" - </dev/null | \
6-
grep -Ev 'AF_UNSPEC|AF_MAX' | \
7-
awk '/^#define[ \t]+AF_[^ \t]+[ \t]+[AP]F_[^ \t]/ { print $2; }'
6+
${1:?} -E -dM -include sys/socket.h -include "${2:?}" -include "${3:?}" - </dev/null | \
7+
grep -Ev 'AF_UNSPEC|AF_MAX' | \
8+
awk '/^#define[ \t]+AF_[^ \t]+[ \t]+[AP]F_[^ \t]/ { print $2; }'

src/basic/generate-arphrd-list.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
$1 -dM -include linux/if_arp.h -include "$2" - </dev/null | \
6-
awk '/^#define[ \t]+ARPHRD_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
7-
sed -e 's/ARPHRD_//'
6+
${1:?} -dM -include linux/if_arp.h -include "${2:?}" - </dev/null | \
7+
awk '/^#define[ \t]+ARPHRD_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
8+
sed -e 's/ARPHRD_//'

src/basic/generate-cap-list.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
$1 -dM -include linux/capability.h -include "$2" -include "$3" - </dev/null | \
6-
awk '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $2; }' | \
7-
grep -v CAP_LAST_CAP
6+
${1:?} -dM -include linux/capability.h -include "${2:?}" -include "${3:?}" - </dev/null | \
7+
awk '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $2; }' | \
8+
grep -v CAP_LAST_CAP

src/basic/generate-errno-list.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
$1 -dM -include errno.h - </dev/null | \
6-
awk '/^#define[ \t]+E[^ _]+[ \t]+/ { print $2; }'
6+
${1:?} -dM -include errno.h - </dev/null | \
7+
awk '/^#define[ \t]+E[^ _]+[ \t]+/ { print $2; }'

src/basic/linux/update.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

56
for i in *.h */*.h; do
6-
if [[ $i == 'loadavg.h' ]]; then
7-
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i -o $i
7+
if [[ "$i" == "loadavg.h" ]]; then
8+
curl --fail "https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i" -o "$i"
89
else
9-
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i -o $i
10+
curl --fail "https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i" -o "$i"
1011
fi
1112

12-
sed -i -e 's/__user //g' -e '/^#include <linux\/compiler.h>/ d' $i
13+
sed -i -e 's/__user //g' -e '/^#include <linux\/compiler.h>/ d' "$i"
1314
done
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
if nm -D -u "$1" | grep ' U '; then
6+
if nm -D -u "${1:?}" | grep ' U '; then
67
echo "Undefined symbols detected!"
78
exit 1
89
fi
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
4+
set -o pipefail
45

5-
cpp="$1"
6+
cpp="${1:?}"
67
shift
78

8-
includes=""
9+
includes=()
910
for i in "$@"; do
10-
includes="$includes -include $i"
11+
includes+=(-include "$i")
1112
done
1213

13-
$cpp -dM $includes - </dev/null | \
14-
grep -vE 'AUDIT_.*(FIRST|LAST)_' | \
15-
sed -r -n 's/^#define\s+AUDIT_(\w+)\s+([0-9]{4})\s*$$/\1\t\2/p' | \
16-
sort -k2
14+
$cpp -dM "${includes[@]}" - </dev/null | \
15+
grep -vE 'AUDIT_.*(FIRST|LAST)_' | \
16+
sed -r -n 's/^#define\s+AUDIT_(\w+)\s+([0-9]{4})\s*$$/\1\t\2/p' | \
17+
sort -k2

src/partition/test-repart.sh

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
#!/usr/bin/env bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
3-
set -ex
3+
set -eux
4+
set -o pipefail
45

56
[[ -e /dev/loop-control ]] || exit 77
67

7-
repart=$1
8-
test -x $repart
8+
repart="${1:?}"
9+
test -x "$repart"
910

10-
D=$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX")
11+
D="$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX")"
12+
13+
# shellcheck disable=SC2064
1114
trap "rm -rf '$D'" EXIT INT QUIT PIPE
12-
mkdir -p $D/definitions
15+
mkdir -p "$D/definitions"
1316

1417
SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
1518

1619
echo "### Testing systemd-repart --empty=create ###"
1720

18-
$repart $D/zzz --empty=create --size=1G --seed=$SEED
21+
"$repart" "$D/zzz" --empty=create --size=1G --seed="$SEED"
1922

20-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/empty
23+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/empty"
2124

22-
cmp $D/empty - <<EOF
25+
cmp "$D/empty" - <<EOF
2326
label: gpt
2427
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
2528
device: $D/zzz
@@ -30,32 +33,32 @@ EOF
3033

3134
echo "### Testing with root, root2, home, & swap ###"
3235

33-
cat >$D/definitions/root.conf <<EOF
36+
cat >"$D/definitions/root.conf" <<EOF
3437
[Partition]
3538
Type=root-x86-64
3639
EOF
3740

38-
ln -s root.conf $D/definitions/root2.conf
41+
ln -s root.conf "$D/definitions/root2.conf"
3942

40-
cat >$D/definitions/home.conf <<EOF
43+
cat >"$D/definitions/home.conf" <<EOF
4144
[Partition]
4245
Type=home
4346
Label=home-first
4447
Label=home-always-too-long-xxxxxxxxxxxxxx-%v
4548
EOF
4649

47-
cat >$D/definitions/swap.conf <<EOF
50+
cat >"$D/definitions/swap.conf" <<EOF
4851
[Partition]
4952
Type=swap
5053
SizeMaxBytes=64M
5154
PaddingMinBytes=92M
5255
EOF
5356

54-
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
57+
"$repart" "$D/zzz" --dry-run=no --seed="$SEED" --definitions="$D/definitions"
5558

56-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated
59+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated"
5760

58-
cmp $D/populated - <<EOF
61+
cmp "$D/populated" - <<EOF
5962
label: gpt
6063
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
6164
device: $D/zzz
@@ -70,27 +73,27 @@ EOF
7073

7174
echo "### Testing with root, root2, home, swap, & another partition ###"
7275

73-
cat >$D/definitions/swap.conf <<EOF
76+
cat >"$D/definitions/swap.conf" <<EOF
7477
[Partition]
7578
Type=swap
7679
SizeMaxBytes=64M
7780
EOF
7881

79-
cat >$D/definitions/extra.conf <<EOF
82+
cat >"$D/definitions/extra.conf" <<EOF
8083
[Partition]
8184
Type=linux-generic
8285
Label=custom_label
8386
UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
8487
EOF
8588

86-
echo "Label=ignored_label" >>$D/definitions/home.conf
87-
echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>$D/definitions/home.conf
89+
echo "Label=ignored_label" >>"$D/definitions/home.conf"
90+
echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$D/definitions/home.conf"
8891

89-
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
92+
"$repart" "$D/zzz" --dry-run=no --seed="$SEED" --definitions="$D/definitions"
9093

91-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2
94+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated2"
9295

93-
cmp $D/populated2 - <<EOF
96+
cmp "$D/populated2" - <<EOF
9497
label: gpt
9598
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
9699
device: $D/zzz
@@ -106,11 +109,11 @@ EOF
106109

107110
echo "### Resizing to 2G ###"
108111

109-
$repart $D/zzz --size=2G --dry-run=no --seed=$SEED --definitions=$D/definitions
112+
"$repart" "$D/zzz" --size=2G --dry-run=no --seed="$SEED" --definitions="$D/definitions"
110113

111-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated3
114+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated3"
112115

113-
cmp $D/populated3 - <<EOF
116+
cmp "$D/populated3" - <<EOF
114117
label: gpt
115118
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
116119
device: $D/zzz
@@ -124,23 +127,23 @@ $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-09
124127
$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
125128
EOF
126129

127-
dd if=/dev/urandom of=$D/block-copy bs=4096 count=10240
130+
dd if=/dev/urandom of="$D/block-copy" bs=4096 count=10240
128131

129132
echo "### Testing with root, root2, home, swap, another partition, & partition copy ###"
130133

131-
cat >$D/definitions/extra2.conf <<EOF
134+
cat >"$D/definitions/extra2.conf" <<EOF
132135
[Partition]
133136
Type=linux-generic
134137
Label=block-copy
135138
UUID=2a1d97e1d0a346cca26eadc643926617
136139
CopyBlocks=$D/block-copy
137140
EOF
138141

139-
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions
142+
"$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions"
140143

141-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated4
144+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated4"
142145

143-
cmp $D/populated4 - <<EOF
146+
cmp "$D/populated4" - <<EOF
144147
label: gpt
145148
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
146149
device: $D/zzz
@@ -155,14 +158,14 @@ $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D
155158
$D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name="block-copy"
156159
EOF
157160

158-
cmp --bytes=41943040 --ignore-initial=0:$((512*4194264)) $D/block-copy $D/zzz
161+
cmp --bytes=41943040 --ignore-initial=0:$((512*4194264)) "$D/block-copy" "$D/zzz"
159162

160-
if [ `id -u` == 0 ] && type -P cryptsetup diff losetup > /dev/null ; then
163+
if [ "$(id -u)" -eq 0 ] && type -P cryptsetup diff losetup >/dev/null ; then
161164
echo "### Testing Format=/Encrypt=/CopyFiles="
162165

163166
# These tests require privileges unfortunately
164167

165-
cat >$D/definitions/extra3.conf <<EOF
168+
cat >"$D/definitions/extra3.conf" <<EOF
166169
[Partition]
167170
Type=linux-generic
168171
Label=luks-format-copy
@@ -173,11 +176,11 @@ CopyFiles=$D/definitions:/def
173176
SizeMinBytes=48M
174177
EOF
175178

176-
$repart $D/zzz --size=auto --dry-run=no --seed=$SEED --definitions=$D/definitions
179+
"$repart" "$D/zzz" --size=auto --dry-run=no --seed="$SEED" --definitions="$D/definitions"
177180

178-
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated5
181+
sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated5"
179182

180-
cmp $D/populated5 - <<EOF
183+
cmp "$D/populated5" - <<EOF
181184
label: gpt
182185
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
183186
device: $D/zzz
@@ -193,23 +196,23 @@ $D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D
193196
$D/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name="luks-format-copy"
194197
EOF
195198

196-
LOOP=`losetup -P --show --find $D/zzz`
197-
VOLUME=test-repart-$RANDOM
199+
LOOP="$(losetup -P --show --find "$D/zzz")"
200+
VOLUME="test-repart-$RANDOM"
198201

199-
touch $D/empty-password
200-
cryptsetup open --type=luks2 --key-file=$D/empty-password ${LOOP}p7 $VOLUME
201-
mkdir $D/mount
202-
mount -t ext4 /dev/mapper/$VOLUME $D/mount
202+
touch "$D/empty-password"
203+
cryptsetup open --type=luks2 --key-file="$D/empty-password" "${LOOP}p7" "$VOLUME"
204+
mkdir "$D/mount"
205+
mount -t ext4 "/dev/mapper/$VOLUME" "$D/mount"
203206
# Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount
204-
cryptsetup close --deferred $VOLUME
205-
losetup -d $LOOP
206-
diff -r $D/mount/def $D/definitions > /dev/null
207-
umount $D/mount
207+
cryptsetup close --deferred "$VOLUME"
208+
losetup -d "$LOOP"
209+
diff -r "$D/mount/def" "$D/definitions" >/dev/null
210+
umount "$D/mount"
208211
else
209212
echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup"
210213
fi
211214

212215
echo "### Testing json output ###"
213-
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=help
214-
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=pretty
215-
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=short
216+
"$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=help
217+
"$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=pretty
218+
"$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=short
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33

44
set -eu
5+
set -o pipefail
56

6-
$1 -dM -include netinet/in.h - </dev/null | \
7-
awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
8-
sed -e 's/IPPROTO_//'
7+
${1:?} -dM -include netinet/in.h - </dev/null | \
8+
awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
9+
sed -e 's/IPPROTO_//'

src/udev/generate-keyboard-keys-gperf.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33
set -eu
44

5+
# shellcheck disable=SC1004
56
awk '
67
BEGIN {
78
print "%{\n\
@@ -16,4 +17,4 @@ _Pragma(\"GCC diagnostic ignored \\\"-Wimplicit-fallthrough\\\"\")\n\
1617
1718
/^KEY_/ { print tolower(substr($1 ,5)) ", " $1 }
1819
{ print tolower($1) ", " $1 }
19-
' < "$1"
20+
' < "${1:?}"

0 commit comments

Comments
 (0)
X Tutup