; Power Computing Power-Lan install script 
; for PCMCIA, X-Surf and Ariadne2 ethernet cards
; -  A1200, A2000, A3000 and A4000  -
; $VER: Install_Power-LAN 2.0.0 (07.05.00)

(set scr (pathonly @icon))

(set scheda
   (askchoice (prompt "Which of the following two cards are you using to network this Amiga")
              (help "Click on the network card installed in your Amiga")
              (choices "PCMCIA" "Ariadne II" "X-Surf")
              (default 0)
   )
)

(if (= scheda 0)
	(
		(set intface "cnet0")
		(set cmd (tackon scr "devs/cnet.device"))
		(set cmd2 "devs:networks")
		(copylib (source cmd)
		         (dest cmd2)
		)
	)
)

(if (= scheda 1)
	(
		(set intface "ariadne_ii0")
		(set cmd (tackon scr "devs/ariadne_ii.device"))
		(set cmd2 "devs:networks")
		(copylib (source cmd)
		         (dest cmd2)
		)
	)
)

(if (= scheda 2) (set intface "xsurf"))

(set processore 0)

(set nomec	(database "cpu"))
(set nomef	(database "fpu"))

(if (= nomec "68000")	(set processore 0))
(if (= nomec "68010")	(set processore 0))
(if (= nomec "68020")	(set processore 2))
(if (= nomec "68030")	(set processore 2))
(if (= nomec "68040")	(set processore 4))
(if (= nomec "68060")	(set processore 6))

(if (<> nomef "NOFPU") (set processore (+ processore 1)))

(if (= processore 0)
	(
		(set cmd (tackon scr "libs/ixemul-000.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
			(dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-000.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
			(dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-000.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
					(dest cmd2)
					(newname "x-surf.device")
				)
			)
		)

   )
)

(if (= processore 1)
	(
		(set cmd (tackon scr "libs/ixemul-000.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
         (dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-000.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
         (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-000.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		      	(dest cmd2)
					(newname "x-surf.device")
				)
			)
		)
   )
)

(if (= processore 2)
	(
		(set cmd (tackon scr "libs/ixemul-020.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
			(dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-020.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-020.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		        (dest cmd2)
				  (newname "x-surf.device")
				)
			)
		)
   )
)

(if (= processore 3)
	(
		(set cmd (tackon scr "libs/ixemul-020-fpu.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-020.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-020.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		         (dest cmd2)
			  		(newname "x-surf.device")
				)
			)
		)
   )
)

(if (= processore 4)
	(
		(set cmd (tackon scr "libs/ixemul-040.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-040.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
	      (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-040.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		        (dest cmd2)
				  (newname "x-surf.device")
				)
			)
		)
   )
)

(if (= processore 5)
   (
		(set cmd (tackon scr "libs/ixemul-040-fpu.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-040.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-040.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		   	   (dest cmd2)
					(newname "x-surf.device")
				)
			)
		)
   )
)

(if (OR (= processore 6)(= processore 7))
	(
		(set cmd (tackon scr "libs/ixemul-060-fpu.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixemul.library")
		)
		(set cmd (tackon scr "libs/ixnet-060.library"))
		(set cmd2 "sys:libs")
		(copylib (source cmd)
		   (dest cmd2)
         (newname "ixnet.library")
		)
		(if (= scheda 2)
			(
				(set cmd (tackon scr "devs/x-surf-040.device"))
				(set cmd2 "devs:networks")
				(copylib (source cmd)
		   	   (dest cmd2)
					(newname "x-surf.device")
				)
			)
		)
   )
)

(set cmd (tackon scr "SMB-Handler"))
(set cmd2 "sys:l")
(copylib (source cmd)
         (dest cmd2)
)

(set cmd (tackon scr "netfs-Handler"))
(set cmd2 "sys:l")
(copylib (source cmd)
         (dest cmd2)
)

