From: Benjamin Poirier bpoirier@redhat.com
redhat/configs: Change script interpreter to /bin/bash
Upstream-status: RHEL-only Bugzilla: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668
When running `make dist-configs` on a system where /bin/sh is dash (rather than bash), the command fails with:
[...] Building .../redhat/configs/kernel-riscv64-rt-debug-fedora.config ... Building .../redhat/configs/kernel-riscv64-rt-debug-fedora.config complete ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution ./generate_all_configs.sh: 26: Bad substitution head: cannot open '.../redhat/configs/kernel-6.14.0*.config' for reading: No such file or directory cat: '.../redhat/configs/kernel-6.14.0*.config': No such file or directory Processing .../redhat/configs/kernel-6.14.0*.config ... .../Makefile:750: arch//Makefile: No such file or directory make[3]: *** No rule to make target 'arch//Makefile'. Stop. make[2]: *** [Makefile:263: __sub-make] Error 2 make[1]: *** [Makefile:564: dist-configs] Error 1 make[1]: Leaving directory '.../redhat' make: *** [makefile:12: dist-configs] Error 2
The problem is due to the following substitution: ${i:$specpackage_name_len}
If we remove the shellcheck ignore, shellcheck explains: SC3057 (warning): In POSIX sh, string indexing is undefined.
Since there are already many other scripts under redhat/ which use /bin/bash as their interpreter, fix this problem by changing the interpreter for this script to use bash as well.
We can then remove the shellcheck ignore but this results in another message: SC2001 (style): See if you can use ${variable//search/replace} instead.
The code is restructured as suggested.
Signed-off-by: Benjamin Poirier bpoirier@redhat.com
diff --git a/redhat/configs/generate_all_configs.sh b/redhat/configs/generate_all_configs.sh index blahblah..blahblah 100755 --- a/redhat/configs/generate_all_configs.sh +++ b/redhat/configs/generate_all_configs.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash
# Adjusts the configuration options to build the variants correctly
@@ -22,9 +22,9 @@ fi # The +1 is to remove the - at the end of the SPECPACKAGE_NAME string specpackage_name_len=$((${#SPECPACKAGE_NAME} + 1)) for i in "${SPECPACKAGE_NAME}"*-"$FLAVOR".config; do - # shellcheck disable=SC3057 - NEW=${SPECPACKAGE_NAME}-"$SPECRPMVERSION"-$(echo "${i:$specpackage_name_len}" | sed s/-"$FLAVOR"//) - mv "$i" "$NEW" + variant=${i:$specpackage_name_len} + variant=${variant/-$FLAVOR} + mv "$i" "$SPECPACKAGE_NAME-$SPECRPMVERSION-$variant" done
rm -f kernel-*-"$SECONDARY".config
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668
From: Prarit Bhargava on gitlab.com https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668#note_2326778...
For Fedora and RHEL this should be /usr/bin/bash IIRC.
From: Benjamin Poirier on gitlab.com https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668#note_2328325...
On my Fedora and RHEL-9.5 systems, `/bin` is a symlink to `/usr/bin` so I don't think it makes a practical difference. Also, there is currently no consistency for the scripts in the redhat directory: ``` $ git grep -h '^#!.*bash' -- redhat/ | sort | uniq -c 4 #! /bin/bash 19 #!/bin/bash 3 #!/usr/bin/bash 3 #!/usr/bin/env bash ```
From: Prarit Bhargava on gitlab.com https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668#note_2330985...
I believe this will result in an rpm warning if I'm not mistaken.
From: Benjamin Poirier on gitlab.com https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3668#note_2332342...
Looking in the [build log](https://s3.amazonaws.com/arr-cki-prod-trusted- artifacts/trusted- artifacts/1650768901/build_x86_64/9011705058/artifacts/build.log) from one of the [pipeline jobs](https://gitlab.com/redhat/red-hat-ci-tools/kernel/cki- internal-pipelines/cki-trusted-contributors/-/jobs/9011705058), is this the kind of warning you are talking about: ``` mangling shebang in /usr/libexec/kselftests/net/altnames.sh from /bin/bash to #!/usr/bin/bash ``` That warning is not printed for generate_all_configs.sh, perhaps because that script is not part of any .rpm package. But anyways, I'll change the interpreter.
kernel@lists.fedoraproject.org