PROCEDURE (HIDDEN) rap$load_installation_tools (
  installation_parameters, ip: (VAR) ..
*copy rat$installation_parameters
                                  = $required
  tape_file, tp: (VAR) file
  status)


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

" PURPOSE:
"   This procedure loads the installation tools from the installation
"   tape.
"
" NOTES:
"   Three tries allowed when there are restore errors.
"
*IFEND


  "$FORMAT=OFF
  VAR
    ignore_status: status
    local_status: status
    menu_selection: string 0 .. $max_name
    number_of_trys: integer = 1
    installation_tools_loaded: boolean = false
    restore_status: status
    tape_name: string = '$local.raf$primary_tape_'
    tools_library: name = raf$library
    unique_catalog: file = $user//$name($unique)
  VAREND
  "$FORMAT=ON"

load_installation_tools: ..
  WHILE NOT installation_tools_loaded DO

    local_status.normal = true
    restore_status.normal = true
    IF number_of_trys > 3 THEN
      local_status = $status(false, 'RA', rae$invalid_installation_tape)
      EXIT load_installation_tools
    IFEND
    tape_file = $fname(tape_name//$trim(installation_parameters.rvsn)//'.1')
    detach_file f=tape_file status=ignore_status

    rap$display_message mm=initiation_messages ..
          mn=requesting_installation_tape mp=(..
          installation_parameters.evsn, installation_parameters.rvsn, ..
          installation_parameters.tape_type) t=$response status=ignore_status
    request_magnetic_tape f=tape_file ..
          evsn=installation_parameters.evsn rvsn=installation_parameters.rvsn ..
          type=$name(installation_parameters.tape_type) r=false status=local_status
    EXIT load_installation_tools WHEN NOT local_status.normal

    change_tape_label_attributes f=tape_file fsp=fsp ..
          fsn=2 "RAF$LIBRARY should be the second file on the tape."

"$RESTORE_PERMANENT_FILES
      $system.osf$builtin_library.restore_permanent_files l=$job_log ..
            status=restore_status
      EXIT load_installation_tools WHEN NOT restore_status.normal
      restore_catalog c=$fname($backup_file(tape_file)) bf=tape_file ..
            ncn=unique_catalog status=local_status
"$QUIT
    include_command c='QUIT' status=ignore_status

    IF (local_status.normal) AND (NOT restore_status.normal) THEN
      local_status = restore_status
    IFEND

    IF (local_status.normal) AND $file(unique_catalog//tools_library, permanent) THEN

      delete_file f=$local//tools_library status=ignore_status
      copy_file i=unique_catalog//tools_library ..
            o=$local//tools_library status=local_status
      EXIT load_installation_tools WHEN NOT local_status.normal
      delete_catalog c=unique_catalog do=cac status=ignore_status
      installation_tools_loaded = true

    ELSE

      detach_file f=tape_file status=ignore_status
      delete_catalog c=unique_catalog do=cac status=ignore_status
      number_of_trys = number_of_trys + 1
      IF local_status.normal THEN
        "Restore successfull but content was not the installation tools
        rap$display_message mm=initiation_messages ..
              mn=incorrect_installation_tape t=$response ..
              status=ignore_status
      ELSEIF $condition(local_status.condition) = ..
            'IFE$TERMINATE_BREAK_RECEIVED' THEN
            rap$display_message mm=initiation_messages ..
                 mn=user_aborts_tape_request t=$response ..
                 status=ignore_status
      ELSE
         $system.put_line l=' '//$strrep(local_status) o=$response
         rap$display_message mm=initiation_messages ..
             mn=unable_to_restore_from_tape t=$response ..
             status=ignore_status
      IFEND
      rap$press_next
      rap$get_install_tape_values ip=installation_parameters ..
            ms=menu_selection
      IF menu_selection = '+QUIT' THEN
        local_status = $status(false, 'RA', ..
              rae$install_aborted_by_user)
        restore_status.normal = true
        EXIT load_installation_tools
      IFEND

    IFEND

  WHILEND load_installation_tools

  EXIT procedure WITH local_status WHEN NOT local_status.normal
  EXIT procedure WITH restore_status WHEN NOT restore_status.normal

PROCEND rap$load_installation_tools

