PROCEDURE activate_production_environment, actpe, actse (
  network_activation, na: boolean = true
  status)


*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'

" PURPOSE:
"   This procedure executes the sequence of commands required to activate the
"   system for production.  Production activation may include installation
"   of software.
"
" NOTES:
"   The creation of the path variable RAV$SYSTEM is to allow for internal testing.
"   Margins have been turned off (set to 0) until all messages can be properly aligned together.  To
"   turn the margins back on replace the 0's with a 2.
"
"   When called by INITIATE_SYSTEM, the variable RAV$PROMPTING_ALLOWED will exist.
"   This will allow prompting to occur based upon system attributes.
"
"   When called by a user, prompting will never take place and installation
"   will never take place.
"
"   The variable rav$initiate_operator_interface will only be XREFable when ACTPE is called
"   by initiate system.  This variable allows ACTPE to tell INITIATE_SYSTEM
"   if it should start up the operator interface.  The interface is not started
"   if the system is activated for console usage only.
"   !! A better solution is to change the INITIATE_SYSTEM/ACTPE code
"   !! such that actpe is the only one which can start the operator interface.
"   !! This will make the code much cleaner.
*IFEND

*copy rav$system_paths

  "$FORMAT=OFF
  TYPE
    inst_param_record: ..
*copy rat$installation_parameters

  TYPEND

  VAR
    activation_status: status
    ignore_status: status
    installation_parameters: inst_param_record
    installation_status: status
    local_status: status
    model_number: string = $unique
    osv$deadstart_phase: (XREF) string 0 .. $max_name
    proc_status: status
    rav$activate_operator_interface: (XREF) string
    rav$margin: (XDCL) integer = 0
    rav$event_message: (XDCL) status
    rav$set_operator_command_list: (XDCL) string = ''
    rav$set_operator_library_list: (XDCL) string = ''
    sys_libs: list of file = ($system.osf$command_library $system.osf$operator_command_library ..
          $system.osf$operator_library $system.osf$operator_library_46d ..
          $system.osf$system_library $system.osf$system_library_46d)
    sys_libs_error_flag: boolean = false
  VAREND
  "$FORMAT=ON"

  IF $variable(rav$prompting_allowed, nonlocal) THEN
    called_by_initiate_system = true
  ELSE
    called_by_initiate_system = false
  IFEND

  IF $variable(rav$initiate_operator_interface, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$initiate_operator_interface: (XREF) boolean
    VAREND
    "$FORMAT=ON"
  ELSE
    "$FORMAT=OFF
    VAR
      rav$initiate_operator_interface: boolean = FALSE
    VAREND
    "$FORMAT=ON"
  IFEND

  IF NOT called_by_initiate_system THEN

    "$FORMAT=OFF
    VAR
      rav$errors_occurred: (XDCL) boolean = false
    VAREND
    "$FORMAT=ON"
  ELSE
    "$FORMAT=OFF
    VAR
      rav$errors_occurred: (XREF) boolean
    VAREND
    "$FORMAT=ON"

  IFEND

  IF $field(rav$installation_tape_values, packing_list, initialized) THEN
    installation_parameters.packing_list = $string(rav$installation_tape_values.packing_list)
    installation_parameters.evsn = rav$installation_tape_values.evsn
    installation_parameters.rvsn = rav$installation_tape_values.rvsn
    IF installation_parameters.rvsn = '' THEN
      installation_parameters.rvsn = installation_parameters.evsn
    ELSEIF installation_parameters.evsn = '' THEN
      installation_parameters.evsn = installation_parameters.rvsn
    IFEND
    IF $field(rav$installation_tape_values, tape_type, initialized) THEN
      installation_parameters.tape_type = $string(rav$installation_tape_values.tape_type)
    ELSE " tape type was not specified "
      installation_parameters.tape_type = 'MT9$6250'
    IFEND
  ELSE " SET_INSTALLATION_TAPE was not called at system core time "
    installation_parameters.packing_list = ''
    installation_parameters.evsn = ''
    installation_parameters.rvsn = ''
    installation_parameters.tape_type = 'MT9$6250'
  IFEND

  IF osv$deadstart_phase = 'INSTALL' THEN
    " There are no pervious cycles to worry about.
    " The following assignment will prevent the delete previous cycles step from executing.
    installation_parameters.save_previous_cycles = true
  ELSE
    installation_parameters.save_previous_cycles = false
  IFEND

  IF called_by_initiate_system THEN

    IF $file(rav$accounting_utils_library, permanent) THEN
      $system.include_command c=$string(rav$accounting_utils_library.record_system_initiation) status=ignore_status
    IFEND

    rap$get_system_initiation_opt ip=installation_parameters

  ELSE

    rap$create_operator_environment
    rap$display_message mm=initiation_messages mn=activating_for_production t=$response status=ignore_status
    installation_parameters.installation_option = 'NONE'
    installation_parameters.activation_option = 'PRODUCTION'

  IFEND

  IF (NOT called_by_initiate_system) OR (osv$deadstart_phase <> 'INSTALL') THEN
    "Run prolog if ACTPE called directly by user OR if run by INITIATE_SYSTEM on continuation deadstart.
    rap$run_initiation_commands icn=system_initiation_prolog status=local_status
    IF NOT local_status.normal THEN
      rap$handle_status si=local_status so=proc_status
    IFEND
  IFEND

  IF called_by_initiate_system THEN

    IF installation_parameters.installation_option <> 'NONE' THEN
      rap$perform_installation_option ip=installation_parameters status=installation_status
      IF NOT installation_status.normal THEN
        rap$handle_status si=installation_status so=proc_status
      IFEND
    IFEND

  IFEND

  IF (installation_parameters.activation_option = 'PRODUCTION') AND (installation_status.normal) THEN
    IF installation_parameters.installation_option = 'INSTALLATION_TAPE' THEN
      activate_job_environment na=network_activation shpa=false status=activation_status
    ELSE
      activate_job_environment na=network_activation shpa=true status=activation_status
    IFEND
    IF NOT activation_status.normal THEN
      rap$handle_status si=activation_status so=proc_status
    IFEND
  IFEND

  IF (called_by_initiate_system) AND (osv$deadstart_phase = 'INSTALL') AND ..
        (installation_parameters.installation_option <> 'INSTALLATION_TAPE') THEN
    " Do not run epilog since the file is not yet present
  ELSE
    rap$run_initiation_commands icn=system_initiation_epilog status=local_status
    IF NOT local_status.normal THEN
      rap$handle_status si=local_status so=proc_status
    IFEND
  IFEND

  IF (called_by_initiate_system AND (installation_parameters.activation_option <> ..
    'CONSOLE')) OR (NOT called_by_initiate_system) THEN
    install_exception_policies status=ignore_status
  IFEND

  binary_model_number = $processor(binary_model_number)
  IF activation_status.normal THEN
    IF (installation_parameters.activation_option = 'PRODUCTION') THEN
      begin_production_environment " for SYSTEM_OPERATOR_UTILITY "
      rav$initiate_operator_interface=true
      rap$display_message mm=initiation_messages mn=production_activated t=$response status=ignore_status
    ELSE
      IF (binary_model_number = 3d(16)) OR (binary_model_number = 3c(16)) OR (binary_model_number = 43(16)) THEN

" This is a Soviet Nuclear Safety or China Weather system.
" Run begin_production_environment to clear capabilities.

        begin_production_environment
      IFEND
      rav$initiate_operator_interface=false
      rap$display_message mm=initiation_messages mn=console_only_activated t=$response status=ignore_status
    IFEND
  ELSE
    IF (binary_model_number = 3d(16)) OR (binary_model_number = 3c(16)) OR (binary_model_number = 43(16)) THEN

" This is a Soviet Nuclear Safety or China Weather System.
" Even if something went wrong earlier, run begin_production_environment
" to clear capabilities from the $system job.

      begin_production_environment
    IFEND
  IFEND

  FOR each library in sys_libs DO
    IF $field($file_attributes(library exception_conditions)(1) exception_conditions specified) THEN
      sys_libs_error_flag = TRUE
      $system.put_line ' Exception condition on file '//library
    ELSE
      IF NOT ($file_attributes(library registered)(1).registered) THEN
        sys_libs_error_flag = TRUE
        $system.put_line ' Missing file '//library
      IFEND
    IFEND
  FOREND
  IF sys_libs_error_flag THEN
    rav$errors_occurred = TRUE
    $system.put_line ' ' o=$local.$output
    $system.put_line ' WARNING:  One or more of the NOS/VE system libraries is not available.' o=$local.$output
    $system.put_line ' Contact your site analyst.' o=$local.$output
    $system.put_line ' ' o=$local.$output
    IF (installation_parameters.activation_option = 'PRODUCTION') THEN
      EXIT procedure WITH $status(false, 'RA', rae$activation_errors_warning, 'production')
    ELSE
      EXIT procedure WITH $status(false, 'RA', rae$activation_errors_warning, 'system console usage only')
    IFEND
  IFEND

  IF called_by_initiate_system THEN

    IF NOT proc_status.normal THEN
      IF (installation_parameters.activation_option = 'PRODUCTION') THEN
        EXIT procedure WITH $status(false, 'RA', rae$activation_errors_warning, 'production')
      ELSE
        EXIT procedure WITH $status(false, 'RA', rae$activation_errors_warning, 'system console usage only')
      IFEND
    IFEND

  ELSE

    IF (rav$activate_operator_interface = '') OR (NOT rav$initiate_operator_interface) THEN
      EXIT procedure WITH $status(false, 'RA', rae$errors_occurred_warning, ..
            'ACTIVATE_PRODUCTION_ENVIRONMENT') WHEN rav$errors_occurred
    ELSE
      IF rav$errors_occurred THEN
        " Have user acknowledge errors, prior to activating the operator interface.
        $system.put_line ' '//..
$strrep($status(false, 'RA', rae$errors_occurred_warning, 'ACTIVATE_PRODUCTION_ENVIRONMENT'))
        rap$press_next
      IFEND
      $system.include_command c=rav$activate_operator_interface status=activation_status
      IF NOT activation_status.normal THEN
        $system.put_line (' '//..
$strrep($status(false, 'RA', rae$errors_occurred_warning, 'RAV$ACTIVATE_OPERATOR_INTERFACE')) ' '//..
$strrep(activation_status)) o=$response
      IFEND
    IFEND

  IFEND

PROCEND activate_production_environment
