;
;$VER: Install-Script 1.2 (12.03.98)
;               
;======================
;=== Global strings ===
;======================
(set #installer_locale 0) 
;
; Determine language
;
; #installer_locale = 0: english
;                   = 1: deutsch
;                   = 2: sverige
;                           
(if (= @language "deutsch") (set #installer_locale 1))
(if (= @language "sverige") (set #installer_locale 2))
;
;==================== english ====================
;
(if (= #installer_locale 0)
    (set            
        ;=== general ===
        ;
        #welcome_text        (cat "This script lets you install\n" @app-name "\non your system.")
        #welcome_update      (cat "This script will update an existing\n" @app-name "\ninstallation.")
        #welcome_remove      (cat "This script will remove an existing\n" @app-name "\ninstallation.")
        #error_instvers_msg  (cat "You are using the installer version %ld.%ld.\n"
                                  "This script will probably not work.\n"
                                  "Try installing anyway ?")
        #error_instvers_help (cat "Get the most resent version from http://www.amiga.de\nVersion 42.9+ is required.")
        #action_prompt       (cat "What do you want to do ?")
        #action_help         (cat "Select an action to perform.")
        #action_install      (cat "Install")
        #action_update       (cat "Update")
        #action_remove       (cat "Remove")
        #cpu_too_low         (cat "You have installed a " (database "cpu") " processor, but a 68020 processor "
                                  "is minimal required in order to use " @app-name ".\nI'm quitting now...")
        ;=== program files ===
        ;
        #askdest_prompt    (cat "Select destination for " @app-name ". A drawer will be created, if necessary.")
        #askdest_help      (cat "Select the destination drawer for " @app-name ". A new drawer will be generated.")
        #files2copy_prompt (cat "Select main program to install.")
        #files2copy_help   (cat "Select the program file to install according to the processor your system has.")
        #copycopy_prompt   (cat "The %s version of " @app-name " will be copied.")
        #copycopy_help     (cat #copycopy_prompt)
        ;=== catalogs ===
        ;
        #catalog_f2c_prompt (cat "Select language catalog to copy.")
        #catalog_f2c_help   (cat "Select the language(s) to install.")
        #getcat_prompt      (cat "Select target drawer for catalog(s). A drawer will be created, if necessary.")
        #getcat_help        (cat "Normally, select the drawer the main program was installed to. "
                                 "A new drawer will be generated, if necessary. "
                                 "LOCALE: would be another option.")
        #copycat_prompt     (cat "Copying %s catalog...")
        #copycat_help       (cat "The %s catalog files will be copied.")
        ;=== guide ===
        ;
        #guide_f2c_prompt (cat "Select documentation to install.")
        #guide_f2c_help   (cat "Select documentation language you like to install.")
        #getdoc_prompt    (cat "Select destination for documentation. A drawer will be created, if necessary.")
        #getdoc_help      (cat "Normally, select the drawer the main program was installed to. "
                               "A new drawer will be generated, if necessary.")
        #copydoc_prompt   (cat "Copying documentation...")
        #copydoc_help     (cat "The %s documentation will be copied.")
        #copydoc_misc_pmt (cat "Copying miscellaneous documentation...")
        #copydoc_misc_hlp (cat "Some additional texts will be copied.")
        ;=== arexx ===
        ;
        #rexx_f2c_prompt  (cat "Install arexx examples ?")
        #rexx_f2c_help    (cat "Select wether to install the example arexx files or not.")
        #rexx_dest_prompt (cat "Select arexx example drawer. A new drawer will be created, if necessary.")
        #rexx_dest_help   (cat "Select a drawer into which the example arexx files will be installed. "
                               "A new drawer will be generated, if necessary.")
        #rexx_copy_prompt (cat "Copying arexx examples...")
        #rexx_copy_help   (cat "The arexx example files will be copied.") 
        ;=== wbstartup ===
        ;
        #cpy_wbstartup_prompt (cat "Start " @app-name " automatically every time you boot ?")
        #cpy_wbstartup_help   (cat "An icon will be copied to SYS:WBStartup/ drawer. Every time you boot "
                                   @app-name " will be started automatically. Select the program version "
                                   "to be started.")
        #cpy_wbstart_none     (cat "No")       
        #wbstart_prompt       (cat "The %s client will be started on boot time.")
        #wbstart_help         (cat "The selected version of " @app-name " will be started during booting.")
        ;=== tooltypes ===
        ;
        #ttype_prefs_prompt (cat "Since %s is a commodity some setup is required.\n"
                                 "Type the keys which will bring up the preferences window, "
                                 "for example\n'lshift lalt v' (= left shift + left alt + v):"
                            )
        #ttype_prefs_help   (cat "Type in a combination of keys, but without then \'.")
        #ttype_load_prompt  (cat "Type the keys which will bring up a file load requester:")
        #ttype_load_help    (cat "Same as previous. " #ttype_prefs_help)
        #ttype_popup_prompt (cat "Should the preferences window open automatically after program start ?")
        #ttype_popup_help   (cat "You can change this later via the tooltype CX_POPUP=<YES|NO>.")
        #ttype_set_prompt   (cat "The requested changes to the %s program icon will be made.")
        #ttype_set_help     (cat "All changes can be manually altered later.")
        ;=== update drawer ===
        ;
        #update_dest_prompt (cat "Locate " @app-name "'s executable(s):")
        #update_dest_help   (cat "Select the drawer where " @app-name "'s executable(s) resides in.")
        #update_f2c_prompt  (cat "Select executables to update:")
        #update_f2c_help    (cat "Select that executable(s) which should be updated.")
        #update_cat_prompt  (cat "Select drawer where old catalogs were installed:")
        #update_cat_help    (cat "This should be either the drawer where the executables reside in "
                                 "or LOCALE:")
        #update_no_exe      (cat "Couldn't find files to update. Exitting...")
        ;=== remove drawer ===
        ;                             
        #remove_safe_prompt (cat "Do you really want to delete your\n" @app-name "\ninstallation ?")
        #remove_safe_help   (cat "This is the last chance to cancel !!!")
        #remove_del_prompt  (cat "Deleting old\n" @app-name "\ninstallation.")
        #remove_del_help    (cat "You will get no second chance to quit !!!")
        #remove_no_exe      (cat "Didn't find " @app-name " executable(s) in selected drawer. Exitting...")
    )
)
;
; ==================== deutsch ====================
;
(if (= #installer_locale 1)
    (set
        ;=== general ===
        ;
        #welcome_text        (cat "Dieses Script installiert\n" @app-name "\nauf Ihrem System.")
        #welcome_update      (cat "Dieses Script erneuert eine vorhandene Installation von\n" @app-name)
        #welcome_remove      (cat "Dieses Script entfernt eine vorhandene Installation von\n" @app-name)
        #error_instvers_msg  (cat "Sie benutzen den Installer in der Version %ld.%ld.\n"
                                  "Die Installations wird wahrscheinlich nicht funktionieren.\n"
                                  "Installation dennoch versuchen ?")
        #error_instvers_help (cat "Die neueste Version ist zu finden unter http://www.amiga.de\nVersion 42.9+ wird benötigt.")
        #action_prompt       (cat "Was wollen Sie ausführen ?")
        #action_help         (cat "Wählen Sie eine Aktion.")
        #action_install      (cat "Installieren")
        #action_update       (cat "Erneuern")
        #action_remove       (cat "Entfernen")
        #cpu_too_low         (cat "Sie haben einen " (database "cpu") " Prozessor installiert, aber um " @app-name
                                  " zu benutzen, benötigen Sie mindestens einen 68020 Prozessor.\nDie Installation "
                                  "wird nun abgebrochen...")      
        ;=== program files ===
        ;           
        #askdest_prompt    (cat "Zielverzeichnis für " @app-name " wählen. Es wird ein neues Verzeichnis erstellt, falls nötig.")
        #askdest_help      (cat "Wählen Sie das Zielverzeichnis, in das " @app-name "installiert werden "
                                "soll. Es wird ein neues Verzeichnis erstellt.")
        #files2copy_prompt (cat "Wählen Sie das zu installierende Hauptprogramm.")
        #files2copy_help   (cat "Wählen Sie das zu installierende Hauptprogramm, das dem Prozessor Ihres System entspricht.")
        #copycopy_prompt   (cat "Die %s Version von " @app-name " wird installiert.")
        #copycopy_help     (cat #copycopy_prompt)
        ;=== catalogs ===
        ;
        #catalog_f2c_prompt (cat "Wählen Sie den zu installierenden Sprach-Katalog.")
        #catalog_f2c_help   (cat "Wählen Sie die Sprache, die das Hauptprogramm benutzen soll.")
        #getcat_prompt      (cat "Zielverzeichnis für Katalog(e) wählen. Ein Verzeichnis wird erstellt, falls nötig.")
        #getcat_help        (cat "Normalerweise sollte dasselbe Verzeichnis gewählt werden, "
                                 "in welches das Hauptprogramm installiert wurde. Ein Verzeichnis "
                                 "wird erstellt, falls nötig. LOCALE: wäre eine andere Möglichkeit.")
        #copycat_prompt     (cat "Installiere %s Katalog...")
        #copycat_help       (cat "Die %s Katalog-Dateien werden installiert.")
        ;=== guide ===
        ;
        #guide_f2c_prompt (cat "Wählen Sie die zu installierende Dokumentation.")
        #guide_f2c_help   (cat "Wählen Sie die Sprache der Dokumentation, die installiert werden soll.")
        #getdoc_prompt    (cat "wählen Sie das Zielverzeichnis für die Dokumentation. Ein neues Verzeichnis wird erstellt, falls nötig.")
        #getdoc_help      (cat "Normalerweise sollte dasselbe Verzeichnis gewählt werden, "
                               " in welches das Hauptprogramm installiert wurde. Ein Verzeichnis "
                               "wird erstellt, falls nötig.")
        #copydoc_prompt   (cat "Installiere Dokumentation...")
        #copydoc_help     (cat "Die %s Dokumentation wird installiert.")
        #copydoc_misc_pmt (cat "Installiere zusätzliche Dokumentationen...")
        #copydoc_misc_hlp (cat "Einige Texte mit zusätzliche Informationen werden installiert.")
        ;=== arexx ===
        ;
        #rexx_f2c_prompt  (cat "ARexx-Beispieldateien installieren ?")
        #rexx_f2c_help    (cat "Wählen Sie, ob die ARexx-Beispieldateien installiert werden sollen oder nicht.")
        #rexx_dest_prompt (cat "Wählen Sie das Zielverzeichnis für die ARexx-Beispieldateien. Ein neues Verzeichnis "
                               "wird erstellt, falls nötig.")
        #rexx_dest_help   (cat "Wählen Sie das Verzeichnis, in welches die ARexx-Beispieldateien installiert "
                               "werden sollen. Es wird ein neues Verzeichnis erstellt, falls nötig.")
        #rexx_copy_prompt (cat "Installiere ARexx-Beispieldateien...")
        #rexx_copy_help   (cat "Die ARexx-Beispieldateien werden kopiert.") 
        ;=== wbstartup ===
        ;                           
        #cpy_wbstartup_prompt (cat @app-name " beim booten automatisch starten ?")
        #cpy_wbstartup_help   (cat "Ein Piktogramm wird in das Verzeichnis SYS:WBStartup/ kopiert. "
                                   "Jedesmal, wenn der Rechner bootet, wird " @app-name " automatisch gestartet. "
                                   "Wählen Sie das zu startende Hauptprogramm.")
        #cpy_wbstart_none     (cat "Nein")       
        #wbstart_prompt       (cat "Die %s Version des Hauptprogramms wird beim booten gestartet.")
        #wbstart_help         (cat "Die ausgewählte Version des Hauptprogramm von " @app-name " wird gestartet, "
                                   "wenn der Rechner bootet.")          
        ;=== tooltypes ===
        ;
        #ttype_prefs_prompt (cat "Da %s ein Commodity ist, müssen noch einige Einstellungen vorgenommen werden.\n"
                                 "Geben Sie die Tastenkombination ein, mit der das Voreinstellungsfenster geöfnet werden soll, "
                                 "z.B.\n'lshift lalt v' (= linke Shift-Taste + linke Alt-Taste + v):"
                            )
        #ttype_prefs_help   (cat "Geben Sie ein Tastenkombination ein, jedoch ohne \'.")
        #ttype_load_prompt  (cat "Geben Sie die Tasenkonbination ein, die eine Dateiabfrage öffnet:")
        #ttype_load_help    (cat "Wie vorherige. " #ttype_prefs_help)
        #ttype_popup_prompt (cat "Soll das Voreinstellungsfenster automatisch nach dem Programmstart geöffnet werden ?")
        #ttype_popup_help   (cat "Sie können dies später ändern über das ToolType CX_POPUP=<YES|NO>.")
        #ttype_set_prompt   (cat "Die geforderten Änderung werden am %s Piktogramm vorgenommen.")
        #ttype_set_help     (cat "Alle Anpassungen können später wieder von Hand geändert werden.")
        ;=== update drawer ===
        ;
        #update_dest_prompt (cat "Wo befindet sich die Hauptprogramme der alten Installation von\n" @app-name " ?")
        #update_dest_help   (cat "Wählen Sie das Verzeichnis, in welches die Hauptprogramme (oder das "
                                 "Hauptprogramm) von " @app-name " installiert worden war(en).")
        #update_f2c_prompt  (cat "Zu erneuernde(s) Hauptprogramm(e) wählen:")
        #update_f2c_help    (cat "Wählen Sie das/die zu erneuernde(s) Hauptprogramm(e).")
        #update_cat_prompt  (cat "Wählen Sie das Verzeichnis, in dem die Kataloge installiert sind.")
        #update_cat_help    (cat "Dies sollte das Hauptprogramm-Verzeichnis sein oder LOCALE:")
        #update_no_exe      (cat "Kann keine zu erneuernden Dateien finden. Breche ab...")
        ;=== remove drawer ===
        ;
        #remove_safe_prompt (cat "Wollen Sie wirklich Ihre Installation von\n" @app-name "\nentfernen ?")
        #remove_safe_help   (cat "Dies ist die letzte Chance abzubrechen !!!")
        #remove_del_prompt  (cat "Entferne alte\n" @app-name "-Installation.")
        #remove_del_help    (cat "Sie werden keine zweite Chance zum Abbruch bekommen !!!")
        #remove_no_exe      (cat "Konnte kein(e) " @app-name " Hauptprogramm(e) im gewählten Verzeichnis "
                                 "finden. Breche ab...")
    )
)
;
; ==================== sverige ====================
;
(if (= #installer_locale 2)
    (set
        ;=== general ===
        ;
        #welcome_text        (cat "This script lets you install\n" @app-name "\non your system.")
        #welcome_update      (cat "This script will update an existing\n" @app-name "\ninstallation.")
        #welcome_remove      (cat "This script will remove an existing\n" @app-name "\ninstallation.")
        #error_instvers_msg  (cat "You are using the installer version %ld.%ld.\n"
                                  "This script will probably not work.\n"
                                  "Try installing anyway ?")
        #error_instvers_help (cat "Get the most resent version from http://www.amiga.de\nVersion 42.9+ is required.")
        #action_prompt       (cat "What do you want to do ?")
        #action_help         (cat "Select an action to perform.")
        #action_install      (cat "Install")
        #action_update       (cat "Update")
        #action_remove       (cat "Remove")
        #cpu_too_low         (cat "You have installed a " (database "cpu") " processor, but a 68020 processor "
                                  "is minimal required in order to use " @app-name ".\nI'm quitting now...")
        ;=== program files ===
        ;
        #askdest_prompt    (cat "Select destination for " @app-name ". A drawer will be created, if necessary.")
        #askdest_help      (cat "Select the destination drawer for " @app-name ". A new drawer will be generated.")
        #files2copy_prompt (cat "Select main program to install.")
        #files2copy_help   (cat "Select the program file to install according to the processor your system has.")
        #copycopy_prompt   (cat "The %s version of " @app-name " will be copied.")
        #copycopy_help     (cat #copycopy_prompt)
        ;=== catalogs ===
        ;
        #catalog_f2c_prompt (cat "Select language catalog to copy.")
        #catalog_f2c_help   (cat "Select the language(s) to install.")
        #getcat_prompt      (cat "Select target drawer for catalog(s). A drawer will be created, if necessary.")
        #getcat_help        (cat "Normally, select the drawer the main program was installed to. "
                                 "A new drawer will be generated, if necessary. "
                                 "LOCALE: would be another option.")
        #copycat_prompt     (cat "Copying %s catalog...")
        #copycat_help       (cat "The %s catalog files will be copied.")
        ;=== guide ===
        ;
        #guide_f2c_prompt (cat "Select documentation to install.")
        #guide_f2c_help   (cat "Select documentation language you like to install.")
        #getdoc_prompt    (cat "Select destination for documentation. A drawer will be created, if necessary.")
        #getdoc_help      (cat "Normally, select the drawer the main program was installed to. "
                               "A new drawer will be generated, if necessary.")
        #copydoc_prompt   (cat "Copying documentation...")
        #copydoc_help     (cat "The %s documentation will be copied.")
        #copydoc_misc_pmt (cat "Copying miscellaneous documentation...")
        #copydoc_misc_hlp (cat "Some additional texts will be copied.")
        ;=== arexx ===
        ;
        #rexx_f2c_prompt  (cat "Install arexx examples ?")
        #rexx_f2c_help    (cat "Select wether to install the example arexx files or not.")
        #rexx_dest_prompt (cat "Select arexx example drawer. A new drawer will be created, if necessary.")
        #rexx_dest_help   (cat "Select a drawer into which the example arexx files will be installed. "
                               "A new drawer will be generated, if necessary.")
        #rexx_copy_prompt (cat "Copying arexx examples...")
        #rexx_copy_help   (cat "The arexx example files will be copied.")
        ;=== wbstartup ===
        ;
        #cpy_wbstartup_prompt (cat "Start " @app-name " automatically every time you boot ?")
        #cpy_wbstartup_help   (cat "An icon will be copied to SYS:WBStartup/ drawer. Every time you boot "
                                   @app-name " will be started automatically. Select the program version "
                                   "to be started.")
        #cpy_wbstart_none     (cat "No")
        #wbstart_prompt       (cat "The %s client will be started on boot time.")
        #wbstart_help         (cat "The selected version of " @app-name " will be started during booting.")
        ;=== tooltypes ===
        ;
        #ttype_prefs_prompt (cat "Since %s is a commodity some setup is required.\n"
                                 "Type the keys which will bring up the preferences window, "
                                 "for example\n'lshift lalt v' (= left shift + left alt + v):"
                            )
        #ttype_prefs_help   (cat "Type in a combination of keys, but without then \'.")
        #ttype_load_prompt  (cat "Type the keys which will bring up a file load requester:")
        #ttype_load_help    (cat "Same as previous. " #ttype_prefs_help)
        #ttype_popup_prompt (cat "Should the preferences window open automatically after program start ?")
        #ttype_popup_help   (cat "You can change this later via the tooltype CX_POPUP=<YES|NO>.")
        #ttype_set_prompt   (cat "The requested changes to the %s program icon will be made.")
        #ttype_set_help     (cat "All changes can be manually altered later.")
        ;=== update drawer ===
        ;
        #update_dest_prompt (cat "Locate " @app-name "'s executable(s):")
        #update_dest_help   (cat "Select the drawer where " @app-name "'s executable(s) resides in.")
        #update_f2c_prompt  (cat "Select executables to update:")
        #update_f2c_help    (cat "Select that executable(s) which should be updated.")
        #update_cat_prompt  (cat "Select drawer where old catalogs were installed:")
        #update_cat_help    (cat "This should be either the drawer where the executables reside in "
                                 "or LOCALE:")
        #update_no_exe      (cat "Couldn't find files to update. Exitting...")
        ;=== remove drawer ===
        ;
        #remove_safe_prompt (cat "Do you really want to delete your\n" @app-name "\ninstallation ?")
        #remove_safe_help   (cat "This is the last chance to cancel !!!")
        #remove_del_prompt  (cat "Deleting old\n" @app-name "\ninstallation.")
        #remove_del_help    (cat "You will get no second chance to quit !!!")
        #remove_no_exe      (cat "Didn't find " @app-name " executable(s) in selected drawer. Exitting...")
    )
)
;======================================
;=== Get install destination drawer ===
;======================================
(procedure P_GetDestination
    (debug "Ask destination drawer:")
    (P_GetDestBaseDrawer)
    (set @default-dest (tackon @default-dest @app-name))   
    (debug "Destination drawer is" @default-dest ".\n")      
)

