;
;CD-Write installation script - $VER: Install_CD-Write 1.3 (24.7.95)
;Copyright © 1995 by Ralph Babel
;all rights reserved
;

(set lang
 (askchoice
  (prompt "Language/Sprache")
  (help "Please select your preferred language.\n\nBitte wählen Sie Ihre bevorzugte Sprache.\n\n" @askchoice-help)
  (choices "English" "Deutsch")
  (default (= (if (exists "ENV:Language")(getenv "Language")("")) "deutsch"))
 )
)

(if (= lang 0)
 (
  (set txt-yes "Yes")
  (set txt-no "No")
  (set txt-prompt-ro "Please enter the DOS device name of your CD-ROM drive:")
  (set txt-help-ro "The DOS device name to be entered determines with which existing device CD-Write is expected to work. This is usually the name of your CD-ROM drive, often called »CD0:«. The DOS device name must be terminated by a colon.\n\n")
  (set txt-confirm-ro "So you want CD-Write to operate with the device ...\n\n»%s«\n\n...?")
  (set txt-no-ro "No valid device name is associated with the name ...\n\n»%s«\n\n... you entered.\n\nPlease check if your CD-ROM drive is mounted, or correct your input.")
  (set txt-bad-ro "The DOS device name must not contain spaces, quotation marks, or vertical bars \"|\".\n\nPlease correct your input.")
  (set txt-prompt-rw "Please enter the name of CD-Write's modifications directory:")
  (set txt-help-rw "The directory name to be entered determines in which directory CD-Write is expected to store the modification data. This directory must be located on a medium that can always be written to.\n\n")
  (set txt-no-rw "The parent directory you specified ...\n\n»%s«\n\n... does not exist.\n\nPlease create it first, or correct your input.")
  (set txt-bad-rw "The name of the modifications directory must not contain spaces, quotation marks, or vertical bars \"|\".\n\nPlease correct your input.")
  (set txt-confirm-rw "So you want CD-Write to store its modification data in the directory ...\n\n»%s«\n\n...?")
  (set txt-error-rw "The directory you specified ...\n\n»%s«\n\n... could not be created.\n\nPlease verify your input.")
  (set txt-prompt-cdw "Enter the DOS device name under which CD-Write should be mounted:")
  (set txt-help-cdw "CD-Write's DOS device name must be specified without a trailing colon and must not yet be assigned.\n\n")
  (set txt-bad-cdw "The DOS device name must not contain spaces, quotation marks, or colons.\n\nPlease correct your input.")
  (set txt-dup-cdw "The DOS device name ...\n\n»%s«\n\n... has already been assigned.\n\nPlease correct your input.")
  (set txt-prompt-l "Into which directory should the filesystem code be copied?")
  (set txt-bad-l "The name of the filesystem directory must not contain spaces or quotation marks.\n\nPlease correct your input.")
  (set txt-prompt-c "Into which directory should the utilities be copied?")
  (set txt-prompt-util "Copying the utilities")
  (set txt-help-util "Using the utilities, you can control certain options and restore deleted files. They are not necessarily required. Please refer to your manual for details.\n\n")
  (set txt-prompt-ml "Into which MountList file should the MountList entry be inserted?")
  (set txt-help-ml "The MountList entry is required so that CD-Write can be mounted automatically.\n\n")
  (set txt-bad-ml "The name of the MountList file must not contain quotation marks.\n\nPlease correct your input.")
  (set txt-prompt-startup "The following command ...\n\n%s\n\n... must be added to your User-Startup file.")
  (set txt-help-startup "This command serves to mount CD-Write every time upon system start-up.\n\n")
  (set txt-prompt-dd "Into which directory should the new DOSDrivers entry be copied?")
  (set txt-help-dd "Devices with an associated DOSDrivers entry are mounted automatically upon system start-up. The directory in which these entries are located must already exist; it is not created automatically.\n\n")
  (set txt-prompt-mount "Should »%s« be mounted now using the command ...\n\n»%s«\n\n...?")
  (set txt-help-mount "If »%s« is not mounted at this point, CD-Write won't become active until after the next reboot.")
  (set txt-exit "Have fun!")
  (set txt-abort "Installation not possible.\n\nCD-Write requires at least Kickstart 2.04.")
 )
)

