diff --git a/example-app/jet.yaml b/example-app/jet.yaml index 35d06d8..96158f7 100644 --- a/example-app/jet.yaml +++ b/example-app/jet.yaml @@ -1,6 +1,8 @@ --- basename: "example" comment: "JetEZ GO Example" +arch: "x86" +abi: "64" files: - source: hello destination: /var/db/scripts/jet/hello diff --git a/example-app/scripts/activate.sh b/example-app/scripts/activate.sh new file mode 100644 index 0000000..e69de29 diff --git a/jet/main.py b/jet/main.py index 83d15f5..9ac0296 100644 --- a/jet/main.py +++ b/jet/main.py @@ -72,7 +72,9 @@ def main(): shutil.rmtree(args.build) os.makedirs(args.build) os.makedirs('%s/contents' % args.build) + os.makedirs('%s/scripts' % args.build) contents = "%s/contents/contents" % args.build + scripts = "%s/scripts/activate" % args.build os.makedirs(contents) contents_pkg = '%s/pkg' % contents os.makedirs(contents_pkg) @@ -117,6 +119,17 @@ def main(): with open(contents_symlink_file, "w") as f: f.write(contents_symlink) + given_scripts_file = os.path.join(args.source, "scripts/activate.sh") + init_content = "" + with open(given_scripts_file, 'r') as file: + init_content = file.read() + + scripts_file = '%s.sh' % scripts + log.info("create symlink file %s", scripts_file) + with open(scripts_file, "w") as f: + f.write(init_content) + os.chmod(scripts_file, 0o755) + log.info("sign manifest file %s" % content_manifest_file) crypto.sign(content_manifest_file, "%s.sig" % content_manifest_file, args.key, args.cert) @@ -128,13 +141,16 @@ def main(): shutil.rmtree(contents) log.info("create package.xml") - utils.create_package_xml(project, args.version, package, args.build) + utils.create_package_xml(project, version, package, args.build) package_manifest = "/set package_id=31 role=Provider_Daemon\n" - package_manifest_files = ["contents/contents.iso", "contents/contents.symlinks", "package.xml"] + package_manifest_files = ["contents/contents.iso", "contents/contents.symlinks", "scripts/activate.sh", "package.xml"] for f in package_manifest_files: - package_manifest += "%s sha1=%s\n" % (f, crypto.generate_sha1(os.path.join(args.build, f))) + if "scripts" not in f: + package_manifest += "%s sha1=%s\n" % (f, crypto.generate_sha1(os.path.join(args.build, f))) + else: + package_manifest += "%s sha1=%s program_id=1\n" % (f, crypto.generate_sha1(os.path.join(args.build, f))) package_manifest_file = os.path.join(args.build, "manifest") log.info("create manifest file %s", package_manifest_file) diff --git a/jet/utils.py b/jet/utils.py index 997c305..65853bd 100644 --- a/jet/utils.py +++ b/jet/utils.py @@ -101,7 +101,7 @@ def load_project(project_file, version): :rtype: dict """ with open(project_file , 'r') as f: - project_yaml = yaml.load(f) + project_yaml = yaml.load(f, Loader=yaml.FullLoader) def required(d, k): if k in d: @@ -114,9 +114,11 @@ def required(d, k): "basename": required(project_yaml, "basename"), "files": [], "comment": project_yaml.get("comment", "JET app %s" % project_yaml["basename"]), - "arch": project_yaml.get("arch", "x86"), - "abi": project_yaml.get("abi", "32"), + "arch": required(project_yaml, "arch"), + "abi": required(project_yaml, "abi"), "copyright": project_yaml.get("copyright", "Copyright %s, Juniper Networks, Inc." % timestamp.year), + "mounted-action": project_yaml.get("mounted-action", "scripts/activate.sh"), + "deleting-action": project_yaml.get("deleting-action", "scripts/activate.sh"), "package_id": project_yaml.get("package_id", 31), "role": project_yaml.get("role", "Provider_Daemon"), "date": timestamp.strftime("%Y%m%d"), @@ -186,8 +188,10 @@ def package_xml_file(filename): etree.SubElement(package_xml, "basename").text = project["basename"] etree.SubElement(package_xml, "comment").text = "%s [%s]" % (project["comment"], version) etree.SubElement(package_xml, "copyright").text = project["copyright"] + etree.SubElement(package_xml, "deleting-action").text = project["deleting-action"] etree.SubElement(package_xml, "description").text = project["basename"] etree.SubElement(package_xml, "mntname").text = "%s%s-%s" % (project["basename"], project["abi"], binascii.b2a_hex(os.urandom(4)).decode()) + etree.SubElement(package_xml, "mounted-action").text = project["mounted-action"] etree.SubElement(package_xml, "require").text = "junos-runtime32" etree.SubElement(package_xml, "version").text = project["date"] etree.SubElement(package_xml, "spin").text = project["time"] @@ -201,5 +205,7 @@ def package_xml_file(filename): dir = etree.SubElement(package_xml, "dir", name="contents") package_xml_file("contents/contents.iso") package_xml_file("contents/contents.symlinks") + dir = etree.SubElement(package_xml, "dir", name="scripts") + package_xml_file("scripts/activate.sh") with open("%s/package.xml" % path, "w+") as f: f.write(etree.tostring(package_xml, pretty_print=True).decode("utf8"))