; Script to install zOOrANDOMIZER v1.00
; written for your pleasure by One / Genetic 1995
; do NOT change anything in this script..


(set zoo_disk   "zOOiNSTALL:")
(set zoo_temp   "ram:t/")
(set zoo_dir    "bbs:utils/")
(set zoo_linez  "linez")
(set zoo_door   "bbs:doors/")
(set zoo_cmddir "bbs:commands/syscmd/")

; first test if the Utils: assign has been made

(complete 0)

(if (= (getassign "utils" "a" ) "")
   (
      (startup "zOOrANDOMIZER"
         (prompt "The utils: assignment is missing !\n\n"
                 "This assign is nessecary for the zOOrANDOMIZER to work.\n\n"
                 "Add Utils: assignment to s:user-startup?")  
         (help   "The Utils: assignment should have been made by AmiExpress when you installed it.\n\n"
                 @startup-help
                 )
         (command ("Assign Utils: \"%s\"" zoo_dir))
       )
   	(makeassign "Utils" zoo_dir (safe))
      (message "\nAssign has been made and added to your user-startup.\n")
   )
)

(set @default-dest zoo_dir)

; create linez directory

(makedir ("%s%s"zoo_dir zoo_linez))

(complete 4)

(set zoo_choice
	(askchoice
		(prompt "The linez directory is created.\n\n"
              "Do you want to install the example linez-files ?\nHighly recommended !\n")
		(help "In the linez directory are the linez files with the different quotez. "
            "They are provided with a few comments so you should understand what's needed in such a file.\n\n"
            "Install them if you want to check them out and/or read the docfile.")
		(choices "Install them !" "No way !")
		(default "0")
	)
)

(copyfiles
	(prompt "")
	(help "")
	(source ("%sc/lzx" zoo_disk))
	(dest "ram:")
)

(complete 21)

; copy zr.lzx to ram:

(copyfiles
	(prompt "")
	(help "")
	(source ("%sc/zr.lzx" zoo_disk))
	(dest "ram:")
)

(complete 33)

; unpack lzx file to ram:t/

(working "Unpacking zr.lzx")
(set lzrc	
   (run ("RAM:lzx -qfw e %s %s" "ram:zr.lzx" zoo_temp))
)
(if (<> lzrc 0)
   (message	("Error decompressing %s's files into the %s directory." "ram:zr.lzx" zoo_temp)
		       "\n")
)

; delete ram:zr.lzx

(delete "ram:lzx")
(delete "ram:zr.lzx")

(complete 43)

(copyfiles
	(prompt "Now copying zOOrANDOMIZER itself...\n")
	(help "")
	(source zoo_temp)
   (pattern "zOOrANDOMIZER#?")
	(dest zoo_dir)
)

(complete 47)

(copyfiles
	(prompt "")
	(help "")
	(source ("%szr.config" zoo_temp))
	(dest zoo_dir)
)

(complete 49)

(if (= zoo_choice 0)
   (copyfiles
      (prompt"Now copying linez files...\n")
      (help "")
      (source zoo_temp)
      (dest ("%s%s" zoo_dir zoo_linez))
      (pattern "#?.zr")
   )
)

(complete 52)

; delete temporal files

(delete ("%s1.zr" zoo_temp))
(delete ("%s2.zr" zoo_temp))
(delete ("%s3.zr" zoo_temp))
(delete ("%s4.zr" zoo_temp))
(delete ("%s5.zr" zoo_temp))
(delete ("%szOOrANDOMIZER" zoo_temp))
(delete ("%szOOrANDOMIZER.info" zoo_temp))
(delete ("%szr.config" zoo_temp))

(complete 55)

; check logoff script & add zOOrANDOMIZER

(set zoo_scdir
   (askdir
      (prompt "Please select the directory where your logoff.script is located. If you don't have one "
              "select/create the directory where you want it to be installed.")
      (help "To get the whole show running you should have a logoff script named logoff.script (if you use another name, " 
             "then add \"Utils:zOOrANDOMIZER\" in your logoff script manually !) and an icon called "
            "LOGOFF in the \"bbs:commands/syscmd/\" directory.\n\n"
            "That icon should contain the following tooltypes to find your logoff script:\n\n"
            "ACCESS=10\n"
            "LOCATION=doors:Scripts/LogOff.script\n"
            "MULTINODE=YES\n"
            "TYPE=SIM\n"
            "STACK=4096\n\n"
            "You may want to install this icon too and change it to your own paths and needs.\n\n"
            @askdir-help)
      (default zoo_door)
   )
)

