(set vernum (getversion "libs:version.library"))
(set ver (/ vernum 65536))
(set rev (- vernum (* ver 65536)))
(complete 0)

(set @default-dest "")
(if (strlen (getassign "TERMINUS" "a"))
   (
      (set rem_flag
         (askbool
            (prompt
               "The logical assignment \"TERMINUS\" is present, it must be unassigned "
               "before the installation can continue."
            )
            (help 
               "Select \"Remove\" to remove"
               "this assignment or \"Abort\" to abort this script."
            )
            (default 1)
            (choices "Remove" "Abort")
         )
      )
      (if (= rem_flag 0)
         (abort "User aborted installation.")
         (run "Assign TERMINUS:")
      )
   )
)

(message
   "This floppy installation script is used to create or update an AmigaDOS 1.3, 2.0 "
   "or 2.1 boot floppy and a Terminus program disk.\n\n"
   "To do so you will need to boot from a copy of your Workbench disk (or your "
   "boot floppy) before installation can continue.\n\n"
   "The Terminus program disk will be created/updated first.  If updating, please "
   "insert the Terminus program disk, which must be labled \"TERMINUS\" before proceeding."
)

(set is_update 0)
(set term-dest (getassign "TERMINUS" "v"))

(if (strlen term-dest)
   (
      (set is_update 
         (askbool
            (prompt 
               "The volume \"TERMINUS:\" is present in \""
               (getdevice term-dest)
               ":\".\n\n  Do you want the update installed there?"
            )
            (help @askchoice-help)
            (choices "Proceed" "Abort")
            (default 1)
         )
      )
      (if (= is_update 0)
         (abort "User aborted installation.")
      )
   )
)

(if (= is_update 0)
   (
      (until (getassign "TERMINUS" "v")
         (
            (message "Please insert a formatted, blank disk in drive DF0:")
            (run "relabel drive DF0: TERMINUS")
            (delete (tackon term-dest ".info") (optional "force"))
            (message 
               "The disk in DF0: has been relabeled as \"TERMINUS\".  Please "
               "wait a few seconds for the drive activity LED to go out then "
               "remove and finally reinsert the disk to update the system so "
               "that the \"TERMINUS\" volume name is present.  Proceed once "
               "the disk LED has extinguished."
            )
         )
      )
      (set term-dest (getassign "TERMINUS" "v"))
   )
)

(set @execute-dir (pathonly @icon))
(makeassign "TERMINST" @execute-dir)
(set script-dest (tackon term-dest "Scripts"))

(if (not (exists script-dest))
   (makedir script-dest)
)

(makeassign "TERMTEMP" script-dest)
(working "Extracting Terminus scripts...")
(set exec-lha (tackon "TERMINST:" "bin/lha -mxE e "))
(set exec-part (tackon "TERMINST:" "ScriptFiles TERMTEMP:"))
(run (cat exec-lha exec-part))
(run "TERMINST:bin/touch TERMTEMP:Scripts/*")

(complete 10)

(makeassign "TERMTEMP" term-dest)
(working "Extracting Terminus executable files...")
(set exec-part (tackon "TERMINST:" "ExecFiles TERMTEMP:"))
(run (cat exec-lha exec-part))

(complete 20)

(working "Extracting Terminus documentation files...")
(set exec-part (tackon "TERMINST:" "DocFiles TERMTEMP:"))
(run (cat exec-lha exec-part))
(makeassign "TERMTEMP")
(makeassign "TERMINST")

(if (exists "keyfile")
   (copyfiles
      (source "keyfile")
      (dest "TERMINUS:")
   )
)

(complete 30)

(set make_boot 
   (askchoice
      (prompt 
         "Please insert the boot disk to be created or updated in drive DF0: now.  Next, "
         "select the appropriate choice from the list below.\n\n"
         "If you are updating a boot disk you will need approximately 140k of free space "
         "for the necessary fonts and libraries that will be copied to it."
      )
      (choices "Update" "AmigaDOS 1.3" "AmigaDOS 2.0" "AmigaDOS 2.1")
      (default 0)
      (help @askchoice-help)
   )
)
         
