Path: blob/main/release/scripts/oracle/generate_metadata.lua
34865 views
#!/usr/libexec/flua12local ucl = require("ucl")34-- read from environment variables5local os_type = os.getenv("TYPE")6local os_version = os.getenv("OSRELEASE")7-- the raw file8local capability_file = os.getenv("ORACLE_CAPABILITY")9-- the platform-specific file10local shapes_file = os.getenv("ORACLE_SHAPES")11-- base template12local template_file = os.getenv("ORACLE_TEMPLATE")13local output_file = os.getenv("ORACLE_OUTPUT")1415if not os_type or not os_version or not capability_file or16not shapes_file or not template_file or not output_file then17io.stderr:write("Error: Oracle metadata script is missing required environment variables:\n")18io.stderr:write("TYPE, OSRELEASE, ORACLE_CAPABILITY, ORACLE_SHAPES, ORACLE_TEMPLATE, ORACLE_OUTPUT\n")19os.exit(1)20end2122-- read files23local function read_file(path)24local f = io.open(path, "r")25if not f then26io.stderr:write("Error: Oracle metadata script cannot open file: " .. path .. "\n")27os.exit(1)28end29local content = f:read("*a")30f:close()31return content32end3334-- parse the template35local template = read_file(template_file)36local metadata = ucl.parser()37metadata:parse_string(template)38local data = metadata:get_object()3940-- update the simple fields41data.operatingSystem = os_type42data.operatingSystemVersion = os_version4344-- capability data is actually JSON, but needs to be inserted as a raw blob45local caps = read_file(capability_file)46-- remove all newlines and preceding spaces to match Oracle's format47caps = caps:gsub("\n", "")48caps = caps:gsub("%s+", "")49-- is it still valid JSON?50local caps_parser = ucl.parser()51if not caps_parser:parse_string(caps) then52io.stderr:write("Error: Oracle metadata script found invalid JSON in capability file\n")53os.exit(1)54end55-- insert as a raw blob56data.imageCapabilityData = caps5758-- parse and insert architecture-dependent shape compatibilities data59local shapes_data = read_file(shapes_file)60local shapes = ucl.parser()61shapes:parse_string(shapes_data)62data.additionalMetadata.shapeCompatibilities = shapes:get_object()6364-- save the metadata file65local dir = os.getenv("PWD")66local out = io.open(output_file, "w")67if not out then68io.stderr:write("Error: Oracle metadata script cannot create output file: "69.. dir .. "/" .. output_file .. "\n")70os.exit(1)71end72out:write(ucl.to_format(data, "json", {pretty = true}))73out:close()747576