(complete 67)

(if (= (exists ("%s/logoff.script" zoo_scdir)) 1)
   (
      (textfile
         (prompt "Do you want to add Utils:zOOrANDOMIZER to your logoff.script ? \n")
         (help "You should add the zOOrANDOMIZER in your logoff script to make sure that after every logoff "
               "the output file is updated with a new quote for the next user !")
         (dest ("%slogoff.script" zoo_temp))
         (include ("%s/logoff.script" zoo_scdir))
         (append "\n;BEGIN zr\n")
         (append "Utils:zOOrANDOMIZER\n")
         (append ";END  zr\n")
         (confirm)
      )
      (protect ("%slogoff.script" zoo_temp) 64) ;scriptfile !!
      (complete 83)
      (if (= (exists ("%slogoff.script" zoo_temp)) 1)
         (
            (if (= (rename ("%s/logoff.script" zoo_scdir) ("%s/logoff.script_old" zoo_scdir)) 0)
               (abort "There's already a file called: logoff.script_old !\n Get rid of it first !!\n")
            )
            (copyfiles
               (source ("%slogoff.script" zoo_temp))
               (dest ("%s/" zoo_scdir))
            )
            (delete ("%slogoff.script" zoo_temp))
            (message "Your logoff.script has been updated.\n\nYour original script is renamed to logoff.script_old.")
            (complete 92)
         )
      )         
   )
   (
      (if (= (exists zoo_scdir) 0)
         (abort ("%s does NOT exists !!" zoo_scdir))
         (
            (textfile
               (prompt "Now is a good time to create your logoff.script ! \n\n"
                       "If you don't the zOOrANDOMIZER won't create different quotes.\n Try HELP for sum more info ! ")
               (help "To get the whole show running you should have a logoff script named logoff.script " 
                     "and an icon called LOGOFF in the \"bbs:commands/syscmd/\" directory.\n\n"
                     "That icon should contain the following tooltypes to find your logoff script:\n\n"
                     "ACCESS=10\n"
                     "LOCATION=doors:Scripts/LogOff.script\n"
                     "MULTINODE=YES\n"
                     "TYPE=SIM\n"
                     "STACK=4096\n\n"
                     "You may want to install this icon too and change it to your own paths and needs.\n\n"
                     "You should add the zOOrANDOMIZER in your logoff script to make sure that after every logoff "
                     "the output file is updated with a new quote for the next user !\n\n"
                     "Create this script now ! \n\n"
                     "Read the /X doc for more information about the logoff.script, icons and tooltypes !")
               (dest ("%slogoff.script" zoo_scdir))
               (append ";BEGIN zr\n")
               (append "Utils:zOOrANDOMIZER\n")
               (append ";END  zr\n")
               (confirm)
            )
            (protect ("%s/logoff.script" zoo_scdir) 64) ;scriptfile !!
            (complete 84)
            (if (= (exists "bbs:commands/syscmd/logoff.info") 0)
               (
                  (copyfiles
                     (prompt "Do you want to install the LOGOFF icon too ?\n"
                             "This icon executes your logoff script.")
                     (help "To get the whole show running you should have an icon called LOGOFF in the \"bbs:commands/syscmd/\" directory.\n\n"
                           "That icon should contain the following tooltypes to find and execute your logoff script:\n\n"
                           "ACCESS=10\n"
                           "LOCATION=doors:Scripts/LogOff.script\n"
                           "MULTINODE=YES\n"
                           "TYPE=SIM\n"
                           "STACK=4096\n\n"
                           "You may want to install this icon too and change it to your own paths and needs.\n\n"
                           "You should add the zOOrANDOMIZER in your logoff script to make sure that after every logoff "
                           "the output file is updated with a new quote for the next user !\n\n"
                           "Install this icon now ! \n\n"
                           "Read the /X doc for more information about the logoff.script, icons and tooltypes !")
                     (source ("%sLOGOFF.info" zoo_temp))
                     (dest zoo_cmddir)
                  )
                  (complete 95)
               )
            )
         )
      )   
   )
)

(delete ("%sLOGOFF.info" zoo_temp))
(complete 99)

; say goodbye

(message "Please notice:\nthis is zOOrANDOMIZER version 1.00 ! \n\n"
         "Read the docfile for more infos!\n"
         "Contact me for any reason at zOOROPA !\n 053-328902 > 24h a day, 28k8! (V.34 & V.FC).\n"
         "\nmzzl !\n\noNE / gENETIC / sYSO zOOROPA BBS\n"
)

(complete 100)

(exit)
