Laszlo Ersek
2023-Jan-19 12:14 UTC
[Libguestfs] [p2v PATCH 3/4] make-disk: replace here-docs with printfs for better indentation
Here-documents break the indentation of the script; replace them with the "printf" shell utility. (We could use the <<- redirection operator for stripping leading TABs from the here-docs, but the script itself does not use TABs for indentation, so that would introduce a different kind of inconsistency.) Because we use a quoted word ('EOF') for our delimiter in the here-documents, variables in the here-docs are not expanded; stick with that. Use a sole '%s\n' format operand with each printf invocation: "[t]he /format/ operand shall be reused as often as necessary to satisfy the /argument/ operands" <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html>. (I've tried to regression-test this with the two latest Ubuntu images: ubuntu-18.04, ubuntu-20.04. The former wouldn't build, and the latter only booted to a GDM login screen. My build host is RHEL-9.1, so the kiosk is not actually expected to work. Any further investigation here is left to Ubuntu users. The Fedora 37 image works fine, even with the virt-p2v binary coming from RHEL-9.1.) Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- virt-p2v-make-disk.in | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/virt-p2v-make-disk.in b/virt-p2v-make-disk.in index 44ff0b45ac7a..0bf7f0e0414f 100644 --- a/virt-p2v-make-disk.in +++ b/virt-p2v-make-disk.in @@ -170,15 +170,15 @@ xzcat "$virt_p2v_xz_binary" > "$virt_p2v_binary" case "$osversion" in centos-*|fedora-*|rhel-*|scientificlinux-*|oraclelinux-*) depsfile="$datadir/dependencies.redhat" - cat > $tmpdir/p2v.conf <<'EOF' -add_drivers+=" usb-storage " -EOF - cat > $tmpdir/post-install <<'EOF' -#!/bin/bash -# Rebuild the initramfs. -latest_version="$(cd /lib/modules; ls -1vr | head -1)" -dracut -v -f --kver $latest_version -EOF + printf '%s\n' \ + 'add_drivers+=" usb-storage "' \ + > $tmpdir/p2v.conf + printf '%s\n' \ + '#!/bin/bash' \ + '# Rebuild the initramfs.' \ + 'latest_version="$(cd /lib/modules; ls -1vr | head -1)"' \ + 'dracut -v -f --kver $latest_version' \ + > $tmpdir/post-install # Double quotes because we want $tmpdir to be expanded: extra_args=" --selinux-relabel @@ -201,11 +201,11 @@ EOF ;; debian-*|ubuntu-*) depsfile="$datadir/dependencies.debian" - cat > $tmpdir/policy-rc.d <<'EOF' -#!/bin/sh -# Avoid running daemons during the upgrade/installation -exit 101 -EOF + printf '%s\n' \ \ + '#!/bin/sh' \ + '# Avoid running daemons during the upgrade/installation' \ + 'exit 101' \ + > $tmpdir/policy-rc.d chmod +x $tmpdir/policy-rc.d # Double quotes because we want $tmpdir to be expanded: preinstall_args="
Richard W.M. Jones
2023-Jan-19 18:56 UTC
[Libguestfs] [p2v PATCH 3/4] make-disk: replace here-docs with printfs for better indentation
On Thu, Jan 19, 2023 at 01:14:47PM +0100, Laszlo Ersek wrote:> Here-documents break the indentation of the script; replace them with the > "printf" shell utility. (We could use the <<- redirection operator for > stripping leading TABs from the here-docs, but the script itself does not > use TABs for indentation, so that would introduce a different kind of > inconsistency.) > > Because we use a quoted word ('EOF') for our delimiter in the > here-documents, variables in the here-docs are not expanded; stick with > that. > > Use a sole '%s\n' format operand with each printf invocation: "[t]he > /format/ operand shall be reused as often as necessary to satisfy the > /argument/ operands" > <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html>. > > (I've tried to regression-test this with the two latest Ubuntu images: > ubuntu-18.04, ubuntu-20.04. The former wouldn't build, and the latter only > booted to a GDM login screen. My build host is RHEL-9.1, so the kiosk is > not actually expected to work. Any further investigation here is left to > Ubuntu users. > > The Fedora 37 image works fine, even with the virt-p2v binary coming from > RHEL-9.1.) > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > virt-p2v-make-disk.in | 28 ++++++++++++++-------------- > 1 file changed, 14 insertions(+), 14 deletions(-) > > diff --git a/virt-p2v-make-disk.in b/virt-p2v-make-disk.in > index 44ff0b45ac7a..0bf7f0e0414f 100644 > --- a/virt-p2v-make-disk.in > +++ b/virt-p2v-make-disk.in > @@ -170,15 +170,15 @@ xzcat "$virt_p2v_xz_binary" > "$virt_p2v_binary" > case "$osversion" in > centos-*|fedora-*|rhel-*|scientificlinux-*|oraclelinux-*) > depsfile="$datadir/dependencies.redhat" > - cat > $tmpdir/p2v.conf <<'EOF' > -add_drivers+=" usb-storage " > -EOF > - cat > $tmpdir/post-install <<'EOF' > -#!/bin/bash > -# Rebuild the initramfs. > -latest_version="$(cd /lib/modules; ls -1vr | head -1)" > -dracut -v -f --kver $latest_version > -EOF > + printf '%s\n' \ > + 'add_drivers+=" usb-storage "' \ > + > $tmpdir/p2v.conf > + printf '%s\n' \ > + '#!/bin/bash' \ > + '# Rebuild the initramfs.' \ > + 'latest_version="$(cd /lib/modules; ls -1vr | head -1)"' \ > + 'dracut -v -f --kver $latest_version' \ > + > $tmpdir/post-install > # Double quotes because we want $tmpdir to be expanded: > extra_args=" > --selinux-relabel > @@ -201,11 +201,11 @@ EOF > ;; > debian-*|ubuntu-*) > depsfile="$datadir/dependencies.debian" > - cat > $tmpdir/policy-rc.d <<'EOF' > -#!/bin/sh > -# Avoid running daemons during the upgrade/installation > -exit 101 > -EOF > + printf '%s\n' \ \ > + '#!/bin/sh' \ > + '# Avoid running daemons during the upgrade/installation' \ > + 'exit 101' \ > + > $tmpdir/policy-rc.d > chmod +x $tmpdir/policy-rc.d > # Double quotes because we want $tmpdir to be expanded: > preinstall_args="Interesting - didn't know this would work ... $ printf '%s\n' 'abc' 'def' 123 abc def 123 It seems like it applies the format pattern to every parameter?! I verified this works both with bash printf and coreutils. bash info says: The FORMAT is reused as necessary to consume all of the ARGUMENTS. If the FORMAT requires more ARGUMENTS than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-zero on failure. and almost the same text appears in coreutils info. So there we are. ACK! Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW