summaryrefslogtreecommitdiff
path: root/meta-phosphor
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2021-10-21 19:10:45 +0300
committerPatrick Williams <patrick@stwcx.xyz>2021-12-15 22:25:40 +0300
commit5905d41d62ccd752ba38f7c8a4bf2fa9c57a5238 (patch)
treef25b42e392d7b0efa72ad85eadc2da51970a414d /meta-phosphor
parent5abb7ee32973c3959f5f498f9f6396017b2f3622 (diff)
downloadopenbmc-5905d41d62ccd752ba38f7c8a4bf2fa9c57a5238.tar.xz
Add bbclass to copy license info to /usr/share/www
Some products have requirements for the source license info to be made available to users. This adds a bbclass that copies the license info stored in /usr/share/common-licenses to /usr/share/www/common-licenses. From there it is served to users by bmcweb in the existing webassets.hpp functionality. File paths will show users the file content, but directories will only display content in an index.* file. So, the bbclass also creates an index.json for each directory so that directory paths will show users the directory contents. Tested: Navigated to /common-licenses and common-licenses/ and confirmed that the directory listing was displayed. Navigated to /common-licenses/bmcweb and common-licenses/bmcweb/ and confirmed that the directory listing was displayed. Navigated to /common-licenses/bmcweb/LICENSE and confirmed that the license text was displayed. Navigated to /common-licenses/../../network/config.json and it returned "Not Found". Navigated to /common-licenses/../ipmi-providers/channel_access.json and it returned "Not Found". Change-Id: I286b0cf53a9520087b1a57b17ea66f408f08ed3b Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'meta-phosphor')
-rw-r--r--meta-phosphor/classes/license_static.bbclass64
1 files changed, 64 insertions, 0 deletions
diff --git a/meta-phosphor/classes/license_static.bbclass b/meta-phosphor/classes/license_static.bbclass
new file mode 100644
index 000000000..dd7301758
--- /dev/null
+++ b/meta-phosphor/classes/license_static.bbclass
@@ -0,0 +1,64 @@
+####
+# Copyright 2021 Intel Corporation
+#
+# Add a class to support serving license info through bmcweb.
+#
+# bmcweb serves static content from the /usr/share/www folder, so this class
+# copies the license info from /usr/share/common-licenses to
+# /usr/share/www/common-licenses so it will be statically served by bmcweb.
+#
+# Requires 'COPY_LIC_DIRS' to be enabled to create /usr/share/common-licenses.
+#
+# Class can be inherited in a project bbclass to copy the license info.
+#
+# Example:
+# inherit license_static
+####
+
+STATIC_LICENSE_DIR = "${IMAGE_ROOTFS}/usr/share/www/common-licenses"
+
+
+def add_index_html_header(f):
+ f.write("<!DOCTYPE html>")
+ f.write("<html>")
+ f.write("<body>")
+ f.write("<p>")
+
+
+def add_index_html_footer(f):
+ f.write("</p>")
+ f.write("</body>")
+ f.write("</html>")
+
+
+def create_index_files(d):
+ import os
+
+ static_license_dir = d.getVar('STATIC_LICENSE_DIR')
+ for dirpath, dirnames, filenames in os.walk(static_license_dir):
+ with open(os.path.join(dirpath, "index.html"), "w") as f:
+ add_index_html_header(f)
+ full_list = filenames+dirnames
+ full_list.sort()
+ f.write("<br>".join(full_list))
+ add_index_html_footer(f)
+
+
+def copy_license_files(d):
+ import shutil
+
+ rootfs_license_dir = d.getVar('ROOTFS_LICENSE_DIR')
+ static_license_dir = d.getVar('STATIC_LICENSE_DIR')
+ shutil.copytree(rootfs_license_dir, static_license_dir)
+
+
+python do_populate_static_lic() {
+ copy_lic_dirs = d.getVar('COPY_LIC_DIRS')
+ if copy_lic_dirs == "1":
+ copy_license_files(d)
+ create_index_files(d)
+ else:
+ bb.warn("Static licenses not copied because 'COPY_LIC_DIRS' is disabled.")
+}
+
+ROOTFS_POSTPROCESS_COMMAND:append = "do_populate_static_lic; "