1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-05 13:18:06 +03:00

src: shellcheck-ify shell scripts

This commit is contained in:
Frantisek Sumsal 2021-04-19 18:07:51 +02:00
parent 0084d4f6b5
commit 437e889b18
11 changed files with 98 additions and 85 deletions

View File

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -E -dM -include sys/socket.h -include "$2" -include "$3" - </dev/null | \ ${1:?} -E -dM -include sys/socket.h -include "${2:?}" -include "${3:?}" - </dev/null | \
grep -Ev 'AF_UNSPEC|AF_MAX' | \ grep -Ev 'AF_UNSPEC|AF_MAX' | \
awk '/^#define[ \t]+AF_[^ \t]+[ \t]+[AP]F_[^ \t]/ { print $2; }' awk '/^#define[ \t]+AF_[^ \t]+[ \t]+[AP]F_[^ \t]/ { print $2; }'

View File

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -dM -include linux/if_arp.h -include "$2" - </dev/null | \ ${1:?} -dM -include linux/if_arp.h -include "${2:?}" - </dev/null | \
awk '/^#define[ \t]+ARPHRD_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \ awk '/^#define[ \t]+ARPHRD_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
sed -e 's/ARPHRD_//' sed -e 's/ARPHRD_//'

View File

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -dM -include linux/capability.h -include "$2" -include "$3" - </dev/null | \ ${1:?} -dM -include linux/capability.h -include "${2:?}" -include "${3:?}" - </dev/null | \
awk '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $2; }' | \ awk '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $2; }' | \
grep -v CAP_LAST_CAP grep -v CAP_LAST_CAP

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -dM -include errno.h - </dev/null | \ ${1:?} -dM -include errno.h - </dev/null | \
awk '/^#define[ \t]+E[^ _]+[ \t]+/ { print $2; }' awk '/^#define[ \t]+E[^ _]+[ \t]+/ { print $2; }'

View File

@ -1,13 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
for i in *.h */*.h; do for i in *.h */*.h; do
if [[ $i == 'loadavg.h' ]]; then if [[ "$i" == "loadavg.h" ]]; then
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i -o $i curl --fail "https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i" -o "$i"
else else
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i -o $i curl --fail "https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i" -o "$i"
fi fi
sed -i -e 's/__user //g' -e '/^#include <linux\/compiler.h>/ d' $i sed -i -e 's/__user //g' -e '/^#include <linux\/compiler.h>/ d' "$i"
done done

View File

@ -1,8 +1,9 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
if nm -D -u "$1" | grep ' U '; then if nm -D -u "${1:?}" | grep ' U '; then
echo "Undefined symbols detected!" echo "Undefined symbols detected!"
exit 1 exit 1
fi fi

View File

@ -1,16 +1,17 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
cpp="$1" cpp="${1:?}"
shift shift
includes="" includes=()
for i in "$@"; do for i in "$@"; do
includes="$includes -include $i" includes+=(-include "$i")
done done
$cpp -dM $includes - </dev/null | \ $cpp -dM "${includes[@]}" - </dev/null | \
grep -vE 'AUDIT_.*(FIRST|LAST)_' | \ grep -vE 'AUDIT_.*(FIRST|LAST)_' | \
sed -r -n 's/^#define\s+AUDIT_(\w+)\s+([0-9]{4})\s*$$/\1\t\2/p' | \ sed -r -n 's/^#define\s+AUDIT_(\w+)\s+([0-9]{4})\s*$$/\1\t\2/p' | \
sort -k2 sort -k2

View File

