blob: 86666665ead8685e32c41e2c322f2af63f4e7c08 [file] [log] [blame]
Jason M. Bills5905d412021-10-21 09:10:45 -07001####
2# Copyright 2021 Intel Corporation
3#
4# Add a class to support serving license info through bmcweb.
5#
6# bmcweb serves static content from the /usr/share/www folder, so this class
7# copies the license info from /usr/share/common-licenses to
8# /usr/share/www/common-licenses so it will be statically served by bmcweb.
9#
10# Requires 'COPY_LIC_DIRS' to be enabled to create /usr/share/common-licenses.
11#
12# Class can be inherited in a project bbclass to copy the license info.
13#
14# Example:
15# inherit license_static
16####
17
Patrick Williamsc7d88022023-03-24 09:39:28 -050018STATIC_LICENSE_DIR = "${IMAGE_ROOTFS}${datadir}/www/common-licenses"
Jason M. Bills5905d412021-10-21 09:10:45 -070019
20
21def add_index_html_header(f):
22 f.write("<!DOCTYPE html>")
23 f.write("<html>")
24 f.write("<body>")
25 f.write("<p>")
26
27
28def add_index_html_footer(f):
29 f.write("</p>")
30 f.write("</body>")
31 f.write("</html>")
32
33
34def create_index_files(d):
35 import os
36
37 static_license_dir = d.getVar('STATIC_LICENSE_DIR')
38 for dirpath, dirnames, filenames in os.walk(static_license_dir):
39 with open(os.path.join(dirpath, "index.html"), "w") as f:
40 add_index_html_header(f)
41 full_list = filenames+dirnames
42 full_list.sort()
43 f.write("<br>".join(full_list))
44 add_index_html_footer(f)
45
46
47def copy_license_files(d):
48 import shutil
49
50 rootfs_license_dir = d.getVar('ROOTFS_LICENSE_DIR')
51 static_license_dir = d.getVar('STATIC_LICENSE_DIR')
52 shutil.copytree(rootfs_license_dir, static_license_dir)
53
54
55python do_populate_static_lic() {
56 copy_lic_dirs = d.getVar('COPY_LIC_DIRS')
57 if copy_lic_dirs == "1":
58 copy_license_files(d)
59 create_index_files(d)
60 else:
61 bb.warn("Static licenses not copied because 'COPY_LIC_DIRS' is disabled.")
62}
63
64ROOTFS_POSTPROCESS_COMMAND:append = "do_populate_static_lic; "