From 4aad1c784bfbedc4ec06170492747d6c25627f4d Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 5 Jun 2010 12:03:48 +0200 Subject: [PATCH] [molecule] add post_iso_script hook support --- examples/specs/5-amd64-g.spec | 13 +++- examples/specs/5-amd64-k.spec | 13 +++- examples/specs/5-x86-g-iso-to-tar.spec | 13 +++- .../specs/5-x86-g-remaster-add-games.spec | 13 +++- examples/specs/5-x86-g.spec | 13 +++- examples/specs/5-x86-k.spec | 13 +++- examples/specs/Sabayon4-x86.spec | 74 ------------------- molecule/specs/plugins/builtin_plugin.py | 74 +++++++++++++------ molecule/specs/plugins/remaster_plugin.py | 4 + 9 files changed, 127 insertions(+), 103 deletions(-) delete mode 100644 examples/specs/Sabayon4-x86.spec diff --git a/examples/specs/5-amd64-g.spec b/examples/specs/5-amd64-g.spec index d8b07f0..27a9951 100644 --- a/examples/specs/5-amd64-g.spec +++ b/examples/specs/5-amd64-g.spec @@ -60,9 +60,20 @@ merge_livecd_root: /sabayon/boot/standard # Extra mkisofs parameters, perhaps something to include/use your bootloader extra_mkisofs_parameters: -b isolinux/isolinux.bin -c isolinux/boot.cat -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path destination_iso_directory: /sabayon/iso diff --git a/examples/specs/5-amd64-k.spec b/examples/specs/5-amd64-k.spec index 6169538..8e95aea 100644 --- a/examples/specs/5-amd64-k.spec +++ b/examples/specs/5-amd64-k.spec @@ -60,9 +60,20 @@ merge_livecd_root: /sabayon/boot/standard # Extra mkisofs parameters, perhaps something to include/use your bootloader extra_mkisofs_parameters: -b isolinux/isolinux.bin -c isolinux/boot.cat -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path destination_iso_directory: /sabayon/iso diff --git a/examples/specs/5-x86-g-iso-to-tar.spec b/examples/specs/5-x86-g-iso-to-tar.spec index da4d301..bbbcd0d 100644 --- a/examples/specs/5-x86-g-iso-to-tar.spec +++ b/examples/specs/5-x86-g-iso-to-tar.spec @@ -35,9 +35,20 @@ source_iso: /sabayon/iso_images/Sabayon_5.0_G.iso # before entering it (and AFTER inner_chroot_script) # outer_chroot_script_after: /path/to/script/to/be/executed/outside/after -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) # pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path (MANDATORY) destination_tar_directory: /home/fabio diff --git a/examples/specs/5-x86-g-remaster-add-games.spec b/examples/specs/5-x86-g-remaster-add-games.spec index 5623f42..709166e 100644 --- a/examples/specs/5-x86-g-remaster-add-games.spec +++ b/examples/specs/5-x86-g-remaster-add-games.spec @@ -41,9 +41,20 @@ source_iso: /sabayon/iso_images/Sabayon_5.0_G.iso # Extra mkisofs parameters, perhaps something to include/use your bootloader extra_mkisofs_parameters: -b isolinux/isolinux.bin -c isolinux/boot.cat -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) # pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path (MANDATORY) destination_iso_directory: /home/fabio diff --git a/examples/specs/5-x86-g.spec b/examples/specs/5-x86-g.spec index 70e0200..89c16a5 100644 --- a/examples/specs/5-x86-g.spec +++ b/examples/specs/5-x86-g.spec @@ -60,9 +60,20 @@ merge_livecd_root: /sabayon/boot/standard # Extra mkisofs parameters, perhaps something to include/use your bootloader extra_mkisofs_parameters: -b isolinux/isolinux.bin -c isolinux/boot.cat -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path destination_iso_directory: /sabayon/iso diff --git a/examples/specs/5-x86-k.spec b/examples/specs/5-x86-k.spec index 61bea33..176d380 100644 --- a/examples/specs/5-x86-k.spec +++ b/examples/specs/5-x86-k.spec @@ -60,9 +60,20 @@ merge_livecd_root: /sabayon/boot/standard # Extra mkisofs parameters, perhaps something to include/use your bootloader extra_mkisofs_parameters: -b isolinux/isolinux.bin -c isolinux/boot.cat -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example +# Pre-ISO building script. Hook called before making the iso image. +# environment variables exported: +# SOURCE_CHROOT_DIR: path pointing to source chroot directory +# CHROOT_DIR: path pointing to destination chroot directory (chroot being worked +# on) +# CDROOT_DIR: path pointing to CD/DVD root directory (ISO filesystem root) pre_iso_script: /sabayon/scripts/cdroot.py +# Post-ISO building script. Hook called after having made the iso image and md5. +# environment variables exported: +# ISO_PATH: path to newly created ISO image file +# ISO_CHECKSUM_PATH: path to newly created ISO image checksum file +# post_iso_script: /sabayon/scripts/post_iso_script.sh + # Destination directory for the ISO image path destination_iso_directory: /sabayon/iso diff --git a/examples/specs/Sabayon4-x86.spec b/examples/specs/Sabayon4-x86.spec deleted file mode 100644 index d30a291..0000000 --- a/examples/specs/Sabayon4-x86.spec +++ /dev/null @@ -1,74 +0,0 @@ -# Molecule example .spec file - -# Define an alternative execution strategy, in this case, the value must be -# "livecd" -# execution_strategy: livecd - -# pre chroot command, example, for 32bit chroots on 64bit system, you always have to append "linux32" -# prechroot: linux32 - -# Release string -# release_string: Sabayon Linux - -# Release Version -# release_version: 4 - -# Release Version string description -# release_desc: Lite MCE - -# Release file (inside chroot) -# release_file: /etc/sabayon-edition - -# Source chroot directory, where files are pulled from -# source_chroot: /var/tmp/catalyst/tmp/stage1-amd64-2006.0 - -# Destination chroot directory, where files are pushed to before creating the squashfs image -# NOTE: data will be stored inside an auto-generated subdir -# destination_chroot: /var/tmp/catalyst/tmp/stage1-amd64-2006.0/default/livecd-stage2-amd64-2006.0 - -# Merge directory with destination chroot -# merge_destination_chroot: /path/to/your/chroot/overlay - -# Extra mirror (r)sync parameters -# extra_rsync_parameters: - -# Error script command, executed when something went wrong and molecule has to terminate the execution -# environment variables exported: -# - CHROOT_DIR: path to chroot directory, if any -# - CDROOT_DIR: path to livecd root directory, if any -# - SOURCE_CHROOT_DIR: path from where chroot is copied for final handling -# error_script: /path/to/script/to/be/executed/outside/after - -# Outer chroot script command, to be executed outside destination chroot before packing it -# outer_chroot_script: /path/to/script/to/be/executed/outside - -# Inner chroot script command, to be executed inside destination chroot before packing it -# inner_chroot_script: /path/to/script/to/be/executed/inside - -# Destination LiveCD root directory, where files are placed before getting mkisofs'ed -# NOTE: data will be stored inside an auto-generated subdir -# destination_livecd_root: /path/to/dest/livecd - -# Merge directory with destination LiveCD root -# merge_livecd_root: /path/to/your/configured/bootloader dir - -# Extra mksquashfs parameters -# extra_mksquashfs_parameters: - -# Extra mkisofs parameters, perhaps something to include/use your bootloader -# extra_mkisofs_parameters: - -# Pre-ISO building script. Hook to be able to copy kernel images in place, for example -# pre_iso_script: - -# Destination directory for the ISO image path -# destination_iso_directory: - -# Destination ISO image name, call whatever you want.iso, not mandatory -# destination_iso_image_name: - -# Directories to remove completely (comma separated) -# paths_to_remove: /path/to/a, /path/to/b - -# Directories to empty (comma separated) -# paths_to_empty: /path/to/a, /path/to/b diff --git a/molecule/specs/plugins/builtin_plugin.py b/molecule/specs/plugins/builtin_plugin.py index bebab34..b2f6f97 100644 --- a/molecule/specs/plugins/builtin_plugin.py +++ b/molecule/specs/plugins/builtin_plugin.py @@ -465,6 +465,8 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin): class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin): + MD5_EXT = ".md5" + def __init__(self, *args, **kwargs): GenericExecutionStep.__init__(self, *args, **kwargs) @@ -501,6 +503,27 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin): _("executing pre_run"), ) ) + + # run pre iso script + exec_script = self.metadata.get('pre_iso_script') + if exec_script: + os.environ['SOURCE_CHROOT_DIR'] = self.source_chroot + os.environ['CHROOT_DIR'] = self.chroot_dir + os.environ['CDROOT_DIR'] = self.source_path + self._output.output("[%s|%s] %s: %s" % ( + blue("IsoHandler"), darkred(self.spec_name), + _("spawning"), exec_script, + ) + ) + rc = molecule.utils.exec_cmd(exec_script) + if rc != 0: + self._output.output("[%s|%s] %s: %s" % ( + blue("IsoHandler"), darkred(self.spec_name), + _("pre iso hook failed"), rc, + ) + ) + return rc + return 0 def post_run(self): @@ -509,6 +532,26 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin): _("executing post_run"), ) ) + + # run pre iso script + exec_script = self.metadata.get('post_iso_script') + if exec_script: + os.environ['ISO_PATH'] = self.dest_iso + os.environ['ISO_CHECKSUM_PATH'] = self.dest_iso + IsoHandler.MD5_EXT + self._output.output("[%s|%s] %s: %s" % ( + blue("IsoHandler"), darkred(self.spec_name), + _("spawning"), exec_script, + ) + ) + rc = molecule.utils.exec_cmd(exec_script) + if rc != 0: + self._output.output("[%s|%s] %s: %s" % ( + blue("IsoHandler"), darkred(self.spec_name), + _("post iso hook failed"), rc, + ) + ) + return rc + return 0 def kill(self, success = True): @@ -524,26 +567,6 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin): def run(self): - # run outer chroot script - exec_script = self.metadata.get('pre_iso_script') - if exec_script: - os.environ['SOURCE_CHROOT_DIR'] = self.source_chroot - os.environ['CHROOT_DIR'] = self.chroot_dir - os.environ['CDROOT_DIR'] = self.source_path - self._output.output("[%s|%s] %s: %s" % ( - blue("IsoHandler"),darkred(self.spec_name), - _("spawning"),exec_script, - ) - ) - rc = molecule.utils.exec_cmd(exec_script) - if rc != 0: - self._output.output("[%s|%s] %s: %s" % ( - blue("IsoHandler"),darkred(self.spec_name), - _("outer chroot hook failed"),rc, - ) - ) - return rc - self._output.output("[%s|%s] %s" % ( blue("IsoHandler"),darkred(self.spec_name), _("building ISO image"), @@ -579,15 +602,16 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin): ) if os.path.isfile(self.dest_iso) and os.access(self.dest_iso,os.R_OK): self._output.output("[%s|%s] %s: %s" % ( - blue("IsoHandler"),darkred(self.spec_name), - _("generating md5 for"),self.dest_iso, + blue("IsoHandler"), darkred(self.spec_name), + _("generating md5 for"), self.dest_iso, ) ) digest = molecule.utils.md5sum(self.dest_iso) - md5file = self.dest_iso+".md5" + md5file = self.dest_iso + IsoHandler.MD5_EXT with open(md5file,"w") as f: f.write("%s %s\n" % (digest,os.path.basename(self.dest_iso),)) f.flush() + return 0 class LivecdSpec(GenericSpec): @@ -684,6 +708,10 @@ class LivecdSpec(GenericSpec): 'cb': self.valid_exec_first_list_item, 've': self.ve_string_splitter, }, + 'post_iso_script': { + 'cb': self.valid_exec_first_list_item, + 've': self.ve_string_splitter, + }, 'destination_iso_directory': { 'cb': self.valid_dir, 've': self.ve_string_stripper, diff --git a/molecule/specs/plugins/remaster_plugin.py b/molecule/specs/plugins/remaster_plugin.py index a8c751d..86313e1 100644 --- a/molecule/specs/plugins/remaster_plugin.py +++ b/molecule/specs/plugins/remaster_plugin.py @@ -364,6 +364,10 @@ class RemasterSpec(GenericSpec): 'cb': self.valid_exec_first_list_item, 've': self.ve_string_splitter, }, + 'post_iso_script': { + 'cb': self.valid_exec_first_list_item, + 've': self.ve_string_splitter, + }, 'destination_iso_directory': { 'cb': self.valid_dir, 've': self.ve_string_stripper,