x86: preinit: make name rewrite into reusable function
authorPhilip Prindeville <philipp@redfish-solutions.com>
Mon, 30 Oct 2017 18:31:04 +0000 (12:31 -0600)
committerJo-Philipp Wich <jo@mein.io>
Thu, 4 Jan 2018 12:44:42 +0000 (13:44 +0100)
There might be other places (such as vendor-supplied preinit scripts)
where we wish to take a DMI name and clean it up in a consistent way,
so make the sed command into a function.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
target/linux/x86/base-files/lib/preinit/01_sysinfo

index cb63a04..3c21c07 100644 (file)
@@ -1,3 +1,12 @@
+sanitize_name_x86() {
+       sed -e '
+               y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;
+               s/[^a-z0-9_-]\+/-/g;
+               s/^-//;
+               s/-$//;
+       ' "$@"
+}
+
 do_sysinfo_x86() {
        local vendor product file
 
@@ -17,12 +26,7 @@ do_sysinfo_x86() {
 
        echo "$vendor $product" > /tmp/sysinfo/model
 
-       sed -e '
-               y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;
-               s/[^a-z0-9_-]\+/-/g;
-               s/^-//;
-               s/-$//;
-       ' /tmp/sysinfo/model > /tmp/sysinfo/board_name
+       sanitize_name_x86 /tmp/sysinfo/model > /tmp/sysinfo/board_name
 }
 
 boot_hook_add preinit_main do_sysinfo_x86