(procedure P_GetDestBaseDrawer      
    (set @default-dest 
        (askdir
            (prompt  #askdest_prompt)
            (help    #askdest_help "\n\n" @askdir-help)
            (default "RAM:")
            (newpath)
        ) 
    )                                                   
)

;===============================
;=== Copy main program files ===
;===============================
(procedure P_CopyMainFiles
    ;;;
    ; Get destination drawer
    ;;;
    (P_GetDestination)
    ;;;
    ; Select main program files to install
    ;;;
    (set #program_files2copy
        (askoptions
            (prompt  #files2copy_prompt)
            (help    #files2copy_help "\n\n" @askoptions-help)
            (choices (cat @app-name "68k")
                     (cat @app-name "68k FPU")
                     (cat @app-name "PPC")      
            )
            (default 0)
        )
    )                                            
    (if (= #program_files2copy 0) (exit (quiet)))
    ;;;
    ; Generate destination drawer
    ;;;
    (makedir @default-dest
        (infos)
    )
    (debug "Drawer" @default-dest "generated.")
    ;;;
    ; Copy requested files
    ;;;
    (if (IN #program_files2copy 0) (P_CopyOneExecutable "68k")) 
    (if (IN #program_files2copy 1) (P_CopyOneExecutable "68k_fpu"))
    (if (IN #program_files2copy 2) (P_CopyOneExecutable "PPC"))
    (debug "Main files copied.\n")
)

(procedure P_CopyOneExecutable #exe_name
    (debug ("Copying %s files..." #exe_name))
    (copyfiles
        (prompt (#copycopy_prompt #exe_name))
        (help   (#copycopy_help #exe_name) "\n\n" @copyfiles-help)
        (source "/")
        (dest   @default-dest)
        (pattern (cat "#?" #exe_name "#?"))
        (infos)
        (confirm)
    )
)

;=====================
;=== Copy catalogs ===
;=====================         
(procedure P_CopyCatalogs 
    (debug "Ask catalogs to copy:")
    ;;;
    ; Select catalogs to copy
    ;;;
    (if (= @user-level 2)
        (
            (debug "Ask catalog language.")
            (set #catalog_files2copy
                (askoptions
                    (prompt  #catalog_f2c_prompt)
                    (help    #catalog_f2c_help "\n\n" @askoptions-help)
                    (choices "english (built in)"
                             "deutsch"
                             ;;;"sverige"
                    )
                    (default (shiftleft 1 #installer_locale))
                )
            )
        )
        ;else
        (
            (debug "Copy install script language catalog.")           
            (set #catalog_files2copy (shiftleft 1 #installer_locale))
        )
    )
    ;;;
    ; Get catalog drawer
    ;;;
    (if (= @user-level 2)
        (
            (debug "Ask target drawer for catalogs.")
            (set #copycat_target
                (askdir
                    (prompt  #getcat_prompt)
                    (help    #getcat_help "\n\n" @askdir-help)
                    (default @default-dest)
                    (newpath)
                )
            )
        )
        ;else
        (
            (debug "Set target for catalogs to default destination.")
            (set #copycat_target @default-dest)
        )
    )                                                
    ;;;
    ; Create drawer
    ;;;
    (set #copycat_target
        (tackon #copycat_target "Catalogs")
    )
    (makedir #copycat_target)
    (debug "Selected drawer for catalogs is" #copycat_target ".\n")
    ;;;
    ; Copy catalogs
    ;;;                                                              
    (if (IN #catalog_files2copy 0) (P_CopyOneCatalog "english")) 
    (if (IN #catalog_files2copy 1) (P_CopyOneCatalog "deutsch")) 
    (if (IN #catalog_files2copy 2) (P_CopyOneCatalog "sverige"))
    (debug "Catalogs copied.\n")
)

(procedure P_CopyOneCatalog #language_name  
    (debug ("Copying %s catalog to %s." #language_name #copycat_target))
    (makedir (tackon #copycat_target #language_name))                    
    (copyfiles
        (prompt (#copycat_prompt #language_name))
        (help   (#copycat_help #language_name) "\n\n" @copyfiles-help)
        (source (cat "/Catalogs/" #language_name "/"))
        (dest   (tackon #copycat_target (cat #language_name "/")))
        (all)
        (confirm)
    )
)

;=================
;=== Copy docs ===
;=================
(procedure P_CopyDocs
    (debug "Ask guide to copy:")
    ;;;
    ; Select docs to copy
    ;;;
    (if (= @user-level 2)
        (
            (debug "Ask documentation language.")
            (set #catalog_files2copy
                (askchoice
                    (prompt  #guide_f2c_prompt)
                    (help    #guide_f2c_help "\n\n" @askchoice-help)
                    (choices "english"
                             "deutsch"
                             ;;;"sverige"
                    )
                    (default #installer_locale)
                )
            )
        )
        ;else
        (
            (debug "Copy install script language documentation.")
            (set #catalog_files2copy #installer_locale)
        )
    )
    ;;;
    ; Get doc drawer    
    ;;;
    (if (= @user-level 2)
        (
            (debug "Ask target drawer for docs.")
            (set #copydoc_target
                (askdir
                    (prompt  #getdoc_prompt)
                    (help    #getdoc_help "\n\n" @askdir-help)
                    (default @default-dest)
                    (newpath)
                )
            )
        )
        ;else
        (
            (debug "Set target for docs to program drawer.")
            (set #copydoc_target @default-dest)
        )
    )                                             
    ;;;
    ; Create drawer
    ;;;
    (set #copydoc_target
        (tackon #copydoc_target "Guide")
    )
    (makedir #copydoc_target)    
    ;;;
    ; Copy docs
    ;;;
    (if (= #catalog_files2copy 0) (P_CopyOneGuide "English.guide"))  
    (if (= #catalog_files2copy 1) (P_CopyOneGuide "Deutsch.guide"))  
    (if (= #catalog_files2copy 2) (P_CopyOneGuide "Sverige.guide"))
    ;;;
    ; Copy miscellaneous texts
    ;;;
    (copyfiles
        (prompt  #copydoc_misc_pmt)
        (help    #copydoc_misc_hlp "\n\n" @copyfiles-help)
        (source  "/Guide/")
        (dest    #copydoc_target)
        (pattern "#?.txt")
    )
    (debug "Guides copied.\n")
)

(procedure P_CopyOneGuide #guide_name
    (debug ("Copying %s." #guide_name))
    (copyfiles
        (prompt  (#copydoc_prompt #guide_name))
        (help    (#copydoc_help #guide_name) "\n\n" @copyfiles-help)
        (source  (cat "/Guide/" #guide_name))
        (dest    #copydoc_target) 
        (newname (cat @app-name ".guide"))
        (confirm)
    )   
    (copyfiles
        (prompt  (#copydoc_prompt #guide_name))
        (help    (#copydoc_help #guide_name) "\n\n" @copyfiles-help)
        (source  (cat "/Guide/" #guide_name ".info"))
        (dest    #copydoc_target)
        (newname (cat @app-name ".guide.info"))  
    )
)

;==========================
;=== Copy rexx examples ===
;==========================
(procedure P_CopyRexxExamples
    (debug "Ask wether arexx examples to copy.")
    ;;;
    ; Copy arexx examples ?   
    ;;;
    (if (= @user-level 2)
        (
            (debug "Ask wether to install arexx examples.")
            (set #copy_rexx
                (askbool
                    (prompt  #rexx_f2c_prompt)
                    (help    #rexx_f2c_help "\n\n" @askbool-help) 
                    (default 1)
                )
            )
        )
        ;else
        (
            (debug "Install arexx examples by default.")
            (set #copy_rexx 1)
        )
    )
    ;;;
    ; Copy examples requested
    ;;;
    (if (= #copy_rexx 1)
        (
            (debug "Install rexx examples.")
            ;;;
            ; Get arexx drawer
            ;;;
            (if (= @user-level 2)
                (
                    (debug "Ask target drawer for arexx")
                    (set #copyrexx_target
                        (askdir
                            (prompt  #rexx_dest_prompt)
                            (help    #rexx_dest_help "\n\n" @askdir-help)
                            (default @default-dest)
                            (newpath)
                        )
                    )
                )
                ;else
                (
                    (debug "Set target for rexx to program drawer")
                    (set #copyrexx_target @default-dest)
                )
            )                                                
            ;;;
            ; Create drawer
            ;;;
            (set #copyrexx_target
                (tackon #copyrexx_target "Rexx")
            )
            (makedir #copyrexx_target)  
            ;;;
            ; Copy files
            ;;;
            (debug "Copying arexx examples.")
            (copyfiles
                (prompt  #rexx_copy_prompt)
                (help    #rexx_copy_help "\n\n" @copyfiles-help)
                (source  "/Rexx/")
                (dest    #copyrexx_target)
                (all)              
                (confirm)
            )                                               
            (debug "ARexx examples copied.\n")
        )
    )
)                                                      

;=====================
;=== Set tooltypes ===
;=====================
(procedure P_InitToolTypes
    (debug "About to set tooltypes.")
    ;;;
    ; Pop up preferences keys
    ;;;
    (set #ttype_prefs_key
        (askstring
            (prompt (#ttype_prefs_prompt @app-name))
            (help   #ttype_prefs_help "\n\n" @askstring-help)
        )
    )
    (debug ("Prefs popup key is %s." #ttype_prefs_key))
    ;;;
    ; Pop up load key
    ;;;
    (set #ttype_load_key
        (askstring
            (prompt #ttype_load_prompt)
            (help   #ttype_load_help "\n\n" @askstring-help)
        )
    )
    (debug ("Prefs popup key is %s." #ttype_load_key))
    ;;;
    ; Pop up preferences after start
    ;;;
    (set #ttype_popup
        (askbool
            (prompt #ttype_popup_prompt)
            (help   #ttype_popup_help "\n\n" @askbool-help)
            (default 0)
        )
    )
    (if (= #ttype_popup 0)
        (
            (set #ttype_popup "NO")
        )
        ;else
        (
            (set #ttype_popup "YES")
        )
    )
    (debug ("Popup preferences after program start is set to %s." #ttype_popup))
    ;;;
    ; Adjust tooltypes
    ;;;
    (if (IN #program_files2copy 0) (P_SetToolTypes "68k"))
    (if (IN #program_files2copy 1) (P_SetToolTypes "68k_fpu"))
    (if (IN #program_files2copy 2) (P_SetToolTypes "PPC"))
    ;;;
    ; Copy icon to wbstartup
    ;;;
    (if (= #copy_wbstartup 1) (P_CopyWBStartup "68k"))
    (if (= #copy_wbstartup 2) (P_CopyWBStartup "68k_fpu"))
    (if (= #copy_wbstartup 3) (P_CopyWBStartup "PPC"))
)

(procedure P_CopyWBStartup #main_type
    (debug ("Copy %s icon to SYS:WBStartup/." #main_type))
    (set #wbstartup_target "SYS:WBStartup/")
    (copyfiles
        (prompt  (#wbstart_prompt #main_type))
        (help    #wbstart_help "\n\n" @copyfiles-help)
        (source  "WBStartup_icon")
        (dest    #wbstartup_target)
        (newname (cat @app-name #main_type ".info"))
        (confirm)
    )                                          
    (tooltype    
        (dest (cat #wbstartup_target @app-name #main_type))
        (setdefaulttool (cat (tackon @default-dest @app-name) #main_type))
        (settooltype "LOADKEY"   #ttype_load_key)
        (settooltype "CX_POPKEY" #ttype_prefs_key)
        (settooltype "CX_POPUP"  #ttype_popup)
        (settooltype "DONOTWAIT" "")
        (setstack 16384)
        (noposition)
    )
)                       

(procedure P_SetToolTypes #name_expand 
    (debug ("Setting %s icon information." #name_expand))
    (tooltype
        (prompt (#ttype_set_prompt #name_expand))
        (help #ttype_set_help)
        (dest (cat (tackon @default-dest @app-name) #name_expand))
        (settooltype "LOADKEY"   #ttype_load_key)
        (settooltype "CX_POPKEY" #ttype_prefs_key)
        (settooltype "CX_POPUP"  #ttype_popup)
        (settooltype "DONOTWAIT" "")
        (setstack 16384)
        (noposition)
        (confirm)
    )
)

;=====================
;=== Install stuff ===
;=====================
(procedure P_Install
    (debug "Perform installation")
    (welcome #welcome_text)

    (P_CopyMainFiles)
    (complete 25)

    (P_CopyCatalogs)
    (complete 50)

    (P_CopyDocs)
    (complete 75)

    (P_CopyRexxExamples)
    (complete 99)
    ;
    ;=== Copy icon to wbstartup
    ;
    (set #cpy_wbstart_68k     "")
    (set #cpy_wbstart_68k_fpu "")
    (set #cpy_wbstart_ppc     "")
    (if (IN #program_files2copy 0) (set #cpy_wbstart_68k     (cat @app-name "68k")))
    (if (IN #program_files2copy 1) (set #cpy_wbstart_68k_fpu (cat @app-name "68k FPU")))
    (if (IN #program_files2copy 2) (set #cpy_wbstart_ppc     (cat @app-name "PPC")))
    (set #copy_wbstartup
        (askchoice
            (prompt  #cpy_wbstartup_prompt)
            (help    #cpy_wbstartup_help "\n\n" @askchoice-help)
            (choices #cpy_wbstart_none
                     #cpy_wbstart_68k
                     #cpy_wbstart_68k_fpu
                     #cpy_wbstart_ppc
            )
            (default 0)
        )
    )                    
    (debug ("Copy to SYS:WBStartup/ is %ld." #copy_wbstartup))

    (P_InitToolTypes)
    (complete 100)
)

;=======================================
;=== Update an existing installation ===
;=======================================
(procedure P_Update
    (debug "Perform update")
    (welcome #welcome_update)
    ;=== Get destination drawer ===
    ;
    (set #askdest_prompt #update_dest_prompt
         #askdest_help   #update_dest_help  
    )
    (P_GetDestBaseDrawer)
    (debug ("Old installation in %s." @default-dest))
    ;=== Get files to update ===
    ;
    (set #update_files 0)
    (P_FilesToUpdate "68k"     1)
    (P_FilesToUpdate "68k_fpu" 2)
    (P_FilesToUpdate "PPC"     4)
    (debug ("Update executable bitmask is %ld.\n" #update_files))
    (if (= #update_files 0)
        (
            (message #update_no_exe)
            (exit (quiet))
        )                                                            
    )
    ;=== Update main ===
    ;                     
    (if (IN #update_files 0)
        (set #upd_68k (cat @app-name "68k"))
        ;else
        (set #upd_68k "")
    )
    (if (IN #update_files 1)
        (set #upd_68k_fpu (cat @app-name "68k FPU"))
        ;else
        (set #upd_68k_fpu "")
    )
    (if (IN #update_files 2)
        (set #upd_PPC (cat @app-name "PPC"))
        ;else
        (set #upd_PPC "")
    )
    (if (= @user-level 2)
        (set #update_files
            (askoptions
                (prompt  #update_f2c_prompt)
                (help    #update_f2c_help "\n\n" @askoptions-help)
                (choices #upd_68k
                         #upd_68k_fpu
                         #upd_PPC
                )
                (default 0)
            )
        )
    )
    (if (IN #update_files 0) (P_CopyOneExecutable "68k"))
    (if (IN #update_files 1) (P_CopyOneExecutable "68k_fpu"))
    (if (IN #update_files 2) (P_CopyOneExecutable "PPC"))
    (debug "Main files updated.")
    ;=== Update catalog(s) ===
    ;                                   
    (if (OR (= @user-level 2) (NOT (exists (tackon @default-dest "Catalogs"))))
        (
            (debug "Ask old catalogs drawer.")
            (set #copycat_target
                (askdir
                    (prompt  #update_cat_prompt)
                    (help    #update_cat_help "\n\n" @askdir-help)
                    (default @default-dest)
                    (newpath)
                )
            )
        )      
        ;else
        (
            (debug "Set target for catalogs to default destination.")
            (set #copycat_target @default-dest)
        )
    )
    (set #copycat_target
        (tackon @default-dest "Catalogs")
    )
    (if (exists #copycat_target)
        (foreach #copycat_target "#?"
            (P_CopyOneCatalog @each-name)
        )
    )
    (debug "Catalogs updated.")
    ;=== Update doc ===
    ;
    (P_CopyDocs)
    ;=== Update rexx ===
    ;
    (P_CopyRexxExamples)
    (debug "Update complete.\n")
)

(procedure P_FilesToUpdate #file_expand #bit_mask
    (set #update_filename (cat (tackon @default-dest @app-name) #file_expand))
    (debug ("Updating file %s ?" #update_filename))
    (if (exists #update_filename)
        (                    
            (set #update_files (BITOR #update_files #bit_mask))
            (debug ("\tUpdating old %s file." #update_filename))
        )
        ;else
        (
            (debug "\tNo old installation found.")
        ) 
    )
)

;====================================
;=== Remove existing installation ===
;====================================
(procedure P_Remove
    (debug "Perform remove")    
    (welcome #welcome_remove)
    ;=== Get destination drawer ===
    ;
    (set #askdest_prompt #update_dest_prompt  
         #askdest_help   #update_dest_help    
    )
    (P_GetDestBaseDrawer)
    (debug ("Drawer to remove is %s." @default-dest)) 
    ;=== Main executable(s) there ? ===
    ;
    (debug "Main executable(s) there ?")
    (if (NOT (exists (cat (tackon @default-dest @app-name) "68k")))
        (
            (if (NOT (exists (cat (tackon @default-dest @app-name) "68k_fpu")))
                (
                    (if (NOT (exists (cat (tackon @default-dest @app-name) "PPC")))
                        (
                            (message #remove_no_exe)
                            (exit (quiet))
                        )
                    )
                )
            )
        )
    )    
    ;=== Remove drawer ===
    ;
    (set #really_delete
        (askbool
            (prompt  #remove_safe_prompt)
            (help    #remove_safe_help "\n\n" @askbool-help)
            (default 0)
        )
    )
    (if (= #really_delete 1)
        (
            (debug ("Deleting drawer %s." @default-dest))
            (set @default-dest (tackon @default-dest "/"))
            (set @default-dest (substr @default-dest 0 (- (strlen @default-dest) 2)))
            (delete @default-dest
                (prompt #remove_del_prompt)
                (help   #remove_del_help)
                (all)
                (optional askuser)
                (confirm)
            )                                             
            (delete (cat @default-dest ".info")
                (prompt #remove_del_prompt)
                (help   #remove_del_help) 
                (optional askuser)  
            )          
            (set @default-dest "RAM:")
        )
    )
)

;============
;=== Main ===
;============                        
(complete 0)
          
;=== Check 68k processor version ===
;
(debug ("CPU is a %s." (database "cpu")))
(if (patmatch "(68000|68010)" (database "cpu"))
    (
        (message #cpu_too_low)
        (exit (quiet))
    )
)                                 
;=== Check installer version & exit eventually ===
;
(set #install_ver (/ @installer-version 65536))
(set #install_rev (- @installer-version (* #install_ver 65536))) 
(debug ("Installer version %ld.%ld." #install_ver #install_rev))
(if (< #install_ver 43)
    (
        (debug "Installer version too low.")           
        (set #installer_ok
            (askbool
                (prompt (#error_instvers_msg #install_ver #install_rev))
                (help   #error_instvers_help "\n\n" @askbool-help)
                (default 0)
            )
        )
    )
    ;else
    (
        (debug "Installer version is ok.")
        (set #installer_ok 1)
    )
)
(if (NOT #installer_ok)
    (
        (debug "Aborting installation.")
        (exit (quiet))
    )
)
;=== Select type of action ===
;                       
(set #type_of_action
    (askchoice
        (prompt  #action_prompt)
        (help    #action_help "\n\n" @askchoice-help)
        (choices
            #action_install
            #action_update
            #action_remove
        )
    )
)                                                  
(if (= #type_of_action 0) (P_Install))
(if (= #type_of_action 1) (P_Update))
(if (= #type_of_action 2) (P_Remove))
(exit)
