bundle common cfe_internal_update_from_repository_file_control
# @brief Define inputs needed for updating *masterfiles*, the default policy distribution point with content from an upstream VCS
{
  vars:
      "inputs" slist => { "$(this.promise_dirname)/lib.cf" };
}

body file control
# @brief Include policy needed for updating *masterfiles*, the default policy distribution point with content from an upstream VCS
{
      inputs => { @(cfe_internal_update_from_repository_file_control.inputs) };
}

bundle agent cfe_internal_update_from_repository
# @brief Ensure *masterfiles*, the default policy is up to date
{
  methods:
    am_policy_hub.cfengine_internal_masterfiles_update::
      "Update staged masterfiles from VCS"
        usebundle => cfe_internal_masterfiles_stage,
        handle => "cfe_internal_update_from_repository_methods_masterfiles_fetch",
        action => u_immediate,
        comment => "Grab the latest updates from upstream VCS repo before deploying masterfiles";

}

bundle agent cfe_internal_masterfiles_stage
# @brief Run masterfiles-stage.sh to update the default distribution of masterfiles
{

  commands:
      "$(update_def.dc_scripts)/masterfiles-stage.sh"
        classes => u_kept_successful_command_results("bundle", "masterfiles_deploy"),
        handle => "masterfiles_update_stage",
        action => u_immediate;

  reports:
    masterfiles_deploy_not_kept::
      "Masterfiles deployment failed, for more info see '$(sys.workdir)/outputs/dc-scripts.log'";

    (DEBUG|DEBUG_cfe_internal_masterfiles_stage).(masterfiles_deploy_kept|masterfiles_deploy_repaired)::
      "DEBUG $(this.bundle): Masterfiles deployed successfully";
}
