PROCEDURE establish_disk_based_system, estdbs (
  deadstart_catalog, dc: file = $optional
  external_vsn, evsn, ev: any of
      string 1..6
      name 1..6
    anyend = $optional
  recorded_vsn, rvsn, rv: any of
      string 1..6
      name 1..6
    anyend = $optional
  type, t: any of
      key
        mt9$1600
        mt9$6250
        mt18$38000
      keyend
    anyend = mt9$6250
  status)

  VAR
    local_status: status
  VAREND

  "  If the deadstart_catalog is already on disk (deadstart_catalog parameter), then neither
  "  the external_vsn nor the recorded_vsn may be specified.  Otherwise, if the deadstart catalog
  "  is not already on disk, then either the external_vsn or the recorded_vsn must be specified.

  IF $specified(deadstart_catalog) THEN
    IF $specified(external_vsn) OR $specified(recorded_vsn) THEN
      local_status = $status(FALSE, 'DS', dse$cannot_use_both_catalog_vsn)
      EXIT PROCEDURE WITH local_status
    IFEND
  ELSE
    IF NOT $specified(external_vsn) AND NOT $specified(recorded_vsn) THEN
      local_status = $status(FALSE, 'DS', dse$must_specify_catalog_or_vsn)
      EXIT PROCEDURE WITH local_status
    IFEND
  IFEND

  "  Create the global variables.

  VAR
    dsv$estdbs_catalog_specified: (JOB) boolean = TRUE
    dsv$estdbs_created_catalog: (JOB) string 0 .. $max_name = $unique
    dsv$estdbs_existing_catalog: (JOB) file
    dsv$estdbs_ex_vsn: (JOB) string 1 .. 6
    dsv$estdbs_re_vsn: (JOB) string 1 ..6
    dsv$estdbs_tape_type: (JOB) key mt9$1600 mt9$6250 mt18$38000 keyend = type
  VAREND

  IF $specified(deadstart_catalog) THEN
    dsv$estdbs_existing_catalog = deadstart_catalog
  ELSE
    dsv$estdbs_catalog_specified = FALSE
  IFEND

  IF $specified(external_vsn) THEN
    dsv$estdbs_ex_vsn = $string(external_vsn)
  ELSE
    dsv$estdbs_ex_vsn = 'NULL'
  IFEND

  IF $specified(recorded_vsn) THEN
    dsv$estdbs_re_vsn = $string(recorded_vsn)
  ELSE
    dsv$estdbs_re_vsn = 'NULL'
  IFEND

  put_line l=' Establishing disk based system ... ' o=$response
  put_line l=' Please wait for completion message. ' o=$response

  "  Execute a task to install the deadstart file.

  TASK tn=install_ds_catalog_to_disk

    VAR
      command_status: status
      ignore_status: status
      local_status: status
    VAREND

    maintain_deadstart_software

      include_command c='establish_deadstart_catalog status=local_status' status=command_status
      IF NOT command_status.normal THEN
        local_status = command_status
      IFEND

    quit

    IF NOT local_status.normal THEN
      display_value v='The command Establish_disk_based_system returned the following bad status:'
      display_value v=local_status
    IFEND

    IF NOT dsv$estdbs_catalog_specified THEN
      delete_catalog c=$fname('$system.'//dsv$estdbs_created_catalog), do=catalog_and_contents, status=ignore_status
    IFEND

    delete_variable n=dsv$estdbs_catalog_specified
    delete_variable n=dsv$estdbs_created_catalog
    delete_variable n=dsv$estdbs_existing_catalog
    delete_variable n=dsv$estdbs_ex_vsn
    delete_variable n=dsv$estdbs_re_vsn
    delete_variable n=dsv$estdbs_tape_type

  TASKEND

 PROCEND establish_disk_based_system