(set Install_DEST
   (askdir
      (prompt "Select the location where the destination drawer - AmiTCP-3.0b2 - should be created.\n\nMake sure that you have at least 3.5MB free!")
      (help "Choose the disk, partition or directory, where the AmiTCP-3.0b2 drawer should be created.\n\n All the files necessary for the Network will be then copied into it.\n\nPlease note that you will need at least 3.5MB free on the disk/partition that you choose!")
      (default "SYS:")
   )
)

(set cmd (tackon scr "AmiTCP-3.0b2"))
(set tcppath (tackon Install_DEST "AmiTCP-3.0b2"))
(set cmd2 tcppath)
(copyfiles (source cmd)
           (dest cmd2)
	        (all)
	        (infos)
)

(set promptstr "Please insert the IP number of this computer.") 
(set ipnum
	(askstring 
		(prompt promptstr)
   	(help "You need to insert the IP number of this computer.") 
   	(default "192.168.0.")
	)
)

(set promptstr "Insert the name of this computer.")
(set nomeip
	(askstring 
   	(prompt promptstr)
      (help "You need to insert the name of this computer.") 
      (default "Amiga-01")
	)
)

(set thisIPname nomeip)
(set promptstr "Insert the name of the workgroup (or domain).")
(set nomedom
	(askstring 
   	(prompt promptstr)
      (help "You need to insert the name of the workgroup to which this computer is connected.")
      (default "Power-LAN")
   )
)

(set ipinfo (cat "HOST "ipnum " " nomeip "\n"))
(set dominfo (cat "DOMAIN " nomedom "\n"))
(textfile
   (dest (tackon tcppath "db/netdb-myhost"))
   (append ipinfo)
   (append dominfo)
)

(set lin1 (cat "   workgroup = " nomedom "\n"))
(set lin2 (cat "   server string = " nomeip "\n"))
(set lin3 (cat "   netbios name = " nomeip "\n"))
(set lin4 (cat "   interfaces = " ipnum "/255.255.255.0\n"))
(textfile
	(dest (tackon tcppath "samba/lib/smb.conf"))
	(include (tackon scr "smb.conf0"))
	(append lin1)
	(append lin2)
	(append lin3)
	(append lin4)
	(include (tackon scr "smb.conf1"))
)

(copyfiles
	(source (tackon tcppath "db/hosts"))
   (dest "ram:")
)
(set ipinfo (cat ipnum " " nomeip "\n"))
(textfile
   (dest (tackon tcppath "db/hosts"))
   (include "RAM:hosts")
   (append ipinfo)
)
   
(set lin1 (cat "assign AmiTCP: \"" tcppath "\"\npath AmiTCP:bin add\n\n"))
(set lin2 (cat "run <>nil: AmiTCP:bin/ifconfig " intface " " ipnum " netmask 255.255.255.0\n"))
(set lin2a (cat "run <>nil: AmiTCP:bin/route add " nomeip " localhost\n"))
(textfile
   (dest "s:Start-LAN")
	(append lin1)
   (include (tackon scr "Start-LAN0"))
   (append lin2)
   (append lin2a)
   (include (tackon scr "Start-LAN1"))
)   

(copyfiles
	(source (tackon scr "xic.inf"))
	(dest "s:")
	(newname "Start-LAN.info")
)

(if (> (exists ("sys:.backdrop")) 0)
	(
		(copyfiles
			(source "sys:.backdrop")
			(dest "ram:")
			(newname "back")
		)
		(textfile
   		(dest "sys:.backdrop")
   		(include "RAM:back")
   		(append ":s/Start-LAN\n")
		)
		(delete "ram:back")
	)
	(
		(textfile
   		(dest "sys:.backdrop")
   		(append ":s/Start-LAN\n")
		)
	)
)

(makedir "sys:MountFiles")
(copyfiles
	(source (tackon scr "mountfiles.inf"))
	(dest "sys:")
	(newname "MountFiles.info")
)
(tooltype (dest "sys:mountfiles") (noposition))
(copyfiles
	(source "sys:.backdrop")
	(dest "ram:")
	(newname "back")
)
(textfile
   (dest "sys:.backdrop")
   (include "RAM:back")
   (append ":MountFiles\n")
)
(delete "ram:back")

(set totips
	(asknumber
		(prompt "How many other computers are part of your network, (excluding this one)?")
		(help "You need to tell exactly how many other computers are connected to the network, including any Amigas or PCs, but excluding this computer.\n\nHave ready the IP number and name for each of them.")
		(default 1)
	)
)

(set currip 1)
(while (<= currip totips) 
	(
	   (set promptstr (cat "Please insert the IP number for computer n. " currip "\n\nThis number is unique for the computer throughout the whole network."))
	   (set ipnum (askstring 
					  (prompt promptstr)
		           (help "You need to insert the IP number for any computer connected to the network.") 
		           (default "192.168.0.")
                 )
      )
		(set isPC (askchoice 
      		  	 	(prompt "Is this computer a PC or an AMIGA?")
        			 	(help "The Network startup file needs to be set accordingly.")
					 	(choices "PC" "Amiga")
        			 	(default 0)
      			 )
		)
		(if (= isPC 0) (set defcomputer "PC-") (set defcomputer "Amiga-"))
	   (set promptstr (cat "Insert the name of the computer with IP n. " ipnum "\n\nThis name is unique for the computer throughout the whole network."))
	   (set nomeip (askstring 
        	         (prompt promptstr)
		          	(help "You need to insert the name for any computer connected to the network.") 
		          	(default defcomputer)
                  )
      )
      (copyfiles (source (tackon tcppath "db/hosts"))
                 (dest "ram:")
      )
      (set ipinfo (cat ipnum " " nomeip "\n"))
      (textfile
         (dest (tackon tcppath "db/hosts"))
         (include "RAM:hosts")
         (append ipinfo)
      )
		(if (= isPC 0)
			(
				(set tlin1
					(askstring 
						(prompt "Please insert the name of the unit on the PC that can be shared whit this computer.")
			   	   (help "You need to insert the name as given to the shared unit or directory (on the PC).")
      	  	   )
    			)
				(set lin1 (cat "\\" tlin1))
				(set pcuser
					(askstring 
						(prompt "Please insert the User Name as set on this PC.")
			   	   (help "The user name is the name that has been set on the PC at installation.")
      	  	   )
    			)
				(set pwordset
					(askchoice
						(prompt "Have you set a password linked to the User Name?")
						(help "If every time you start the PC, you are asked for a password, answer yes. You will be asked to input the password.")
						(choices "No" "Yes")
						(default 0)
					)
				)
				(if (= pwordset 1)
					(
						(set pword
							(askstring 
								(prompt "Please insert the password.")
				   	  		(help "If te PC asks for a password, you need to insert it now, otherwise this Amiga will not capable to share files with the PC.")
							)
      	  		   )
						(set tlin (cat " P=" pword))
					)
					(
						(set tlin "")
					)

				)
				(set lin3 (cat pcuser " " tlin " DN=" nomeip) )
			)
			(
				(set lin1 (cat "\\ALL"))
				(set lin3 "pcguest")
			)
		)
		(set lin2 (cat " MH=" thisIPname " W=" nomedom " U="))
      (textfile
         (dest (cat "sys:mountfiles/" nomeip ))
         (append "Handler   = L:SMB-Handler\nStacksize = 40000\nPriority  = 10\nGlobVec   = -1\nMount     = 1\nStartUp   = \"C=\\\\")
			(append nomeip)
			(append lin1)
			(append lin2)
			(append lin3)
			(append "\"")
      )
		(set nomeicona (cat nomeip ".info"))
		(set cmd (tackon scr "mount.inf"))
		(set cmd2 "sys:mountfiles")
		(copyfiles
			(source cmd )
			(dest cmd2)
			(newname nomeicona)
		)
		(tooltype (dest (tackon "sys:mountfiles" nomeip)) (noposition))
	   (set currip (+ currip 1))
	   (delete "ram:hosts")
	)
)

(set #reboot
(cat "Installation completed!"
     "\n\nThank you for buying from us."
     "\n\n\nSelect the \"Proceed\" gadget to reboot your Amiga."
     "\n\n\nIf you wish to modify manually your setup, please do so after the reboot."
))

(message #reboot)
(run "Reboot")