@ -1,25 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -ex set -eux
set -o pipefail
[[ -e /dev/loop-control ]] || exit 77 [[ -e /dev/loop-control ]] || exit 77
repart=$1 repart="${1:?}"
test -x $repart test -x "$repart"
D=$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX") D="$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX")"
# shellcheck disable=SC2064
trap "rm -rf '$D'" EXIT INT QUIT PIPE trap "rm -rf '$D'" EXIT INT QUIT PIPE
mkdir -p $D/definitions mkdir -p "$D/definitions"
SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8 SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
echo "### Testing systemd-repart --empty=create ###" echo "### Testing systemd-repart --empty=create ###"
$repart $D/zzz --empty=create --size=1G --seed=$SEED "$repart" "$D/zzz" --empty=create --size=1G --seed="$SEED"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/empty sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/empty"
cmp $D/empty - <<EOF cmp "$D/empty" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -30,32 +33,32 @@ EOF
echo "### Testing with root, root2, home, & swap ###" echo "### Testing with root, root2, home, & swap ###"
cat >$D/definitions/root.conf <<EOF cat >"$D/definitions/root.conf" <<EOF
[Partition] [Partition]
Type=root-x86-64 Type=root-x86-64
EOF EOF
ln -s root.conf $D/definitions/root2.conf ln -s root.conf "$D/definitions/root2.conf"
cat >$D/definitions/home.conf <<EOF cat >"$D/definitions/home.conf" <<EOF
[Partition] [Partition]
Type=home Type=home
Label=home-first Label=home-first
Label=home-always-too-long-xxxxxxxxxxxxxx-%v Label=home-always-too-long-xxxxxxxxxxxxxx-%v
EOF EOF
cat >$D/definitions/swap.conf <<EOF cat >"$D/definitions/swap.conf" <<EOF
[Partition] [Partition]
Type=swap Type=swap
SizeMaxBytes=64M SizeMaxBytes=64M
PaddingMinBytes=92M PaddingMinBytes=92M
EOF EOF
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions "$repart" "$D/zzz" --dry-run=no --seed="$SEED" --definitions="$D/definitions"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated"
cmp $D/populated - <<EOF cmp "$D/populated" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -70,27 +73,27 @@ EOF
echo "### Testing with root, root2, home, swap, & another partition ###" echo "### Testing with root, root2, home, swap, & another partition ###"
cat >$D/definitions/swap.conf <<EOF cat >"$D/definitions/swap.conf" <<EOF
[Partition] [Partition]
Type=swap Type=swap
SizeMaxBytes=64M SizeMaxBytes=64M
EOF EOF
cat >$D/definitions/extra.conf <<EOF cat >"$D/definitions/extra.conf" <<EOF
[Partition] [Partition]
Type=linux-generic Type=linux-generic
Label=custom_label Label=custom_label
UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
EOF EOF
echo "Label=ignored_label" >>$D/definitions/home.conf echo "Label=ignored_label" >>"$D/definitions/home.conf"
echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>$D/definitions/home.conf echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$D/definitions/home.conf"
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions "$repart" "$D/zzz" --dry-run=no --seed="$SEED" --definitions="$D/definitions"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2 sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated2"
cmp $D/populated2 - <<EOF cmp "$D/populated2" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -106,11 +109,11 @@ EOF
echo "### Resizing to 2G ###" echo "### Resizing to 2G ###"
$repart $D/zzz --size=2G --dry-run=no --seed=$SEED --definitions=$D/definitions "$repart" "$D/zzz" --size=2G --dry-run=no --seed="$SEED" --definitions="$D/definitions"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated3 sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated3"
cmp $D/populated3 - <<EOF cmp "$D/populated3" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -124,11 +127,11 @@ $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-09
$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label" $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
EOF EOF
dd if=/dev/urandom of=$D/block-copy bs=4096 count=10240 dd if=/dev/urandom of="$D/block-copy" bs=4096 count=10240
echo "### Testing with root, root2, home, swap, another partition, & partition copy ###" echo "### Testing with root, root2, home, swap, another partition, & partition copy ###"
cat >$D/definitions/extra2.conf <<EOF cat >"$D/definitions/extra2.conf" <<EOF
[Partition] [Partition]
Type=linux-generic Type=linux-generic
Label=block-copy Label=block-copy
@ -136,11 +139,11 @@ UUID=2a1d97e1d0a346cca26eadc643926617
CopyBlocks=$D/block-copy CopyBlocks=$D/block-copy
EOF EOF
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated4 sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated4"
cmp $D/populated4 - <<EOF cmp "$D/populated4" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -155,14 +158,14 @@ $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D
$D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name="block-copy" $D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name="block-copy"
EOF EOF
cmp --bytes=41943040 --ignore-initial=0:$((512*4194264)) $D/block-copy $D/zzz cmp --bytes=41943040 --ignore-initial=0:$((512*4194264)) "$D/block-copy" "$D/zzz"
if [ `id -u` == 0 ] && type -P cryptsetup diff losetup > /dev/null ; then if [ "$(id -u)" -eq 0 ] && type -P cryptsetup diff losetup >/dev/null ; then
echo "### Testing Format=/Encrypt=/CopyFiles=" echo "### Testing Format=/Encrypt=/CopyFiles="
# These tests require privileges unfortunately # These tests require privileges unfortunately
cat >$D/definitions/extra3.conf <<EOF cat >"$D/definitions/extra3.conf" <<EOF
[Partition] [Partition]
Type=linux-generic Type=linux-generic
Label=luks-format-copy Label=luks-format-copy
@ -173,11 +176,11 @@ CopyFiles=$D/definitions:/def
SizeMinBytes=48M SizeMinBytes=48M
EOF EOF
$repart $D/zzz --size=auto --dry-run=no --seed=$SEED --definitions=$D/definitions "$repart" "$D/zzz" --size=auto --dry-run=no --seed="$SEED" --definitions="$D/definitions"
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated5 sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated5"
cmp $D/populated5 - <<EOF cmp "$D/populated5" - <<EOF
label: gpt label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz device: $D/zzz
@ -193,23 +196,23 @@ $D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D
$D/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name="luks-format-copy" $D/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name="luks-format-copy"
EOF EOF
LOOP=`losetup -P --show --find $D/zzz` LOOP="$(losetup -P --show --find "$D/zzz")"
VOLUME=test-repart-$RANDOM VOLUME="test-repart-$RANDOM"
touch $D/empty-password touch "$D/empty-password"
cryptsetup open --type=luks2 --key-file=$D/empty-password ${LOOP}p7 $VOLUME cryptsetup open --type=luks2 --key-file="$D/empty-password" "${LOOP}p7" "$VOLUME"
mkdir $D/mount mkdir "$D/mount"
mount -t ext4 /dev/mapper/$VOLUME $D/mount mount -t ext4 "/dev/mapper/$VOLUME" "$D/mount"
# Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount # Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount
cryptsetup close --deferred $VOLUME cryptsetup close --deferred "$VOLUME"
losetup -d $LOOP losetup -d "$LOOP"
diff -r $D/mount/def $D/definitions > /dev/null diff -r "$D/mount/def" "$D/definitions" >/dev/null
umount $D/mount umount "$D/mount"
else else
echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup" echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup"
fi fi
echo "### Testing json output ###" echo "### Testing json output ###"
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=help "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=help
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=pretty "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=pretty
$repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=short "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --json=short

View File

@ -1,8 +1,9 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -dM -include netinet/in.h - </dev/null | \ ${1:?} -dM -include netinet/in.h - </dev/null | \
awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \ awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
sed -e 's/IPPROTO_//' sed -e 's/IPPROTO_//'

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
# shellcheck disable=SC1004
awk ' awk '
BEGIN { BEGIN {
print "%{\n\ print "%{\n\
@ -16,4 +17,4 @@ _Pragma(\"GCC diagnostic ignored \\\"-Wimplicit-fallthrough\\\"\")\n\
/^KEY_/ { print tolower(substr($1 ,5)) ", " $1 } /^KEY_/ { print tolower(substr($1 ,5)) ", " $1 }
{ print tolower($1) ", " $1 } { print tolower($1) ", " $1 }
' < "$1" ' < "${1:?}"

View File

@ -1,8 +1,9 @@
#!/bin/sh #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -eu set -eu
set -o pipefail
$1 -dM -include linux/input.h - </dev/null | awk ' ${1:?} -dM -include linux/input.h - </dev/null | awk '
/\<(KEY_(MAX|MIN_INTERESTING))|(BTN_(MISC|MOUSE|JOYSTICK|GAMEPAD|DIGI|WHEEL|TRIGGER_HAPPY))\>/ { next } /\<(KEY_(MAX|MIN_INTERESTING))|(BTN_(MISC|MOUSE|JOYSTICK|GAMEPAD|DIGI|WHEEL|TRIGGER_HAPPY))\>/ { next }
/^#define[ \t]+(KEY|BTN)_[^ ]+[ \t]+[0-9BK]/ { print $2 } /^#define[ \t]+(KEY|BTN)_[^ ]+[ \t]+[0-9BK]/ { print $2 }
' '