mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Roland Hieber <rohieb@rohieb.name>
To: ptxdist@pengutronix.de
Cc: Roland Hieber <rohieb@rohieb.name>
Subject: [ptxdist] [PATCH 1/2] install_replace_figlet: allow escaping the figlet output
Date: Fri,  1 Dec 2017 00:31:29 +0100	[thread overview]
Message-ID: <20171130233130.16278-2-rohieb@rohieb.name> (raw)
In-Reply-To: <20171130233130.16278-1-rohieb@rohieb.name>

All known gettys in PTXdist allow inserting variables into /etc/issue by
prefixing certain characters with backslashes (e.g. a literal '\v'
expands to the kernel version from uname -v). In this case, '\'s in the
figlet output must be escaped accordingly so they are displayed as '\'s
on the screen.

For readability, refactor the code into a new local function. Then
add a new parameter describing the escape mode ('etcissue' or none, the
default) as a new, fifth parameter to install_replace_figlet. Currently,
install_replace_figlet is only used in rootfs.make on /etc/issue, and
the chance that we break existing code with the new default should be
small.

Signed-off-by: Roland Hieber <rohieb@rohieb.name>
---
 rules/post/install.make           |  4 +++-
 scripts/lib/ptxd_make_xpkg_pkg.sh | 20 ++++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/rules/post/install.make b/rules/post/install.make
index c40e36eb6..c0e24569e 100644
--- a/rules/post/install.make
+++ b/rules/post/install.make
@@ -301,14 +301,16 @@ install_replace = \
 # $2: filename
 # $3: placeholder
 # $4: value
+# $5: escape mode (empty or 'etcissue')
 #
 install_replace_figlet = \
 	XPKG=$(subst _,-,$(strip $(1)));							\
 	FILE=$(strip $(2));									\
 	PLACEHOLDER=$(strip $(3));								\
 	VALUE=$(strip $(4));									\
+	ESCAPEMODE=$(strip $(5));									\
 	$(call install_check, install_replace);							\
-	echo "ptxd_install_replace_figlet '$$FILE' '$$PLACEHOLDER' '$$VALUE'" >> "$(STATEDIR)/$$XPKG.cmds"
+	echo "ptxd_install_replace_figlet '$$FILE' '$$PLACEHOLDER' '$$VALUE' '$$ESCAPEMODE'" >> "$(STATEDIR)/$$XPKG.cmds"
 
 #
 # install_script_replace
diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh
index 4efc31630..eb3452e3a 100644
--- a/scripts/lib/ptxd_make_xpkg_pkg.sh
+++ b/scripts/lib/ptxd_make_xpkg_pkg.sh
@@ -567,6 +567,7 @@ ptxd_install_replace_figlet() {
     local dst="$1"
     local placeholder="$2"
     local value="$3"
+    local escapemode="$4"
     local -a dirs ndirs pdirs sdirs ddirs
     local mod_nfs mod_rw
 
@@ -578,8 +579,23 @@ install replace figlet:
 " &&
 
     ptxd_exist "${dirs[@]/%/${dst}}" &&
-    figlet="$(figlet -d "${PTXDIST_SYSROOT_HOST}/share/figlet" -- "${value}" | \
-	awk '{ gsub("\\\\", "`"); if ($0 !~ "^ *$") printf("%s\\n", $0) }')" && #`
+    ptxd_figlet_helper() {
+        local value="$1"
+        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 }' ;;
+            *)		;;
+        esac | \
+        awk '{ if ($0 !~ "^ *$") printf("%s\\n", $0) }'  # newlines for sed
+    } &&
+    figlet="$(ptxd_figlet_helper "$value" "$escapemode")" &&
     sed -i -e "s#${placeholder}#${figlet}#g" "${dirs[@]/%/${dst}}" ||
 
     ptxd_install_error "install_replace failed!"
-- 
2.15.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

  reply	other threads:[~2017-11-30 23:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30 23:31 [ptxdist] [PATCH 0/2] improve type design in the login banner Roland Hieber
2017-11-30 23:31 ` Roland Hieber [this message]
2017-11-30 23:31 ` [ptxdist] [PATCH 2/2] rootfs: correctly escape /etc/issue figlets Roland Hieber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171130233130.16278-2-rohieb@rohieb.name \
    --to=rohieb@rohieb.name \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox