(welcome)


(SET InstallPath 
  (ASKDIR
    (PROMPT "Please select the directory to install the program. The recommended "
            "installation destination is the drawer of your packet programme"
            "because you don't have to open two drawers when using packet radio")
    (HELP "You have to select where to install the programs on your "
          "harddisk.\n\n" @askdir-help)
    (DEFAULT @default-dest)
  )
)

(SET @default-dest InstallPath)

(copyfiles 
 (SOURCE "")
 (DEST InstallPath)
 (PATTERN "AmigaTNC#?")
)

( if 

  (askbool
    (PROMPT "Do you want to (re)configure AmigaTNC?")
    (HELP "AmigaTNC needs some configuration files. You can create these "
          "configuration files by hand or with the supplied installation "
          "procedure.\n\n" @askbool-help)
    (DEFAULT 0)
  )

  ( ( set defunit 1)

    ( delete (tackon InstallPath "AmigaTNCUnit#?.cfg") )

    ( while 
    
      ( set unit 
         ( askchoice 
         
           ( PROMPT "Which unit do you want to configure?")
           ( HELP "AmigaTNC supports more than one unit to be run at the"
                  "same time. You can select the unit number you want to"
                  "configure\n\n" @askchoice-help )
           ( CHOICES "Configuration done" "Unit 0" "Unit 1" "Unit 2" "Unit 3")
           ( DEFAULT defunit )

         )          

      ) 

      ( set defunit 0)       

      ( set realunit ( - unit 1) )

      ( set unitfile ( cat "AmigaTNCUnit" realunit ".cfg" ) )

      ( set configfile ( tackon InstallPath UnitFile) )






      ( set driverunit ( cat "DRIVERUNIT " realunit "\n" ))





      ( if (= @user-level 2)



        ( set permanent
           ( askbool

             ( PROMPT "Do you want that the AmigaTNC driver is started when "
                      "you click on the AmigaTNC icon? Otherwise the driver "
                      "is started when you use your packet programme."
                      "Running the driver without the packet radio programme "
                      "enables digipeating.")
             ( HELP @askbool-help)

             ( DEFAULT 1 )

           )
        )

        ( set permanent 1)
      )

       
      ( set permanentdriver (cat "PERMANENTDRIVER " permanent "\n") )


      ( if (= @user-level 2)


        ( set multiport
           ( askbool

             ( PROMPT "Do you want to use the multi port support of AmigaTNC? "
                      "You'll need the multi port support if you own a multi "
                      "port TNC. If your TNC doesn't support multi port you "
                      "can try to use the upper ports for internal loopback. "
                      "Internal loopback is also possible with the modem driver "
                      "on the ports 2-8. NOTE: Some programmes might not support "
                      "the multi port mode of AmigaTNC.")
             ( HELP @askbool-help)
             ( DEFAULT 1 )
           )

        )
        ( set multiport 1)
      )

      (set mport (select multiport "0" "1"))




      ( set modemtype 
         ( askchoice 
         
           ( PROMPT "What type of modem/TNC do you own?")
           ( HELP @askchoice-help)
           ( CHOICES "Baycom compatible modem" "Amiga MiniModem (used in AP)"
                     "KISS TNC" )
           
           ( DEFAULT 0 )

         )          
      ) 

      ( set drivermode ( select modemtype "DRIVERMODE BAYCOMMODEM\n"
                                          "DRIVERMODE BAYCOMAUDIO\n"
                                          "DRIVERMODE KISSTNC\n" ) )
           


      ( if ( <> modemtype 2)
           
           ( 

             (if (patmatch "68000|68010" (database "cpu") )

                 (set defsoftdcd 0)

                 (set defsoftdcd 1)

             )


             ( if (= @user-level 2)


               (set softdcd ( askbool
                                  (PROMPT "Should the software dcd be enabled. This is "
                                          "recommended if you don't have a hardware dcd "
                                          "and own a FAST cpu. Software dcd is a cpu "
                                          "intensive ability of AmigaTNC" )
                                  (HELP @askbool-help)
                                  (DEFAULT defsoftdcd)
                                ))
               (set softdcd defsoftdcd)
             )

             (set softwaredcd (select softdcd "0" "4"))

             (if (= @user-level 2)

               (set excltim ( askbool
                                   (PROMPT "Should the modem driver used in shared mode? "
                                           "You only need this if you want to use more than "
                                           "one modem / TNC at the same time. This mode is "
                                           "experimental. Do you want to use it anyway ?")
                                   (HELP @askbool-help)
                                   (DEFAULT 0)
                                 ))
 
               (set excltim 0 )

             )


             (set exclusivetim (select excltim "1" "0"))

             (set driverlines (cat
                               "MODEMBAUD 1200\n"
                               "SOFTWAREDCD " softwaredcd "\n"
                               "EXCLUSIVETIMER " exclusivetim "\n"
                               "MULTIPORT " mport "\n"
                              ))
           )
           (
  
             (set tncdevice ( askstring
                                (PROMPT "What is the name of your serial interface "
                                        "device. The internal serial interface is "
                                        "named : \"serial.device\"" )
                                (HELP @askstring-help)
                                (DEFAULT "serial.device")
                            ))

             (set tncunit ( asknumber
                             (PROMPT "What is the unit number of this interface? "
                                     "If your interface card supports more than "
                                     "one serial interface you can select on which "
                                     "interface AmigaTNC is used. Default : 0")
                             (HELP @asknumber-help)
                             (DEFAULT 0)              
                          ))
 
             (set tncbaud ( asknumber
                             (PROMPT "Please enter the baud rate of your serial "
                                     "interface of your TNC. This is not the baud "
                                     "rate of the real transmission. In most cases "
                                     "this should be 9600.")
                             (HELP @asknumber-help)
                             (DEFAULT 9600)
                          )) 

             (set initstring ( askchoice
                               (PROMPT "Please select the type of your TNC")
                               (HELP @askchoice-help)
                               (CHOICES "TNC2 with The Firmware"
                                        "TNC2 with TAPR firmware"
                                        "PK232"
                                        "KAM" )
                               (default 0)
                             ))

             (set kissinit ( select initstring 
                             "\\017\\021\\027@K\\013"
                             "\\003KISS ON\\013RESTART\\013"
                             "\\003KISS ON\\013"
                             "INTFACE KISS\\013RESET\\013"
                           ))

             (if (= @user-level 2)

               (set kisstype ( askchoice
                                 (PROMPT "Please select the type of KISS mode")
                                 (HELP @askchoice-help)
                                 (CHOICES "Autodetection"
                                          "KISS only mode"
                                          "SMACK mode"
                                          "Flexnet CRC-KISS" )
                                 (default 0)
                               ))
               (set kisstype 0 )
             )


             (set driverlines ( cat
                                "TNCDEVICE " tncdevice "\n"
                                "TNCUNIT " tncunit "\n"
                                "TNCFLAGS 0\n"
                                "TNCBAUD " tncbaud "\n"
                                "KISSINIT " kissinit "\n"
                                "KISSTYPE " kisstype "\n"
                              ) )
                               
           )


      )



 


      (set mycall (askstring
                    (PROMPT "Please enter your callsign")
                    (HELP @askstring-help)
                    (DEFAULT "NOCALL")
                  ))




      (set tncinit (cat
                    "TNCINIT 0 I " mycall "\n"
                    "TNCINIT 0 U 2 Terminal offline. Pse QRX\n"
                    "TNCINIT 0 K 2\n"
                    "TNCINIT 0 @T2 225\n"
                   ))


      ( textfile
 
        (PROMPT "The configuration file "
                unitfile " will be created now!" )
   
        (HELP "Sorry - no help")        

        (DEST configfile)
       
        (APPEND driverunit)
        (APPEND permanentdriver)
        (APPEND drivermode)
        (APPEND driverlines)        
        (APPEND "BUFFERS 600\n")
        (APPEND tncinit)



      )

  



     
    )   

  )
)

    (
     (set xatc (tackon InstallPath "AmigaTNC") )
 
     (tooltype (DEST xatc) (settooltype "CONFIGFILE") )
     (tooltype (DEST xatc) (settooltype "CONFIGFILE0") )
     (tooltype (DEST xatc) (settooltype "CONFIGFILE1") )
     (tooltype (DEST xatc) (settooltype "CONFIGFILE2") )
     (tooltype (DEST xatc) (settooltype "CONFIGFILE3") )

     ( if (exists (tackon InstallPath "AmigaTNCUnit0.cfg") )
          (tooltype (DEST xatc) (settooltype "CONFIGFILE0" "AmigaTNCUnit0.cfg")))

     ( if (exists (tackon InstallPath "AmigaTNCUnit1.cfg") )
          (tooltype (DEST xatc) (settooltype "CONFIGFILE1" "AmigaTNCUnit1.cfg")))

     ( if (exists (tackon InstallPath "AmigaTNCUnit2.cfg") )
          (tooltype (DEST xatc) (settooltype "CONFIGFILE2" "AmigaTNCUnit2.cfg")))

     ( if (exists (tackon InstallPath "AmigaTNCUnit3.cfg") )
          (tooltype (DEST xatc) (settooltype "CONFIGFILE3" "AmigaTNCUnit3.cfg")))
    )



( if 

  (askbool
    (PROMPT "Do you want to setup your packet radio programme?")
    (HELP "This installer script supports the automatic setup of some "
          "packet radio programmes\n\n" @askbool-help)
    (DEFAULT 0)
  )

  ( 



    ( while 
    
      ( set prprogram 
         ( askchoice 
         
           ( PROMPT "Which packet radio programme do you want to configure?")
           ( HELP @askchoice-help)
           ( CHOICES "Configuration done" "AHP4" "AmiCom" "ProfiPacket")
           ( DEFAULT 0 )

         )          

      ) 


      ( set prpath
         ( askdir
           ( PROMPT "Where is this packet programme installed?")
           ( HELP "The installer needs to know the location of the "
                  "selected packet radio programme to modify its "
                  "configuration\n\n"@askdir-help)
           ( DEFAULT "sys:")
         )

      )


      ( if (= prprogram 1)

        ;AHP4



        (


         ( if (exists (tackon InstallPath "AmigaTNCUnit3.cfg") )

           (set aconfig "AmigaTNCUnit3.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit2.cfg") )

           (set aconfig "AmigaTNCUnit2.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit1.cfg") )

           (set aconfig "AmigaTNCUnit1.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit0.cfg") )

           (set aconfig "AmigaTNCUnit0.cfg") )

         (set acon (tackon InstallPath aconfig) )


         ( set xrun (cat "Inst_GetConfig <\"" acon "\""))


         ( if (<> 0 (run xrun (safe)))
           (abort "Error getting config!"  )
         )

         ( set xunit (getenv "AmigaTNCUnit") )
         ( set xcall (getenv "AmigaTNCCall") )


         (set ahp4 (tackon prpath "AHP"))
         (set ahp4_40 (tackon prpath "AHP-040"))

         (if (exists ahp4)

              (
               (tooltype (dest AHP4 ) (settooltype "DEVICE" "amigatnc.device" ))
               (tooltype (dest AHP4 ) (settooltype "UNIT" xunit ))
               (tooltype (dest AHP4 ) (settooltype "DEVICE2" "amigatnc.device" ))
               (tooltype (dest AHP4 ) (settooltype "UNIT2" xunit ))
               (tooltype (dest AHP4 ) (settooltype "TNC0" "0"))
               (tooltype (dest AHP4 ) (settooltype "TNC1" "0"))
               (tooltype (dest AHP4 ) (settooltype "TNC2" "10"))
               (tooltype (dest AHP4 ) (settooltype "MYCALL" xcall))
              )


         )


         (if (exists ahp4_40)

              (
               (tooltype (dest AHP4_40 ) (settooltype "DEVICE" "amigatnc.device" ))
               (tooltype (dest AHP4_40 ) (settooltype "UNIT" xunit ))
               (tooltype (dest AHP4_40 ) (settooltype "DEVICE2" "amigatnc.device" ))
               (tooltype (dest AHP4_40 ) (settooltype "UNIT2" xunit ))
               (tooltype (dest AHP4_40 ) (settooltype "TNC0" "0"))
               (tooltype (dest AHP4_40 ) (settooltype "TNC1" "0"))
               (tooltype (dest AHP4_40 ) (settooltype "TNC2" "10"))
               (tooltype (dest AHP4_40 ) (settooltype "MYCALL" xcall))
              )


         )


         (message "AHP is now configured for AmigaTNC!")

        )

      )

      ( if (= prprogram 3)
        (
         ;ProfiPacket

         ( set ppprefs (tackon prpath "data/ProfiPacket.prefs"))

         ( set xrun (cat "Inst_ConfigProfiPacket " ppprefs " - amigatnc.device "))

         ( if (<> 0 (run xrun (safe)))
         (abort "Error clearing config!"  ) 
         )


         ( if (exists (tackon InstallPath "AmigaTNCUnit0.cfg") )

           (
             (set acon (tackon InstallPath "AmigaTNCUnit0.cfg"))

             ( set xrun (cat "Inst_GetConfig <\"" acon "\""))

          
             ( if (<> 0 (run xrun (safe)))
             (abort "Error getting config!"  ) 
             )

             ( set xunit (getenv "AmigaTNCUnit") )
             ( set xcall (getenv "AmigaTNCCall") )


             ( set xrun (cat "Inst_ConfigProfiPacket " ppprefs " + amigatnc.device "
                         xunit " AmigaTNC_1 " xcall))

             ( if (<> 0 (run xrun (safe)))
             (abort "Error setting config!"  ) 
             )
             
           )
 
         )

         ( if (exists (tackon InstallPath "AmigaTNCUnit1.cfg") )

           (
             (set acon (tackon InstallPath "AmigaTNCUnit1.cfg"))

             ( set xrun (cat "Inst_GetConfig <\"" acon "\""))

          
             ( if (<> 0 (run xrun (safe)))
             (abort "Error getting config!"  ) 
             )

             ( set xunit (getenv "AmigaTNCUnit") )
             ( set xcall (getenv "AmigaTNCCall") )


             ( set xrun (cat "Inst_ConfigProfiPacket " ppprefs " + amigatnc.device "
                         xunit " AmigaTNC_2 " xcall))

             ( if (<> 0 (run xrun (safe)))
             (abort "Error setting config!"  ) 
             )
             
           )
 
         )
         ( if (exists (tackon InstallPath "AmigaTNCUnit2.cfg") )

           (
             (set acon (tackon InstallPath "AmigaTNCUnit2.cfg"))

             ( set xrun (cat "Inst_GetConfig <\"" acon "\""))

          
             ( if (<> 0 (run xrun (safe)))
             (abort "Error getting config!"  ) 
             )

             ( set xunit (getenv "AmigaTNCUnit") )
             ( set xcall (getenv "AmigaTNCCall") )


             ( set xrun (cat "Inst_ConfigProfiPacket " ppprefs " + amigatnc.device "
                         xunit " AmigaTNC_3 " xcall))

             ( if (<> 0 (run xrun (safe)))
             (abort "Error setting config!"  ) 
             )
             
           )
 
         )
         ( if (exists (tackon InstallPath "AmigaTNCUnit3.cfg") )

           (
             (set acon (tackon InstallPath "AmigaTNCUnit3.cfg"))

             ( set xrun (cat "Inst_GetConfig <\"" acon "\""))

          
             ( if (<> 0 (run xrun (safe)))
             (abort "Error getting config!"  ) 
             )

             ( set xunit (getenv "AmigaTNCUnit") )
             ( set xcall (getenv "AmigaTNCCall") )


             ( set xrun (cat "Inst_ConfigProfiPacket " ppprefs " + amigatnc.device "
                         xunit " AmigaTNC_4 " xcall))

             ( if (<> 0 (run xrun (safe)))
             (abort "Error setting config!"  ) 
             )
             
           )
 
         )

         (message "ProfiPacket is now configured for AmigaTNC!")

        )

      ) 

      ( if (= prprogram 2) 
        (

         ;AmiCom


         ( if (exists (tackon InstallPath "AmigaTNCUnit3.cfg") )

           (set aconfig "AmigaTNCUnit3.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit2.cfg") )

           (set aconfig "AmigaTNCUnit2.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit1.cfg") )

           (set aconfig "AmigaTNCUnit1.cfg") )

         ( if (exists (tackon InstallPath "AmigaTNCUnit0.cfg") )

           (set aconfig "AmigaTNCUnit0.cfg") )

         (set acon (tackon InstallPath aconfig) )


         ( set xrun (cat "Inst_GetConfig <\"" acon "\""))
          
         ( if (<> 0 (run xrun (safe)))
           (abort "Error getting config!"  ) 
         )

         ( set xunit (getenv "AmigaTNCUnit") )
         ( set xcall (getenv "AmigaTNCCall") )

         ( set newconfig (tackon prpath "konfig.ac") )
         ( set oldconfig (tackon prpath "konfig.ac.old") )

         ( delete oldconfig)
         ( rename newconfig oldconfig)

         ( set xrun (cat "Inst_ConfigAmicom <\"" oldconfig "\" >\"" newconfig 
                         "\" " xunit " " xcall) )

         ( if (<> 0 (run xrun ))
           (abort "Cannot modify configuration!")
         )
         

         (message "Amicom is now configured for AmigaTNC!")
        )
      )
           
    )

  )

)



