mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes
@ 2018-09-19  8:43 Uwe Kleine-König
  2018-10-05 15:50 ` Robert Schwebel
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2018-09-19  8:43 UTC (permalink / raw)
  To: ptxdist

TL;DR: awk and backslashes in the replacement argument of gsub is ugly.

With GNU Awk 4.0.2 we have:

	$ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }'
	\\\\\\\\

and with GNU Awk 4.1.4 (and newer) we have:

	$ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }'
	\\\\

This results in too much backslashes in /etc/issues for users of the
former version.

For the glory details I recommend reading through

	https://www.gnu.org/software/gawk/manual/html_node/Gory-Details.html
	https://bugs.debian.org/909147

As it's awkward to come up with an expression that does the same on both
versions (e.g. using --posix) use sed instead.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 scripts/lib/ptxd_make_xpkg_pkg.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh
index 5e69cefdc85d..685f4e549446 100644
--- a/scripts/lib/ptxd_make_xpkg_pkg.sh
+++ b/scripts/lib/ptxd_make_xpkg_pkg.sh
@@ -584,13 +584,13 @@ install replace figlet:
         local escapemode="$2"
         figlet -d "${PTXDIST_SYSROOT_HOST}/share/figlet" -- "${value}" | \
         case "$escapemode" in
-            # a lot of leaning toothpicks because we need to escape a literal
-            # '\' with '\\' on multiple levels:
-            # - one level for the string inside awk: \\\\\\\\\\\\\\\\ -> \\\\\\\\
-            # - one level for the shell string after sed -e:          -> \\\\
-            # - one level for the s expression inside sed:            -> \\
-            # - and finally, one level for /etc/issue:                -> \
-            etcissue)	awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }' ;;
+            # /etc/issue needs each backslash quoted by another backslash. As
+            # the string is interpreted by the shell once more below, another
+            # level of quoting is needed such that every \ in the output of
+            # figlet needs to be replaced by \\\\. As a \ in sed needs to be
+            # quoted, too, this results in eight backslashes in the replacement
+            # string.
+            etcissue)	sed 's,\\,\\\\\\\\,';;
             *)		;;
         esac | \
         awk '{ if ($0 !~ "^ *$") printf("%s\\n", $0) }'  # newlines for sed
-- 
2.19.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ptxdist] [PATCH] ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes
  2018-09-19  8:43 [ptxdist] [PATCH] ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes Uwe Kleine-König
@ 2018-10-05 15:50 ` Robert Schwebel
  2018-10-05 20:52   ` [ptxdist] [PATCH] ptxd_install_replace_figlet: replace all backslashes, not only the first Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Schwebel @ 2018-10-05 15:50 UTC (permalink / raw)
  To: ptxdist

Hi Uwe,

On Wed, Sep 19, 2018 at 10:43:36AM +0200, Uwe Kleine-König wrote:
> TL;DR: awk and backslashes in the replacement argument of gsub is ugly.
> 
> With GNU Awk 4.0.2 we have:
> 
> 	$ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }'
> 	\\\\\\\\
> 
> and with GNU Awk 4.1.4 (and newer) we have:
> 
> 	$ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }'
> 	\\\\
> 
> This results in too much backslashes in /etc/issues for users of the
> former version.
> 
> For the glory details I recommend reading through
> 
> 	https://www.gnu.org/software/gawk/manual/html_node/Gory-Details.html
> 	https://bugs.debian.org/909147
> 
> As it's awkward to come up with an expression that does the same on both
> versions (e.g. using --posix) use sed instead.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This has now landed in ptxdist-2018.10.0, and it is broken.
Here is what DistroKit outputs:

 ____                        _                   _      
|  _ \ ___ _ __   __ _ _   _| |_ _ __ ___  _ __ (_)_  __
| |_) / _ \ '_  / _` | | | | __| '__/ _ | '_ |  / /
|  __/  __/ | | | (_| | |_| | |_| | | (_) | | | | |>  < 
|_|   \___|_| |_|__, |__,_|__|_|  ___/|_| |_|_/_/_DistroKit                 |___/                                  

 ____  _     _             _  ___ _   
|  _ \(_)___| |_ _ __ ___ | |/ (_) |_ 
| | | | / __| __| '__/ _ \| ' /| | __|
| |_| | \__  |_| | | (_) | . | | |_ 
|____/|_|___/\__|_|  ___/|_|__|__|

rsc
-- 
Pengutronix e.K.                           | Dipl.-Ing. Robert Schwebel  |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ptxdist] [PATCH] ptxd_install_replace_figlet: replace all backslashes, not only the first
  2018-10-05 15:50 ` Robert Schwebel
@ 2018-10-05 20:52   ` Uwe Kleine-König
  2018-10-06 10:30     ` Robert Schwebel
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2018-10-05 20:52 UTC (permalink / raw)
  To: ptxdist; +Cc: Robert Schwebel

Fixes: f53889792197 ("ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 scripts/lib/ptxd_make_xpkg_pkg.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh
index b3f2f20f3e4e..766d46ac3238 100644
--- a/scripts/lib/ptxd_make_xpkg_pkg.sh
+++ b/scripts/lib/ptxd_make_xpkg_pkg.sh
@@ -587,7 +587,7 @@ install replace figlet:
             # figlet needs to be replaced by \\\\. As a \ in sed needs to be
             # quoted, too, this results in eight backslashes in the replacement
             # string.
-            etcissue)	sed 's,\\,\\\\\\\\,';;
+            etcissue)	sed 's,\\,\\\\\\\\,g';;
             *)		;;
         esac | \
         awk '{ if ($0 !~ "^ *$") printf("%s\\n", $0) }'  # newlines for sed
-- 
2.19.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ptxdist] [PATCH] ptxd_install_replace_figlet: replace all backslashes, not only the first
  2018-10-05 20:52   ` [ptxdist] [PATCH] ptxd_install_replace_figlet: replace all backslashes, not only the first Uwe Kleine-König
