STXInstaller.st
changeset 0 ce9f4417b660
child 1 7ebb34d8f3df
equal deleted inserted replaced
-1:000000000000 0:ce9f4417b660
       
     1 Object subclass:#STXInstaller
       
     2 	instanceVariableNames:'stxLibDir stxBinDir actionPercentageHolder actionTextHolder'
       
     3 	classVariableNames:'LastBinDir LastLibDir'
       
     4 	poolDictionaries:''
       
     5 	category:'eXept-tools'
       
     6 !
       
     7 
       
     8 
       
     9 !STXInstaller  class methodsFor:'startup'!
       
    10 
       
    11 open
       
    12     ^ self new open
       
    13 
       
    14     "Created: 17.7.1996 / 14:36:22 / cg"
       
    15 ! !
       
    16 
       
    17 !STXInstaller methodsFor:'installing'!
       
    18 
       
    19 copyFiles
       
    20     |msg fileSpec filesToCopy numFiles nDone|
       
    21 
       
    22     msg := #('ST/X Installation' '' 'copying:' '' 'to:' '') asStringCollection.
       
    23 
       
    24     fileSpec := #(
       
    25                 "/ name            destination   subDir   required
       
    26 
       
    27                 ( 'stc/stc'               #bin     nil      false)
       
    28                 ( 'rules/stmkmp'          #bin     nil      false)
       
    29                 ( 'rules/stmkmf'          #bin     nil      false)
       
    30 
       
    31                 ( 'librun/librun.a'       #lib     'lib'    false)
       
    32                 ( 'libbasic/libbasic.o'   #lib     'lib'    false)
       
    33                 ( 'libbasic2/libbasic2.o' #lib     'lib'    false)
       
    34                 ( 'libbasic3/libbasic3.o' #lib     'lib'    false)
       
    35                 ( 'libcomp/libcomp.o'     #lib     'lib'    false)
       
    36                 ( 'libview/libview.o'     #lib     'lib'    false)
       
    37                 ( 'libview2/libview2.o'   #lib     'lib'    false)
       
    38                 ( 'libwidg/libwidg.o'     #lib     'lib'    false)
       
    39                 ( 'libwidg2/libwidg2.o'   #lib     'lib'    false)
       
    40                 ( 'libwidg3/libwidg3.o'   #lib     'lib'    false)
       
    41                 ( 'libtool/libtool.o'     #lib     'lib'    false)
       
    42 
       
    43                 ( 'projects/smalltalk/*.rc'    #lib   nil    false)
       
    44                 ( 'projects/smalltalk/patches' #lib   nil    false)
       
    45 
       
    46                 ( 'projects/smalltalk/bitmaps'        #lib nil    false)
       
    47                 ( 'projects/smalltalk/configurations' #lib nil    false)
       
    48                 ( 'projects/smalltalk/doc'            #lib nil    false)
       
    49                 ( 'projects/smalltalk/include'        #lib nil    false)
       
    50                 ( 'projects/smalltalk/resources'      #lib nil    false)
       
    51                 ( 'projects/smalltalk/rules'          #lib nil    false)
       
    52               ).
       
    53 
       
    54     filesToCopy := OrderedCollection new.
       
    55 
       
    56     fileSpec do:[:entry |
       
    57         |fileName dest subDir required destDir|
       
    58 
       
    59         fileName := entry at:1.
       
    60         dest := entry at:2.
       
    61         subDir := entry at:3.
       
    62         required := entry at:4.
       
    63 
       
    64         dest == #bin ifTrue:[
       
    65             destDir := stxBinDir
       
    66         ] ifFalse:[
       
    67             destDir := stxLibDir
       
    68         ].
       
    69         
       
    70         destDir := destDir asFilename.
       
    71         subDir notNil ifTrue:[
       
    72             destDir := destDir construct:subDir
       
    73         ].
       
    74 
       
    75         filesToCopy add:(fileName -> destDir pathName)
       
    76     ].
       
    77 
       
    78     numFiles := filesToCopy size.
       
    79     nDone := 0.
       
    80 
       
    81     filesToCopy do:[:entry |
       
    82         |fileName destDir|
       
    83 
       
    84         actionPercentageHolder value:(nDone / numFiles * 100) rounded.
       
    85 
       
    86         fileName := entry key.
       
    87         destDir := entry value.
       
    88 
       
    89         msg at:4 put:'    ' , (fileName asText allBold).
       
    90         msg at:6 put:'    ' , (destDir asText allBold).
       
    91         actionTextHolder value:nil.
       
    92         actionTextHolder value:msg.
       
    93 
       
    94         OperatingSystem executeCommand:('cp -r ../../' , fileName , ' ' , destDir).
       
    95 
       
    96         nDone := nDone + 1
       
    97     ].
       
    98 
       
    99     ^ true
       
   100 
       
   101     "Created: 17.7.1996 / 15:16:20 / cg"
       
   102     "Modified: 17.7.1996 / 15:21:09 / cg"
       
   103 !
       
   104 
       
   105 createDirectories
       
   106     |msg dirsToMake numDirs nDone|
       
   107 
       
   108     msg := #('ST/X Installation' '' 'creating directory:' '' '' '') asStringCollection.
       
   109 
       
   110     dirsToMake := OrderedCollection new.
       
   111     dirsToMake add:stxBinDir.
       
   112     dirsToMake add:stxLibDir.
       
   113     dirsToMake add:(stxLibDir asFilename constructString:'lib').
       
   114     dirsToMake add:(stxLibDir asFilename constructString:'doc').
       
   115     dirsToMake add:(stxLibDir asFilename constructString:'include').
       
   116     dirsToMake add:(stxLibDir asFilename constructString:'resources').
       
   117     dirsToMake add:(stxLibDir asFilename constructString:'binary').
       
   118     dirsToMake add:(stxLibDir asFilename constructString:'bitmaps').
       
   119 
       
   120     numDirs := dirsToMake size.
       
   121     nDone := 0.
       
   122 
       
   123     dirsToMake do:[:dirName |
       
   124         |d errMsg stop box|
       
   125 
       
   126         actionPercentageHolder value:(nDone / numDirs * 100) rounded.
       
   127 
       
   128         msg at:4 put:'    ' , dirName.
       
   129         actionTextHolder value:nil.
       
   130         actionTextHolder value:msg.
       
   131 
       
   132         d := dirName asFilename.
       
   133 
       
   134         d exists ifFalse:[
       
   135             OperatingSystem recursiveCreateDirectory:d pathName
       
   136         ].
       
   137 
       
   138         d exists ifFalse:[
       
   139             errMsg := 'failed to create directory: ' , dirName.
       
   140             stop := true
       
   141         ] ifTrue:[
       
   142             d isDirectory ifFalse:[
       
   143                 errMsg := 'not a directory: ' , dirName.
       
   144                 stop := true
       
   145             ] ifTrue:[
       
   146                 (d isReadable
       
   147                 and:[d isWritable]) ifFalse:[
       
   148                     errMsg := 'no R/W access to directory: ' , dirName.
       
   149                     stop := false
       
   150                 ] ifTrue:[
       
   151                     errMsg := nil
       
   152                 ]
       
   153             ]
       
   154         ].
       
   155 
       
   156         errMsg notNil ifTrue:[
       
   157             box := WarningBox new.
       
   158             box title:errMsg.
       
   159             box showAtPointerNotCovering:(WindowGroup activeGroup topViews first).
       
   160         ].
       
   161 
       
   162         Delay waitForSeconds:0.25.
       
   163         nDone := nDone + 1.
       
   164     ].
       
   165     ^ true
       
   166 
       
   167     "Created: 17.7.1996 / 15:24:19 / cg"
       
   168     "Modified: 17.7.1996 / 15:35:30 / cg"
       
   169 ! !
       
   170 
       
   171 !STXInstaller methodsFor:'startup'!
       
   172 
       
   173 askAndInstall
       
   174     "/ check, if we are in the projects/smalltalk directory
       
   175 
       
   176     (Filename currentDirectory pathName endsWith:'projects/smalltalk') ifFalse:[
       
   177         self warn:'must be in the projects/smalltalk directory'.
       
   178         ^ self
       
   179     ].
       
   180 
       
   181     [self askForDestination] whileTrue:[
       
   182         self checkForExistingInstallationAndConfirm ifFalse:[
       
   183             ^ self
       
   184         ].
       
   185         self doInstall ifTrue:[
       
   186             ^ self
       
   187         ].
       
   188         (self confirm:'installation failed or aborted - retry ?')
       
   189         ifFalse:[
       
   190             ^ self
       
   191         ]
       
   192     ].
       
   193 
       
   194     "Modified: 17.7.1996 / 15:08:30 / cg"
       
   195 !
       
   196 
       
   197 askForDestination
       
   198     "open a dialog to enter destination directories"
       
   199 
       
   200     |d cm l green dark
       
   201      stxLibDirHolder stxBinDirHolder
       
   202     |
       
   203 
       
   204     LastLibDir isNil ifTrue:[
       
   205         LastLibDir := '/usr/local/lib/smalltalk'
       
   206     ].
       
   207     LastBinDir isNil ifTrue:[
       
   208         LastBinDir := '/usr/local/bin'
       
   209     ].
       
   210 
       
   211     stxLibDirHolder := LastLibDir asValue.
       
   212     stxBinDirHolder := LastBinDir asValue.
       
   213 
       
   214     Screen current hasColors ifTrue:[
       
   215         green := (Color red:0 green:80 blue:20) "darkened".
       
   216         dark := Color grey:10.
       
   217     ] ifFalse:[
       
   218         green := Color white.
       
   219         dark := Color black.
       
   220     ].
       
   221 
       
   222     d := DialogBox new.
       
   223 
       
   224     d label:'ST/X CD Installation'.
       
   225     l := d addTextLabel:'Smalltalk/X CD installation.'.
       
   226     l adjust:#left; backgroundColor:dark; foregroundColor:Color white.
       
   227     d addVerticalSpace.
       
   228     d addVerticalSpace.
       
   229 
       
   230     d addHorizontalLine.
       
   231 
       
   232     l := d addTextLabel:'Destination directories:'.
       
   233     l adjust:#left; backgroundColor:dark; foregroundColor:Color white.
       
   234 
       
   235     cm := ComboBoxView on:stxBinDirHolder.
       
   236     cm list:(Array 
       
   237                 with:'/tmp/stxbin'
       
   238                 with:'/usr/local/bin'
       
   239                 with:'/usr/bin'
       
   240                 with:(Filename homeDirectory constructString:'bin')).
       
   241     d 
       
   242         addLabelledField:cm 
       
   243         label:'binaries' 
       
   244         adjust:#left 
       
   245         tabable:true 
       
   246         from:0.0 to:1.0 separateAtX:0.25
       
   247         nameAs:'binaryBox'.
       
   248 
       
   249     (d componentAt:'binaryBox.label') backgroundColor:dark; foregroundColor:Color white.
       
   250 
       
   251     cm := ComboBoxView on:stxLibDirHolder.
       
   252     cm list:(Array 
       
   253                 with:'/tmp/stxlib'
       
   254                 with:'/usr/local/lib/smalltalk'
       
   255                 with:'/usr/lib/smalltalk'
       
   256                 with:((Filename homeDirectory 
       
   257                             construct:'lib')
       
   258                             constructString:'smalltalk')).
       
   259     d 
       
   260         addLabelledField:cm 
       
   261         label:'libraries' 
       
   262         adjust:#left 
       
   263         tabable:true 
       
   264         from:0.0 to:1.0 separateAtX:0.25
       
   265         nameAs:'libraryBox'.
       
   266 
       
   267     (d componentAt:'libraryBox.label') backgroundColor:dark; foregroundColor:Color white.
       
   268 
       
   269     d addAbortButton; addOkButtonLabelled:'install'.
       
   270     d extent:400@300.
       
   271 
       
   272     d allViewBackground:dark.
       
   273 
       
   274     d openAtCenter.
       
   275     d accepted ifTrue:[
       
   276         stxLibDir := LastLibDir := stxLibDirHolder value.
       
   277         stxBinDir := LastBinDir := stxBinDirHolder value.
       
   278         ^ true
       
   279     ].
       
   280     ^ false
       
   281 
       
   282     "Modified: 17.7.1996 / 15:08:30 / cg"
       
   283 !
       
   284 
       
   285 checkForExistingInstallationAndConfirm
       
   286     "look if there is another installation and confirm
       
   287      reinstalling; return true if ok, false if not"
       
   288 
       
   289     stxLibDir asFilename exists ifTrue:[
       
   290         ^ DialogBox
       
   291             confirm:('detected existing installation in ' 
       
   292                      , stxLibDir asText allBold
       
   293                      , '\\continue & overwrite ?') withCRs 
       
   294            yesLabel:'overwrite' noLabel:'cancel'
       
   295         
       
   296     ].
       
   297     ^ true
       
   298 
       
   299 !
       
   300 
       
   301 doInstall
       
   302     "install ST/X; return true if ok, false if not"
       
   303 
       
   304     |progressView ok|
       
   305 
       
   306     progressView := ProgressIndicator
       
   307                         inBoxWithLabel:'ST/X Installation'
       
   308                         text:#('ST/X Installation' '' '' '' '' '' '' '') asStringCollection
       
   309                         abortable:true.
       
   310     progressView topView extent:400@300.
       
   311 
       
   312     ok := false.
       
   313 
       
   314     progressView showProgressOf:
       
   315             [:progressValue :currentAction |
       
   316 
       
   317               actionPercentageHolder := progressValue.
       
   318               actionTextHolder := currentAction.
       
   319 
       
   320               (self createDirectories) ifTrue:[
       
   321                   ok := self copyFiles
       
   322               ]
       
   323             ].
       
   324 
       
   325     ^ ok
       
   326 
       
   327     "Created: 17.7.1996 / 15:11:27 / cg"
       
   328     "Modified: 17.7.1996 / 15:24:27 / cg"
       
   329 !
       
   330 
       
   331 open
       
   332     self askAndInstall
       
   333 
       
   334     "Created: 17.7.1996 / 14:37:14 / cg"
       
   335 ! !
       
   336 
       
   337 !STXInstaller  class methodsFor:'documentation'!
       
   338 
       
   339 version
       
   340     ^ '$Header$'
       
   341 ! !