(if (= lang 1)
 (
  (set txt-yes "Ja")
  (set txt-no "Nein")
  (set txt-prompt-ro "Bitte geben Sie den DOS-Gerätenamen Ihres CD-ROM-Laufwerks ein:")
  (set txt-help-ro
   "Der einzugebende DOS-Gerätename legt fest, mit welchem vorhandenen Gerät CD-Write zusammenarbeiten soll. Dies ist üblicherweise der Name Ihres CD-ROM-Laufwerks, meist »CD0:« genannt. Der DOS-Gerätename muß mit einem Doppelpunkt enden.\n\n")
  (set txt-confirm-ro "CD-Write soll also mit dem Gerät ...\n\n»%s«\n\n... zusammenarbeiten?")
  (set txt-no-ro "Dem von Ihnen angegebenen Namen ...\n\n»%s«\n\n... ist kein gültiger Gerätename zuordenbar.\n\nBitte prüfen Sie, ob Ihr CD-ROM-Laufwerk angemeldet ist, oder berichtigen Sie Ihre Eingabe.")
  (set txt-bad-ro "Der DOS-Gerätename darf weder Leerzeichen noch Anführungszeichen, noch den vertikalen Strich \"|\" enthalten.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-prompt-rw "Bitte legen Sie das Änderungsdatenverzeichnis für CD-Write fest:")
  (set txt-help-rw "Der einzugebende Verzeichnisname legt fest, in welchem Verzeichnis CD-Write die Änderungsdaten ablegen soll. Dieses Verzeichnis muß sich auf einem ständig beschreibbaren Medium befinden.\n\n")
  (set txt-no-rw "Das von Ihnen angegebene übergeordnete Verzeichnis ...\n\n»%s«\n\n... existiert nicht.\n\nBitte legen Sie es erst an, oder berichtigen Sie Ihre Eingabe.")
  (set txt-bad-rw "Der Name des Änderungsdatenverzeichnisses darf weder Leerzeichen noch Anführungszeichen, noch den vertikalen Strich \"|\" enthalten.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-confirm-rw "CD-Write soll also seine Änderungsdaten im Verzeichnis ...\n\n»%s«\n\n... ablegen?")
  (set txt-error-rw "Das von Ihnen angegebene Verzeichnis ...\n\n»%s«\n\n... konnte nicht angelegt werden.\n\nBitte überprüfen Sie Ihre Eingabe.")
  (set txt-prompt-cdw "Unter welchem DOS-Gerätenamen soll CD-Write angemeldet werden?")
  (set txt-help-cdw "Der DOS-Gerätename von CD-Write muß ohne Doppelpunkt spezifiziert werden und darf noch nicht vergeben sein.\n\n")
  (set txt-bad-cdw "Der DOS-Gerätename darf weder Leerzeichen noch Anführungszeichen, noch Doppelpunkte enthalten.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-dup-cdw "Der DOS-Gerätename ...\n\n»%s«\n\n... ist bereits vergeben.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-prompt-l "In welches Verzeichnis soll das Dateisystem kopiert werden?")
  (set txt-bad-l "Der Name des Dateisystemverzeichnisses darf weder Leerzeichen noch Anführungszeichen enthalten.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-prompt-c "In welches Verzeichnis sollen die Zusatzprogramme kopiert werden?")
  (set txt-prompt-util "Kopieren der Zusatzprogramme")
  (set txt-help-util "Die Zusatzprogramme ermöglichen die Steuerung bestimmter Optionen und das Wiederherstellen gelöschter Dateien. Sie sind nicht zwingend notwendig. Details hierzu entnehmen Sie bitte Ihrem Handbuch.\n\n")
  (set txt-prompt-ml "In welche MountList-Datei soll der MountList-Eintrag eingefügt werden?")
  (set txt-help-ml "Der MountList-Eintrag wird benötigt, um CD-Write automatisch anmelden zu können.\n\n")
  (set txt-bad-ml "Der Name der MountList-Datei darf keine Anführungszeichen enthalten.\n\nBitte berichtigen Sie Ihre Eingabe.")
  (set txt-prompt-startup "Das folgende Kommando ...\n\n%s\n\n... muß in Ihre User-Startup-Datei eingefügt werden.")
  (set txt-help-startup "Dieses Kommando meldet CD-Write bei jedem Systemstart an.\n\n")
  (set txt-prompt-dd "In welchem Verzeichnis soll der DOSDrivers-Eintrag angelegt werden?")
  (set txt-help-dd "Geräte mit zugehörigem DOSDrivers-Eintrag werden bei jedem Systemstart automatisch angemeldet. Das Verzeichnis, in dem diese Einträge liegen, muß bereits existieren; es wird nicht automatisch angelegt.\n\n")
  (set txt-prompt-mount "Soll »%s« bereits jetzt durch den Befehl ...\n\n»%s«\n\n... angemeldet werden?")
  (set txt-help-mount "Wird »%s« jetzt nicht angemeldet, so wird CD-Write erst nach einem Neustart aktiv.")
  (set txt-exit "Die Installation von CD-Write ist beendet.\n\n\nViel Spaß!")
  (set txt-abort "Installation nicht möglich.\n\nCD-Write setzt zumindest Kickstart 2.04 voraus.")
 )
)

(if (>= (getversion) $00250084)
 (
  (complete 0)
  (welcome)
  (set oldlevel @user-level)

  (set ro-dev "CD0:")
  (set ok false)
  (until ok
   (set ro-dev
    (askdir
     (default ro-dev)
     (prompt txt-prompt-ro)
     (help txt-help-ro @askdir-help)
     (disk)
    )
   )

   (set ok (not (patmatch "#?[ \"|]#?" ro-dev)))
   (if ok
    (
     (set tmp (getdevice ro-dev))
     (set ok (<> tmp ""))
     (if ok
      (
       (set ro-dev (cat tmp ":"))
       (set ok
        (askbool
         (choices txt-yes txt-no)
         (default 1)
         (prompt (txt-confirm-ro ro-dev))
         (help txt-help-ro)
        )
       )
      )
      (
       (message (txt-no-ro ro-dev))
       (if (= @user-level 0)
        (user 1)
       )
      )
     )
    )
    (message txt-bad-ro)
   )
  )

  (user 1)

  (set rw-dir (tackon @default-dest "cdwdata"))
  (set ok false)
  (until ok
   (set rw-dir
    (askdir
     (default rw-dir)
     (prompt txt-prompt-rw)
     (help txt-help-rw @askdir-help)
     (newpath)
    )
   )

   (set rw-dir-path (pathonly rw-dir))
   (set rw-dir-last (fileonly rw-dir))

   (if (exists rw-dir-path)
    (
     (if (or (patmatch "#? #?" rw-dir-path) (not (patmatch "#?:#?" rw-dir-path)))
      (set rw-dir-path (expandpath rw-dir-path))
     )

     (set i 0)
     (set found false)
     (until found
      (set found (= (substr rw-dir-path i 1) ":"))
      (if (not found)
       (set i (+ i 1))
      )
     )

     (set rw-dir-dev (substr rw-dir-path 0 (+ i 1)))

     (if (patmatch "#? #?" rw-dir-dev)
      (
       (set rw-dir-dev (getdevice rw-dir-dev))
       (if (not (patmatch "#? #?" rw-dir-dev))
        (set rw-dir-path (cat rw-dir-dev ":" (substr rw-dir-path (+ i 1))))
       )
      )
     )

     (set rw-dir (tackon rw-dir-path rw-dir-last))

     (set ok (not (patmatch "#?[ \"|]#?" rw-dir)))
     (if ok
      (
       (set ok
        (askbool
         (choices txt-yes txt-no)
         (default 1)
         (prompt (txt-confirm-rw rw-dir))
         (help txt-help-rw)
        )
       )
       (if ok
        (
         (if (not (exists rw-dir (noreq)))
          (
           (trap 4 (makedir rw-dir))
           (if (<> @error-msg "")
            (
             (message (txt-error-rw rw-dir))
             (set ok false)
            )
           )
          )
         )
        )
       )
      )
      (message txt-bad-rw)
     )
    )
    (message (txt-no-rw rw-dir-path))
   )
  )

  (user oldlevel)

  (set suffix 0)
  (set ok false)
  (until ok
   (set cdw-name (cat "CDW" suffix))
   (exists (cat cdw-name ":") (noreq))
   (set ok (= (getassign cdw-name "d") ""))
   (if (not ok)
    (set suffix (+ suffix 1))
   )
  )

  (if (<> suffix 0)
   (if (= @user-level 0)
    (user 1)
   )
  )

  (set ok false)
  (until ok
   (set cdw-name
    (askstring
     (default cdw-name)
     (prompt txt-prompt-cdw)
     (help txt-help-cdw @askstring-help)
    )
   )

   (set ok (not (patmatch "#?[ \":]#?" cdw-name)))
   (if ok
    (
     (exists (cat cdw-name ":") (noreq))
     (set ok (= (getassign cdw-name "d") ""))
     (if (not ok)
      (message (txt-dup-cdw cdw-name))
     )
    )
    (message txt-bad-cdw)
   )
  )

  (user oldlevel)

  (set l-dir "L:")
  (set ok false)
  (until ok
   (
    (set l-dir
     (askdir
      (default l-dir)
      (prompt txt-prompt-l)
      (help @askdir-help)
     )
    )

    (if (not (patmatch "#?:#?" l-dir))
     (set l-dir (expandpath l-dir))
    )

    (set ok (not (patmatch "#?[ \"]#?" l-dir)))
    (if (not ok)
     (message txt-bad-l)
    )
   )
  )

  (set c-dir
   (askdir
    (default "C:")
    (prompt txt-prompt-c)
    (help @askdir-help)
   )
  )

  (set base-dir (pathonly @icon))

  (copyfiles
   (source (tackon base-dir "l/BabelCDWriteFS"))
   (dest l-dir)
  )

  (complete 20)

  (copyfiles
   (prompt txt-prompt-util)
   (source (tackon base-dir "c"))
   (choices "BabelCDWriteCtrl" "BabelCDWriteUnDelete")
   (dest c-dir)
   (help txt-help-util @copyfiles-help)
   (optional)
   (confirm)
  )

  (complete 40)

  (if (< (shiftright (getversion "libs:version.library") 16) 38)
   (
    (set ml-file "DEVS:MountList")
    (set ok false)
    (until ok
     (
      (set ml-file
       (askfile
        (default ml-file)
        (prompt txt-prompt-ml)
        (help txt-help-ml @askfile-help)
       )
      )

      (set ok (not (patmatch "#?\"#?" ml-file)))
      (if (not ok)
       (message txt-bad-ml)
      )
     )
    )

    (set tmp (cat "T:MountList." cdw-name ".tmp"))
    (set entry (cat "\n" cdw-name ": Handler   = " (tackon l-dir "BabelCDWriteFS") "\n      Startup   = " ro-dev "|" rw-dir "\n      StackSize = 4096\n      Priority  = 10\n      GlobVec   = -1\n      Mount     = 1\n#\n\n"))
    (if (exists ml-file)
     (textfile
      (dest tmp)
      (append entry)
      (include ml-file)
      (safe)
     )
     (textfile
      (dest tmp)
      (append entry)
      (safe)
     )
    )

    (copyfiles
     (source tmp)
     (dest (pathonly ml-file))
     (newname (fileonly ml-file))
     (optional "fail" "force" "askuser")
    )
    (delete tmp (safe))

    (complete 60)

    (if (= ml-file "DEVS:MountList")
     (set mount-cmd (cat "Mount " cdw-name ":"))
     (set mount-cmd (cat "Mount " cdw-name ": From \"" ml-file "\""))
    )

    (startup @app-name
     (command mount-cmd)
     (prompt (txt-prompt-startup mount-cmd))
     (help txt-help-startup @startup-help)
    )
   )
   (
    (set dd-dir
     (askdir
      (default "DEVS:DOSDrivers")
      (prompt txt-prompt-dd)
      (help txt-help-dd @askdir-help)
      (newpath)
     )
    )

    (set tmp (tackon dd-dir cdw-name))
    (textfile
     (dest tmp)
     (append cdwname "Handler   = " (tackon l-dir "BabelCDWriteFS") "\nStartup   = " ro-dev "|" rw-dir "\nStackSize = 4096\nPriority  = 10\nGlobVec   = -2\nMount     = 1\n")
    )

    (copyfiles
     (source (tackon base-dir "DOSDrivers/CDW0.info"))
     (dest dd-dir)
     (newname (cat cdw-name ".info"))
    )

    (set mount-cmd (cat "Mount \"" tmp "\""))
   )
  )

  (complete 80)

  (run mount-cmd
   (prompt (txt-prompt-mount cdw-name mount-cmd))
   (help (txt-help-mount cdw-name))
   (confirm)
  )

  (complete 100)
  (set @default-dest "")
  (exit txt-exit)
 )
 (abort txt-abort)
)