(set boot-dest "DF0:")
(if (not (= make_boot 0))
   (
      (message
         "The disk installed in DF0: is about to be modified.  All unneccesary files are going to "
         "be deleted.  Are you certain that you want to continue with this installation?\n\n"
         "CAUTION -- DO NOT USE YOUR ORIGINAL WORKBENCH DISK!"
      )
      (set n 0)
      (if (= make_boot 1)
         (
            (while (set thisfile (select n "c/Ask" 
                                             "c/DiskChange"
                                             "c/DiskDoctor"
                                             "c/Edit"
                                             "c/Lock"
                                             "c/Protect"
                                             "c/Quit"
                                             "c/RemRAD"
                                             "c/Sort"
                                             "c/Which"
                                             "c/Why"
                                             "System/FixFonts"
                                             "System/FixFonts.info"
                                             "System/InitPrinter"
                                             "System/InitPrinter.info"
                                             "System/MergeMem"
                                             "System/MergeMem.info"
                                             "System/NoFastMem"
                                             "System/NoFastMem.info"
                                             "Prefs/CopyPrefs"
                                             "Prefs/CopyPrefs.info"
                                             "Prefs/Pointer.info"
                                             "Prefs/Serial.info"
                                             "l/Aux-Handler"
                                             "l/FastFileSystem"
                                             "l/Pipe-Handler"
                                             "l/Speak-Handler"
                                             "devs/narrator.device"
                                             "s/Startup-Sequence"
                                             "s/Startup-Sequence.HD"
                                             "s/StartupII"
                                             "fonts/ruby/12"
                                             "fonts/ruby/15"
                                             "fonts/ruby/8"
                                             "fonts/opal/12"
                                             "fonts/opal/9"
                                             "fonts/sapphire/14" 
                                             "fonts/sapphire/19"
                                             "fonts/diamond/12"
                                             "fonts/diamond/20"
                                             "fonts/garnet/16"
                                             "fonts/garnet/9"
                                             "fonts/emerald/17"
                                             "fonts/emerald/20"
                                             "fonts/diamond.font"
                                             "fonts/emerald.font"
                                             "fonts/garnet.font"
                                             "fonts/opal.font"
                                             "fonts/ruby.font"
                                             "fonts/sapphire.font"
                                             "fonts/diamond"
                                             "fonts/emerald"
                                             "fonts/garnet"
                                             "fonts/opal"
                                             "fonts/ruby"
                                             "fonts/sapphire"
                                             "libs/mathieeedoubbas.library"
                                             "libs/mathieeedoubtrans.library"
                                             "libs/mathtrans.library"
                                             "libs/translator.library"
                                             "Empty"
                                             "Utilities/.info"
                                             "Utilities/Calculator"
                                             "Utilities/Calculator.info"
                                             "Utilities/Clock"
                                             "Utilities/Clock.info"
                                             "Utilities/ClockPtr"
                                             "Utilities/ClockPtr.info" 
                                             "Utilities/CMD"
                                             "Utilities/Cmd.info"
                                             "Utilities/InstallPrinter"
                                             "Utilities/InstallPrinter.info"
                                             "Utilities/Notepad"
                                             "Utilities/Notepad.info"
                                             "Utilities/Say"
                                             "Utilities/Say.info"
                                             "Expansion"
                                             "Empty.info"
                                             "Expansion.info"
                                             ""))
               (
                  (set n (+ n 1))
                  (working "Deleting file: " thisfile)
                  (delete (tackon boot-dest thisfile) (optional "force"))
               )
            )

            (working "Building Startup-sequence script file...")
            (textfile
               (dest (tackon boot-dest "s/startup-sequence"))
               (append
                  "echo \"Terminus 2.0 boot disk for Workbench 1.3\"\n"
                  "version\n"
                  "c:SetPatch >NIL: r\n"
                  "Addbuffers df0: 10\n"
                  "Binddrivers\n"
                  "FF >NIL: -0\n"
                  "Sys:System/FastMemFirst\n"
                  "resident CLI L:Shell-Seg SYSTEM pure add\n"
                  "mount newcon:\n"
                  "makedir ram:t\n"
                  "assign T: ram:t\n"
                  "makedir ram:env\n"
                  "assign ENV: ram:env\n"
                  "makedir ram:clipboards\n"
                  "assign CLIPS: ram:clipboards\n"
                  "SYS:System/SetMap usa1\n"
                  "path ram: c: s: sys:system sys:utilities add\n"
                  "LoadWB\n"
                  "EndCLI >NIL:\n"
               )
            )
         )
         (
            (while (set thisfile (select n "Prefs/Pointer"
                                             "Prefs/Pointer.info"
                                             "Prefs/Serial"
                                             "Prefs/Serial.info"
                                             "Prefs/Font"
                                             "Prefs/Font.info"
                                             "Prefs/IControl"
                                             "Prefs/IControl.info"
                                             "Prefs/Input"
                                             "Prefs/Input.info"
                                             "Prefs/Overscan"
                                             "Prefs/Overscan.info"
                                             "Prefs/Palette"
                                             "Prefs/Palette.info"
                                             "Prefs/Printer"
                                             "Prefs/Printer.info"
                                             "Prefs/PrinterGfx"
                                             "Prefs/PrinterGfx.info"
                                             "Prefs/ScreenMode"
                                             "Prefs/ScreenMode.info"
                                             "Prefs/Time"
                                             "Prefs/Time.info"
                                             "Prefs/WBPattern"
                                             "Prefs/WBPattern.info"
                                             "Libs/bullet.library"
                                             "Libs/mathieeedoubtrans.library"
                                             "Libs/mathieeesingtrans.library"
                                             "Libs/mathtrans.library"
                                             "Expansion"
                                             "System/Fountain"
                                             "System/Fountain.info"
                                             "System/FixFonts"
                                             "System/FixFonts.info"
                                             "System/NoFastMem"
                                             "System/NoFastMem.info"
                                             "Utilities/Clock"
                                             "Utilities/Clock.info"
                                             "Utilities/Display"
                                             "Utilities/Display.info"
                                             "Utilities/Exchange"
                                             "Utilities/Exchange.info"
                                             "Utilities/Say"
                                             "Utilities/Say.info"
                                             "L/aux-handler"
                                             "L/speak-handler"
                                             "S/HDBackup.config"
                                             "S/PickMap"
                                             "S/Startup-sequence"
                                             "S/Startup-sequence.HD"
                                             "C/DiskChange"
                                             "C/DiskDoctor"
                                             "C/Edit"
                                             "C/Lock"
                                             "C/MagTape"
                                             "C/Protect"
                                             "C/RemRAD"
                                             "C/Sort"
                                             "C/Which"
                                             "Devs/postscript_init.ps"
                                             "Devs/narrator.device"
                                             "Devs/DOSDrivers/PIPE"
                                             "Devs/DOSDriversPIPE.info"
                                             "Devs/DOSDrivers"
                                             "Expansion.info"
                                             ""))
               (
                  (set n (+ n 1))
                  (working "Deleting file: " thisfile)
                  (delete (tackon boot-dest thisfile) (optional "force"))
               )
            )

            (working "Building Startup-sequence script file...")
            (textfile
               (dest (tackon boot-dest "s/startup-sequence"))
               (if (= make_boot 2)
                  (
                     (append
                        "c:setpatch >NIL:\n"
                        "c:version >NIL:\n"
                        "addbuffers >NIL: df0: 15\n"
                        "Resident >NIL: C:Execute PURE ADD\n"
                        "makedir ram:T ram:Clipboards ram:env ram:env/sys\n"
                        "copy >NIL: ENVARC: ram:env all quiet noreq\n"
                        "assign ENV: ram:env\n"
                        "assign T: ram:t ;set up T: directory for scripts\n"
                        "assign CLIPS: ram:clipboards\n"
                        "assign REXX: s:\n"
                        "if exists sys:Monitors\n"
                        "    join >NIL: sys:monitors/~(#?.info) as t:mon-start\n"
                        "    execute t:mon-start\n"
                        "    delete >NIL: t:mon-start\n"
                        "endif\n"
                        "BindDrivers\n"
                        "setenv Workbench $Workbench\n"
                        "setenv Kickstart $Kickstart\n"
                        "Echo \"Terminus 2.0 boot disk Kickstart $Kickstart, Workbench $Workbench\"\n"
                        "version\n"
                        "IPrefs\n"
                        "conclip\n"
                        "path ram: c: sys:utilities sys:rexxc sys:system s: sys:prefs sys:wbstartup add\n"
                        "LoadWB\n"
                        "EndCLI >NIL:\n"
                     )
                  )
                  (
                     (append
                        "C:SetPatch QUIET\n"
                        "Version >NIL:\n"
                        "AddBuffers >NIL: DF0: 15\n"
                        "FailAt 21\n"
                        "MakeDir RAM:T RAM:Clipboards RAM:ENV RAM:ENV/Sys\n"
                        "Copy >NIL: ENVARC: RAM:ENV ALL NOREQ\n"
                        "Assign >NIL: ENV: RAM:ENV\n"
                        "Assign >NIL: T: RAM:T\n"
                        "Assign >NIL: CLIPS: RAM:Clipboards\n"
                        "Assign >NIL: REXX: S:\n"
                        "Assign >NIL: PRINTERS: DEVS:Printers\n"
                        "Assign >NIL: KEYMAPS: DEVS:Keymaps\n"
                        "Assign >NIL: LOCALE: SYS:Locale\n"
                        "IF NOT EXISTS SYS:Fonts\n"
                        "  Assign FONTS:\n"
                        "EndIF\n"
                        "BindDrivers\n"
                        "IF EXISTS DEVS:Monitors\n"
                        "  List >NIL: DEVS:Monitors/~(#?.info) TO T:M LFORMAT \"DEVS:Monitors/%s\"\n"
                        "  Execute T:M\n"
                        "  Delete >NIL: T:M\n"
                        "EndIF\n"
                        "SetEnv Workbench $Workbench\n"
                        "SetEnv Kickstart $Kickstart\n"
                        "UnSet Workbench\n"
                        "UnSet Kickstart\n"
                        "IPrefs\n"
                        "Echo \"Terminus 2.0 boot disk Kickstart $Kickstart, Workbench $Workbench\"\n"
                        "version\n"
                        "ConClip\n"
                        "Path >NIL: RAM: C: SYS:Utilities SYS:Rexxc SYS:System S: SYS:Prefs SYS:WBStartup add\n"
                        "LoadWB\n"
                        "EndCLI >NIL:\n"
                     )
                  )
               )
            )
            (if (not (exists (tackon boot-dest "fonts")))
               (
                  (makedir (tackon boot-dest "fonts"))
                  (run "Assign FONTS: DF0:fonts")
               )
            )
         )
      )
   )
)

(complete 50)

(copyfiles
   (source "Fonts")
   (dest (tackon boot-dest "fonts"))
   (all)
)

(complete 60)

(set ver 0)
(if (exists (tackon boot-dest "libs/asl.library"))
   (
      (set vernum (getversion (tackon boot-dest "libs/asl.library")))
      (set ver (/ vernum 65536))
   )
)

(if (and (not (exists (tackon boot-dest "libs/req.library"))) (< ver 38))
   (copyfiles
      (source "Libs/req.library")
      (dest (tackon boot-dest "libs"))
   )
)

(complete 70)

(if (not (exists (tackon boot-dest "libs/OwnDevUnit.library")))
   (copyfiles
      (source "Libs/OwnDevUnit.library")
      (dest (tackon boot-dest "libs"))
   )
)

(complete 80)

(if (not (exists (tackon boot-dest "libs/xprkermit.library")))
   (copyfiles
      (source "Libs/xprkermit.library")
      (dest (tackon boot-dest "libs"))
   )
)

(complete 90)

(if (not (exists (tackon boot-dest "libs/xprbplus.library")))
   (copyfiles
      (source "Libs/xprbplus.library")
      (dest (tackon boot-dest "libs"))
   )
)

(complete 100)

(exit)

