From 6e6b34aba300d662301b8afbf364e1d4bf8859ca Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Mon, 20 May 2024 14:46:18 +0200 Subject: [PATCH] chroot-fixups: make our scripts work again in pre-UsrMove chroots When we build csmock for RHEL-9, rpmbuild translates `/bin/bash` to `/usr/bin/bash` in our scripts. When we copy the scripts into an old chroot, such as `rhel-6-x86_64`, the translated path does not exist and the script fails with: ``` >>> 2024-05-20 12:04:36 "/usr/bin/mock" "-r" "rhel-6-x86_64" "--plugin-option=tmpfs:keep_mounted=True" "--config-opts=print_main_output=True" "--quiet" "--chroot" "/usr/share/csmock/scripts/run-shellcheck.sh /builddir/build/BUILDROOT > /builddir/shellcheck-capture.err" /bin/sh: /usr/share/csmock/scripts/run-shellcheck.sh: /usr/bin/bash: bad interpreter: No such file or directory ``` Closes: https://github.com/csutils/csmock/pull/167 --- make-srpm.sh | 2 +- scripts/chroot-fixups/00-pre-usr-move-shells.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 scripts/chroot-fixups/00-pre-usr-move-shells.sh diff --git a/make-srpm.sh b/make-srpm.sh index 13cde513..4105dff9 100755 --- a/make-srpm.sh +++ b/make-srpm.sh @@ -301,7 +301,7 @@ This package contains the unicontrol plug-in for csmock. %{_mandir}/man1/csmock.1* %{_datadir}/csmock/cwe-map.csv %{_datadir}/csmock/scripts/enable-keep-going.sh -%{_datadir}/csmock/scripts/chroot-fixups +%attr(755,root,root) %{_datadir}/csmock/scripts/chroot-fixups %{_datadir}/csmock/scripts/patch-rawbuild.sh %{python3_sitelib}/csmock/__init__.py* %{python3_sitelib}/csmock/common diff --git a/scripts/chroot-fixups/00-pre-usr-move-shells.sh b/scripts/chroot-fixups/00-pre-usr-move-shells.sh new file mode 100755 index 00000000..a43c6df6 --- /dev/null +++ b/scripts/chroot-fixups/00-pre-usr-move-shells.sh @@ -0,0 +1,13 @@ +# intentionally no shebang so that rpmbuild does not break this script +# shellcheck shell=sh + +# exit successfully if this is a post-UsrMove chroot +test -L /bin && exit 0 + +# if rpmbuild from the host env translated /bin/bash to /usr/bin/bash in our +# scripts, create a reverse symlink to make them work in the chroot env again +for sh in sh bash; do + dst=/usr/bin/${sh} + test -e ${dst} && continue + test -x /bin/${sh} && ln -sv ../../bin/${sh} $dst +done