;------------------------------------------------------------------------
;
; Python Installation script for Python version 2.0
;
; Copyright © Irmen de Jong.
; V2.7 (28-oct-2000)
;

(set OSVersion          (/ (getversion) 65536))

(set cpu (database "cpu"))

(set @app-name "Python 2.0")

(set #source-dir (pathonly @icon) )

;
; ENGLISH STRINGS
;
(set #welcomemsg "Installation of Python 2.0\n\nA new directory (with icon) will be created, in which the program is installed.\n\n(note: it is advised to leave a previous Python: assign active with this installation)")
(set #osmsg "ARGH! You have an obsolete Kickstart version!\n\nPython only works on Kickstart 2.04 or higher. Upgrade to 3.1!")
(set #nopretendmsg "Can only install for real.")
(set #updatemsg "This will install a fresh copy of Python 2.0.\nIf you already have installed the previous version, you might consider running the Update_Previous script instead.\nIf so, abort this installation now.")
(set #oldversionmsg "\nDo you have a previous installed version, and if so, do you want to delete that (fully)?\nWARNING: If you select 'yes', the full contents of the directory of the old version will be deleted!\n\n\n(If you have a previous version installed, and you don't delete it, you must install this new version to a new directory)")
(set #oldversionhelp "Yes: delete all files from old version. You can then install this new version in the place of the old one, otherwise, you'll have to install this version in a new directory.\n\nIf you have any files in the directory of the old version that you want to keep, SELECT 'NO'!")
(set #whereisold "Where is your previous release installed?")
(set #deleteoldmsg "\nWill now delete old version. Last chance to keep old data!")
(set #willdeletemsg "\nWill now delete drawer\n\n%s\n\ncompletely.")
(set #willdeletehelp "Last chance to keep old files: click 'Abort'!")
(set #deleteworkmsg "Deleting %s...")
(set #oldversion "old version")
(set #deleteinstall "Do you want to delete the installation directory?\n\n(it is no longer needed)")
(set #installationfiles "installation files")
(set #whereprompt "Were must Python be installed? Most of the files don't have to be copied, if you accept the offered default.")
(set #wherehelp "  Here you can specify the location where to install Python.\n  Installation can be made on-place. This is recommended if you have already unarchived the Python archive to its final location. In this case most of the files are left where they are. Only necessary files are moved to different positions.\n  If you choose another location, a new subdirectory will be created (with icon) in which the program is installed.")
(set #currentmsg "\nInstalling Python to\n\n%s\n\n(the current place)")
(set #existingerr "Can't install into existing directory!")
(set #oldstillexistserr "Couldn't fully remove old drawer! (is it still in use?)")
(set #newmsg "\nInstalling Python to\n\n%s\n\n(a new directory)" )
(set #whichprompt "Which version of the program should be installed?")
(set #whichhelp "Choose the version which matches your CPU/FPU configuration best.\nRead the README file for info on how to obtain other versions.\n\n")
(set #startupprompt "The following commands will be added to your \"S:User-Startup\" file (You'll need them to run Python):\n\nASSIGN Python: %s\nPATH Python: ADD\n")
(set #readmemsg (cat "Please read shown information...\n\n\n(It is also wise to read the README file)"))
(set #abort "Abort")
(set #proceed "Proceed")
(set #endmsg "\nPython 2.0 is now installed!\n\nIf you're using NewIcons, take a look in the Icons directory. NewIcon versions of the icons are available there.")
(set #nexttoprev "You seem to have a previous version of Python already installed. If that is version 1.6 or earlier, you can install this new version 2.0 NEXT TO the old one. Do you want to do that?")
(set #nexttoprev_help "If you install this version NEXT TO your previous version, you can use both at the same time.")
(set #nexttoprev_yes "Yes, next to previous")
(set #nexttoprev_no "No, standalone")
(set #installnextto_done "The new version ('Python20') has been installed next to the previous one, which remains available as 'Python'. Additional new files can be found in the 'Python:Python-2.0' subdirectory.")
;
; NEDERLANDSE STRINGS
;
(if (= @language "nederlands")
(
(set #welcomemsg "Installatie van Python 2.0\n\nEr wordt een nieuwe lade (met ikoon) aangemaakt, waarin het programma wordt geïnstalleerd.\n\n(opmerking: het is aan te raden een vorige Python: assign te laten bestaan voor deze installatie)")
(set #osmsg "ARGH! U heeft een verouderde Kickstart versie!\n\nPython werkt alleen op Kickstart 2.04 of nieuwer. Upgrade naar 3.1!")
(set #nopretendmsg "Kan alleen echte installatie uitvoeren.")
(set #updatemsg "Er zal een nieuwe installatie van Python 2.0 plaatsvinden.\nAls u al een vorige versie heeft geïnstalleerd, is het aan te raden om het Update_Previous script te gebruiken inplaats van dit installatieprogramma.\nAls u dat wilt, moet u nu deze installatie afbreken.")
(set #oldversionmsg "\nHeeft u een vorige versie geïnstalleerd, en zo ja, wilt u deze dan (in zijn geheel) verwijderen?\nWAARSCHUWING: als u 'ja' kiest, wordt de complete inhoud van de lade van de oude versie gewist!\n\n\n(Als u een vorige versie geïnstalleerd heeft, en deze niet verwijdert, moet u de nieuwe versie in een nieuwe lade installeren)")
(set #oldversionhelp "Ja: verwijder alle files van de oude versie. U kunt dan deze nieuwe versie op de plaats van de oude installeren, anders moet u dat in een nieuwe lade doen.\n\nAls u files heeft in de lade van de oude versie die u wilt bewaren, KIES DAN 'NEE'!")
(set #whereisold "Waar is uw vorige versie geïnstalleerd?")
(set #deleteoldmsg "\nOude versie wordt nu verwijderd. Laatste kans om oude files te bewaren!")
(set #willdeletemsg "\nDe lade\n\n%s\n\nwordt in zijn geheel verwijderd.")
(set #willdeletehelp "Laatste kans om oude files te bewaren: klik 'Stop'!")
(set #deleteworkmsg "%s wordt verwijderd...")
(set #oldversion "Oude versie")
(set #deleteinstall "Wilt u de installatie-lade verwijderen?\n\n(die is niet langer nodig)")
(set #installationfiles "Installatie files")
(set #whereprompt "Waar moet Python geïnstalleerd worden? De meeste files hoeven niet gekopiëerd te worden, als u de standaard keuze accepteert.")
(set #wherehelp "  Hier kunt u de lokatie van Python opgeven.\n  De installatie kan ter plekke plaatsvinden. Dit is aanbevolen als u de Python archive al in de juiste plaats heeft uitgepakt. In dit geval worden de meeste files met rust gelaten. Slechts een paar files worden naar hun benodigde lokatie gekopiëerd.\n  Als u een andere lokatie kiest, wordt een nieuwe lade (met ikoon) aangemaakt, waarin Python wordt geïnstalleerd.")
(set #currentmsg "\nInstalleren van Python in\n\n%s\n\n(de huidige plaats)")
(set #existingerr "Kan niet in bestaande lade installeren!")
(set #oldstillexistserr "Kan oude lade niet volledig verwijderen! (wordt hij nog gebruikt?)")
(set #newmsg "\nPython wordt geïnstalleerd in\n\n%s\n\n(een nieuwe lade)" )
(set #whichprompt "Welke versie van het programma moet geïnstalleerd worden?")
(set #whichhelp "Kies de versie die het beste bij uw CPU/FPU configuratie past.\nLees het README bestand voor informatie over hoe andere versies te verkrijgen.\n\n")
(set #startupprompt "De volgende commando's zullen aan uw \"S:User-Startup\" bestand worden toegevoegd (ze zijn nodig om Python te kunnen gebruiken):\n\nASSIGN Python: %s\nPATH Python: ADD\n")
(set #readmemsg (cat "Leest u AUB de getoonde informatie...\n\n\n(Het is ook verstandig om de README file te lezen)"))
(set #abort "Stop")
(set #proceed "Ga verder")
(set #endmsg "\nPython 2.0 is nu geïnstalleerd!\n\nAls u NewIcons gebruikt, kijk dan eens in de Icons directory. Hier zijn NewIcon versies van de icons beschikbaar.")
(set #nexttoprev "U heeft waarschijnlijk al een vorige versie van Python geïstalleerd. Als dat versie 1.6 of eerder is, kunt u deze versie 2.0 ERBIJ zetten. Wilt u dat?")
(set #nexttoprev_help "Als u deze nieuwe versie BIJ de oude installeert, kunt u de nieuwe en de oude tegelijkertijd blijven gebruiken.")
(set #nexttoprev_yes "Ja, ERBIJ zetten")
(set #nexttoprev_no "Nee, los installeren")
(set #installnextto_done "De nieuwe versie ('Python20') is geïnstalleerd naast de vorige versie, die nog steeds ongewijzigd aan te roepen is d.m.v. 'Python'. Overige nieuwe bestanden zijn te vinden in de 'Python:Python-2.0' subdirectory.")
)
)

;------------------------------------------------------------------------
;;;;
;;;; Subroutines follow below:
;;;;

;;;;
;;;; Check if OS version is good enough.
;;;;
(procedure checkKick
 (if (< OSVersion 37)
    (message #osmsg)
 )
)

;;;;
;;;; Find out which pager to use ($PAGER or sys:utilities/multiview)
;;;;
(procedure installPager
 (set pager-cmd
   (if (exists "ENV:PAGER" (noreq)) (getenv "PAGER") ("SYS:Utilities/Multiview")
   )
 )
)

;;;;
;;;; Ask user if she wants to delete an old version.
;;;;
(procedure removeOldversion
(if (askbool 
	(prompt #oldversionmsg)
	(help #oldversionhelp)
	)
	(
		(set oldreleasepath "Python:")
		(set oldreleasepath (expandpath
		    (askdir
		        (prompt #whereisold)
		        (help "Select directory")
		        (default "Python:")
		    ) )
		)    

		(if (askbool
			(prompt (#willdeletemsg oldreleasepath))
			(help #willdeletehelp)
			(choices #proceed #abort)
			)
			(
				(working (#deleteworkmsg #oldversion))
				(run "assign Python: remove")
				(run ("delete >NIL: %s %s.info FORCE ALL" oldreleasepath oldreleasepath))
				;;; Check if indeed all stuff went to the bitbasket
			        (if (exists oldreleasepath) (abort #oldstillexistserr))
			)
			(abort)
		)
	)
)
)

;;;;
;;;; Select wether to install next to existing Python.
;;;;
(procedure installNextToPrev
(if (exists "Python:" (noreq))
 (
	(askbool (prompt #nexttoprev )
	(help #nexttoprev_help )
	(choices #nexttoprev_yes #nexttoprev_no ) )
 )
 FALSE
)
)

;;;;
;;;; Select destination. Create drawer if necessary.
;;;;
(procedure selectDestination
(set destination
    (askdir
        (prompt #whereprompt)
        (help #wherehelp)
        (newpath)
        (default #source-dir)
    )
)    

(set @default-dest destination)

(if (= #source-dir destination)
    (
        (set #otherdir FALSE)
        (message (#currentmsg destination))
    )
    (
        (set #otherdir TRUE)
        (set tempdest destination)
        (set destination (tackon destination "Python-2.0"))

        (if (exists destination) (abort #existingerr))

        (message (#newmsg destination))
        (makedir destination)
        (copyfiles
        (source (tackon #source-dir "Icons/Drawer.info"))
        (dest tempdest)
        (newname "Python-2.0.info")
        )
    )
)
)


;;;;
;;;; Install the Python binary.
;;;;
(procedure installprog
 (if #otherdir
   (
    (copyfiles
    (source (tackon #source-dir "Python_030"))
    (dest destination)
    (newname "Python")
    )
    (run ("delete >NIL: FORCE %s/python_#?" destination))
   )
   (
    (rename (tackon #source-dir "Python_030") (tackon #source-dir "Python") )
   )
 )
)


;;;;
;;;; Ask user if she wants to delete the installation drawer.
;;;;
;;;; BUG: hmm this doesnt work because installer keeps a lock in that drawer.
;;;;
;(procedure removeInstallation
;(if (askbool (prompt #deleteinstall) (help ""))
;    (
;	(working (#deleteworkmsg #installationfiles))
;	(message ("delete >NIL: %s %s.info FORCE ALL" #source-dir #source-dir))
;	(run ("delete >NIL: %s %s.info FORCE ALL" #source-dir #source-dir))
;    )
;)
;)


;------------------------------------------------------------------------
;;;;
;;;; Now, install the files.
;;;;
(procedure installFiles
(if #otherdir
  (
    (installprog)
    (complete 50)
    (copyfiles
    (source #source-dir)
    (dest destination)
    (pattern "(Lib|Demo|Docs|Icons|Modules)")
    (infos)
    )
    (complete 90)
    (copyfiles
    (source (tackon #source-dir "DISCL_and_COPYRIGHT"))
    (dest destination) (infos))
    (copyfiles
    (source (tackon #source-dir "README"))
    (dest destination) (infos))
    (copyfiles
    (source (tackon #source-dir "CHANGES"))
    (dest destination) (infos))
    (copyfiles
    (source (tackon #source-dir "RunTest.py"))
    (dest destination) (infos))
    (copyfiles
    (source (tackon #source-dir "Icons/def_py.info"))
    (dest destination)
    (newname "RunTest.py.info")
    )

    (copyfiles
    (source (tackon #source-dir "Icons/Python.info"))
    (dest destination)
    (newname "Python.info")
    )

    ;;;; Because we installed to another drawer, the installation files can be removed.
    ;(removeInstallation)	; Doesn't work: installer still locks drawer

  )
  (
    (complete 50)
    (installprog)
    (complete 75)
    (copyfiles
    (source (tackon #source-dir "Icons/Python.info"))
    (dest destination)
    (newname "Python.info")
    )
    (copyfiles
    (source (tackon #source-dir "Icons/def_py.info"))
    (dest destination)
    (newname "RunTest.py.info")
    )
    (run ("delete >NIL: FORCE %s/(python_#?|install#?)" destination))
    (run ("delete >NIL: FORCE %s/Update_Previous#?" destination))
  )
)
)

;------------------------------------------------------------------------
;;;;
;;;; Install the files next to previous version.
;;;;
(procedure installFilesNextToPrev
(
	(set #otherdir TRUE)
	(set tempdest "Python:" )
	(set destination (tackon tempdest "Python-2.0"))
	(set @default-dest tempdest)

	;; create destination subdirectory
        (makedir destination)
        (copyfiles
        (source (tackon #source-dir "Icons/Drawer.info"))
        (dest tempdest)
        (newname "Python-2.0.info")
        )

	;; install files
	(installFiles)

	;; rename new Python binary to Python20 in parent dir (next to previous one)
	(rename (tackon destination "Python") (tackon tempdest "Python20") )
	(rename (tackon destination "Python.info") (tackon tempdest "Python20.info") )

	;; move library files to Python:lib
	(rename (tackon destination "Lib/Python2.0") (tackon tempdest "Lib/Python2.0") )

	;; copy site-python files
        (copyfiles
        (source (tackon destination "Lib/site-python"))
        (dest (tackon tempdest "Lib/site-python"))
	(pattern "#?.py")
        )
	
	;; delete original Lib dir
	(run ("delete >NIL: FORCE ALL %s" (tackon destination "Lib")))

	(message #installnextto_done)
)
)

;------------------------------------------------------------------------
;;;;
;;;; Main installation sequence starts here
;;;;

(if (= @pretend 1)
    (abort #nopretendmsg)
)

;;;; DISABLED FOR 2.0 installation:
;;;; (message #updatemsg)

(message #welcomemsg)

(checkKick)

(installPager)

(complete 0)

(if (installNextToPrev)
 (
	;; INSTALL NEXT TO PREVIOUS VERSION

	(installFilesNextToPrev)

	(complete 95)
 )
 (
	;; Install standalone

	(removeOldversion)

	(complete 10)

	(selectDestination)

	(complete 25)

	(installFiles)

	(complete 95)

	(startup @app-name
	        (prompt (#startupprompt destination))
	        (help @startup-help)
	        (command ("ASSIGN Python: %s\n" destination))
	        (command "PATH Python: ADD\n")
	)

	(run ("ASSIGN >NIL: Python: %s" destination))

 )
)


(run (cat "run " pager-cmd " %s") (tackon destination "DISCL_and_COPYRIGHT") (safe))

(message #readmemsg)
(message #endmsg)

(run "delete >NIL: ram:more FORCE")

(complete 100) ; 100% done!

