STXInstaller.st
author Claus Gittinger <cg@exept.de>
Thu, 18 Jul 1996 15:24:24 +0200
changeset 0 ce9f4417b660
child 1 7ebb34d8f3df
permissions -rw-r--r--
intitial checkin

Object subclass:#STXInstaller
	instanceVariableNames:'stxLibDir stxBinDir actionPercentageHolder actionTextHolder'
	classVariableNames:'LastBinDir LastLibDir'
	poolDictionaries:''
	category:'eXept-tools'
!


!STXInstaller  class methodsFor:'startup'!

open
    ^ self new open

    "Created: 17.7.1996 / 14:36:22 / cg"
! !

!STXInstaller methodsFor:'installing'!

copyFiles
    |msg fileSpec filesToCopy numFiles nDone|

    msg := #('ST/X Installation' '' 'copying:' '' 'to:' '') asStringCollection.

    fileSpec := #(
                "/ name            destination   subDir   required

                ( 'stc/stc'               #bin     nil      false)
                ( 'rules/stmkmp'          #bin     nil      false)
                ( 'rules/stmkmf'          #bin     nil      false)

                ( 'librun/librun.a'       #lib     'lib'    false)
                ( 'libbasic/libbasic.o'   #lib     'lib'    false)
                ( 'libbasic2/libbasic2.o' #lib     'lib'    false)
                ( 'libbasic3/libbasic3.o' #lib     'lib'    false)
                ( 'libcomp/libcomp.o'     #lib     'lib'    false)
                ( 'libview/libview.o'     #lib     'lib'    false)
                ( 'libview2/libview2.o'   #lib     'lib'    false)
                ( 'libwidg/libwidg.o'     #lib     'lib'    false)
                ( 'libwidg2/libwidg2.o'   #lib     'lib'    false)
                ( 'libwidg3/libwidg3.o'   #lib     'lib'    false)
                ( 'libtool/libtool.o'     #lib     'lib'    false)

                ( 'projects/smalltalk/*.rc'    #lib   nil    false)
                ( 'projects/smalltalk/patches' #lib   nil    false)

                ( 'projects/smalltalk/bitmaps'        #lib nil    false)
                ( 'projects/smalltalk/configurations' #lib nil    false)
                ( 'projects/smalltalk/doc'            #lib nil    false)
                ( 'projects/smalltalk/include'        #lib nil    false)
                ( 'projects/smalltalk/resources'      #lib nil    false)
                ( 'projects/smalltalk/rules'          #lib nil    false)
              ).

    filesToCopy := OrderedCollection new.

    fileSpec do:[:entry |
        |fileName dest subDir required destDir|

        fileName := entry at:1.
        dest := entry at:2.
        subDir := entry at:3.
        required := entry at:4.

        dest == #bin ifTrue:[
            destDir := stxBinDir
        ] ifFalse:[
            destDir := stxLibDir
        ].
        
        destDir := destDir asFilename.
        subDir notNil ifTrue:[
            destDir := destDir construct:subDir
        ].

        filesToCopy add:(fileName -> destDir pathName)
    ].

    numFiles := filesToCopy size.
    nDone := 0.

    filesToCopy do:[:entry |
        |fileName destDir|

        actionPercentageHolder value:(nDone / numFiles * 100) rounded.

        fileName := entry key.
        destDir := entry value.

        msg at:4 put:'    ' , (fileName asText allBold).
        msg at:6 put:'    ' , (destDir asText allBold).
        actionTextHolder value:nil.
        actionTextHolder value:msg.

        OperatingSystem executeCommand:('cp -r ../../' , fileName , ' ' , destDir).

        nDone := nDone + 1
    ].

    ^ true

    "Created: 17.7.1996 / 15:16:20 / cg"
    "Modified: 17.7.1996 / 15:21:09 / cg"
!

createDirectories
    |msg dirsToMake numDirs nDone|

    msg := #('ST/X Installation' '' 'creating directory:' '' '' '') asStringCollection.

    dirsToMake := OrderedCollection new.
    dirsToMake add:stxBinDir.
    dirsToMake add:stxLibDir.
    dirsToMake add:(stxLibDir asFilename constructString:'lib').
    dirsToMake add:(stxLibDir asFilename constructString:'doc').
    dirsToMake add:(stxLibDir asFilename constructString:'include').
    dirsToMake add:(stxLibDir asFilename constructString:'resources').
    dirsToMake add:(stxLibDir asFilename constructString:'binary').
    dirsToMake add:(stxLibDir asFilename constructString:'bitmaps').

    numDirs := dirsToMake size.
    nDone := 0.

    dirsToMake do:[:dirName |
        |d errMsg stop box|

        actionPercentageHolder value:(nDone / numDirs * 100) rounded.

        msg at:4 put:'    ' , dirName.
        actionTextHolder value:nil.
        actionTextHolder value:msg.

        d := dirName asFilename.

        d exists ifFalse:[
            OperatingSystem recursiveCreateDirectory:d pathName
        ].

        d exists ifFalse:[
            errMsg := 'failed to create directory: ' , dirName.
            stop := true
        ] ifTrue:[
            d isDirectory ifFalse:[
                errMsg := 'not a directory: ' , dirName.
                stop := true
            ] ifTrue:[
                (d isReadable
                and:[d isWritable]) ifFalse:[
                    errMsg := 'no R/W access to directory: ' , dirName.
                    stop := false
                ] ifTrue:[
                    errMsg := nil
                ]
            ]
        ].

        errMsg notNil ifTrue:[
            box := WarningBox new.
            box title:errMsg.
            box showAtPointerNotCovering:(WindowGroup activeGroup topViews first).
        ].

        Delay waitForSeconds:0.25.
        nDone := nDone + 1.
    ].
    ^ true

    "Created: 17.7.1996 / 15:24:19 / cg"
    "Modified: 17.7.1996 / 15:35:30 / cg"
! !

!STXInstaller methodsFor:'startup'!

askAndInstall
    "/ check, if we are in the projects/smalltalk directory

    (Filename currentDirectory pathName endsWith:'projects/smalltalk') ifFalse:[
        self warn:'must be in the projects/smalltalk directory'.
        ^ self
    ].

    [self askForDestination] whileTrue:[
        self checkForExistingInstallationAndConfirm ifFalse:[
            ^ self
        ].
        self doInstall ifTrue:[
            ^ self
        ].
        (self confirm:'installation failed or aborted - retry ?')
        ifFalse:[
            ^ self
        ]
    ].

    "Modified: 17.7.1996 / 15:08:30 / cg"
!

askForDestination
    "open a dialog to enter destination directories"

    |d cm l green dark
     stxLibDirHolder stxBinDirHolder
    |

    LastLibDir isNil ifTrue:[
        LastLibDir := '/usr/local/lib/smalltalk'
    ].
    LastBinDir isNil ifTrue:[
        LastBinDir := '/usr/local/bin'
    ].

    stxLibDirHolder := LastLibDir asValue.
    stxBinDirHolder := LastBinDir asValue.

    Screen current hasColors ifTrue:[
        green := (Color red:0 green:80 blue:20) "darkened".
        dark := Color grey:10.
    ] ifFalse:[
        green := Color white.
        dark := Color black.
    ].

    d := DialogBox new.

    d label:'ST/X CD Installation'.
    l := d addTextLabel:'Smalltalk/X CD installation.'.
    l adjust:#left; backgroundColor:dark; foregroundColor:Color white.
    d addVerticalSpace.
    d addVerticalSpace.

    d addHorizontalLine.

    l := d addTextLabel:'Destination directories:'.
    l adjust:#left; backgroundColor:dark; foregroundColor:Color white.

    cm := ComboBoxView on:stxBinDirHolder.
    cm list:(Array 
                with:'/tmp/stxbin'
                with:'/usr/local/bin'
                with:'/usr/bin'
                with:(Filename homeDirectory constructString:'bin')).
    d 
        addLabelledField:cm 
        label:'binaries' 
        adjust:#left 
        tabable:true 
        from:0.0 to:1.0 separateAtX:0.25
        nameAs:'binaryBox'.

    (d componentAt:'binaryBox.label') backgroundColor:dark; foregroundColor:Color white.

    cm := ComboBoxView on:stxLibDirHolder.
    cm list:(Array 
                with:'/tmp/stxlib'
                with:'/usr/local/lib/smalltalk'
                with:'/usr/lib/smalltalk'
                with:((Filename homeDirectory 
                            construct:'lib')
                            constructString:'smalltalk')).
    d 
        addLabelledField:cm 
        label:'libraries' 
        adjust:#left 
        tabable:true 
        from:0.0 to:1.0 separateAtX:0.25
        nameAs:'libraryBox'.

    (d componentAt:'libraryBox.label') backgroundColor:dark; foregroundColor:Color white.

    d addAbortButton; addOkButtonLabelled:'install'.
    d extent:400@300.

    d allViewBackground:dark.

    d openAtCenter.
    d accepted ifTrue:[
        stxLibDir := LastLibDir := stxLibDirHolder value.
        stxBinDir := LastBinDir := stxBinDirHolder value.
        ^ true
    ].
    ^ false

    "Modified: 17.7.1996 / 15:08:30 / cg"
!

checkForExistingInstallationAndConfirm
    "look if there is another installation and confirm
     reinstalling; return true if ok, false if not"

    stxLibDir asFilename exists ifTrue:[
        ^ DialogBox
            confirm:('detected existing installation in ' 
                     , stxLibDir asText allBold
                     , '\\continue & overwrite ?') withCRs 
           yesLabel:'overwrite' noLabel:'cancel'
        
    ].
    ^ true

!

doInstall
    "install ST/X; return true if ok, false if not"

    |progressView ok|

    progressView := ProgressIndicator
                        inBoxWithLabel:'ST/X Installation'
                        text:#('ST/X Installation' '' '' '' '' '' '' '') asStringCollection
                        abortable:true.
    progressView topView extent:400@300.

    ok := false.

    progressView showProgressOf:
            [:progressValue :currentAction |

              actionPercentageHolder := progressValue.
              actionTextHolder := currentAction.

              (self createDirectories) ifTrue:[
                  ok := self copyFiles
              ]
            ].

    ^ ok

    "Created: 17.7.1996 / 15:11:27 / cg"
    "Modified: 17.7.1996 / 15:24:27 / cg"
!

open
    self askAndInstall

    "Created: 17.7.1996 / 14:37:14 / cg"
! !

!STXInstaller  class methodsFor:'documentation'!

version
    ^ '$Header$'
! !