@ 2018-10-06 10:30     ` Robert Schwebel
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Schwebel @ 2018-10-06 10:30 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: ptxdist

On Fri, Oct 05, 2018 at 10:52:12PM +0200, Uwe Kleine-König wrote:
> Fixes: f53889792197 ("ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  scripts/lib/ptxd_make_xpkg_pkg.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh
> index b3f2f20f3e4e..766d46ac3238 100644
> --- a/scripts/lib/ptxd_make_xpkg_pkg.sh
> +++ b/scripts/lib/ptxd_make_xpkg_pkg.sh
> @@ -587,7 +587,7 @@ install replace figlet:
>              # figlet needs to be replaced by \\\\. As a \ in sed needs to be
>              # quoted, too, this results in eight backslashes in the replacement
>              # string.
> -            etcissue)	sed 's,\\,\\\\\\\\,';;
> +            etcissue)	sed 's,\\,\\\\\\\\,g';;
>              *)		;;
>          esac | \
>          awk '{ if ($0 !~ "^ *$") printf("%s\\n", $0) }'  # newlines for sed
> -- 
> 2.19.0

Tested-by: Robert Schwebel <r.schwebel@pengutronix.de>

on DistroKit.

rsc
-- 
Pengutronix e.K.                           | Dipl.-Ing. Robert Schwebel  |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-06 10:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19  8:43 [ptxdist] [PATCH] ptxd_install_replace_figlet: Use sed instead of awk to quote backslashes Uwe Kleine-König
2018-10-05 15:50 ` Robert Schwebel
2018-10-05 20:52   ` [ptxdist] [PATCH] ptxd_install_replace_figlet: replace all backslashes, not only the first Uwe Kleine-König
2018-10-06 10:30     ` Robert Schwebel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox