From 437e889b18743ea4d594521829e43b6067ce9036 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 19 Apr 2021 18:07:51 +0200 Subject: [PATCH] src: shellcheck-ify shell scripts --- src/basic/generate-af-list.sh | 9 +- src/basic/generate-arphrd-list.sh | 9 +- src/basic/generate-cap-list.sh | 9 +- src/basic/generate-errno-list.sh | 7 +- src/basic/linux/update.sh | 9 +- src/boot/efi/no-undefined-symbols.sh | 5 +- .../sd-journal/generate-audit_type-list.sh | 17 +-- src/partition/test-repart.sh | 101 +++++++++--------- src/shared/generate-ip-protocol-list.sh | 9 +- src/udev/generate-keyboard-keys-gperf.sh | 3 +- src/udev/generate-keyboard-keys-list.sh | 5 +- 11 files changed, 98 insertions(+), 85 deletions(-) diff --git a/src/basic/generate-af-list.sh b/src/basic/generate-af-list.sh index 0a5c5c4cd76..f747e0d0659 100755 --- a/src/basic/generate-af-list.sh +++ b/src/basic/generate-af-list.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eu +set -o pipefail -$1 -E -dM -include sys/socket.h -include "$2" -include "$3" - / d' $i + sed -i -e 's/__user //g' -e '/^#include / d' "$i" done diff --git a/src/boot/efi/no-undefined-symbols.sh b/src/boot/efi/no-undefined-symbols.sh index b9541c31266..8bdb16accf2 100755 --- a/src/boot/efi/no-undefined-symbols.sh +++ b/src/boot/efi/no-undefined-symbols.sh @@ -1,8 +1,9 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: LGPL-2.1-or-later 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!" exit 1 fi diff --git a/src/libsystemd/sd-journal/generate-audit_type-list.sh b/src/libsystemd/sd-journal/generate-audit_type-list.sh index d5b145f31d2..aad653c1286 100755 --- a/src/libsystemd/sd-journal/generate-audit_type-list.sh +++ b/src/libsystemd/sd-journal/generate-audit_type-list.sh @@ -1,16 +1,17 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eu +set -o pipefail -cpp="$1" +cpp="${1:?}" shift -includes="" +includes=() for i in "$@"; do - includes="$includes -include $i" + includes+=(-include "$i") done -$cpp -dM $includes - $D/empty +sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/empty" -cmp $D/empty - <$D/definitions/root.conf <"$D/definitions/root.conf" <$D/definitions/home.conf <"$D/definitions/home.conf" <$D/definitions/swap.conf <"$D/definitions/swap.conf" <$D/populated +sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated" -cmp $D/populated - <$D/definitions/swap.conf <"$D/definitions/swap.conf" <$D/definitions/extra.conf <"$D/definitions/extra.conf" <>$D/definitions/home.conf -echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>$D/definitions/home.conf +echo "Label=ignored_label" >>"$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 - <$D/populated3 +sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated3" -cmp $D/populated3 - <$D/definitions/extra2.conf <"$D/definitions/extra2.conf" <$D/populated4 +sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated4" -cmp $D/populated4 - < /dev/null ; then +if [ "$(id -u)" -eq 0 ] && type -P cryptsetup diff losetup >/dev/null ; then echo "### Testing Format=/Encrypt=/CopyFiles=" # These tests require privileges unfortunately - cat >$D/definitions/extra3.conf <"$D/definitions/extra3.conf" <$D/populated5 + sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated5" - cmp $D/populated5 - < /dev/null - umount $D/mount + cryptsetup close --deferred "$VOLUME" + losetup -d "$LOOP" + diff -r "$D/mount/def" "$D/definitions" >/dev/null + umount "$D/mount" else echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup" fi 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=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=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=short diff --git a/src/shared/generate-ip-protocol-list.sh b/src/shared/generate-ip-protocol-list.sh index 749a1305c1b..1144e8027fb 100755 --- a/src/shared/generate-ip-protocol-list.sh +++ b/src/shared/generate-ip-protocol-list.sh @@ -1,8 +1,9 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eu +set -o pipefail -$1 -dM -include netinet/in.h - / { next } /^#define[ \t]+(KEY|BTN)_[^ ]+[ \t]+[0-9BK]/ { print $2 } '