Source

vlocity-vinstall-gambas / Vlocity / Installation.class

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
' Gambas class file
'    This file is part of vinstall-ng

'    vinstall-ng is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    vinstall-ng  is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with vinstall-ng.  If not, see <http://www.gnu.org/licenses/>.

PRIVATE $root AS String
PRIVATE $targetmnt AS String ' normally /mnt/target
PRIVATE $name AS String
PRIVATE $version AS String
PRIVATE $Source AS String
PRIVATE $ConfFile AS String
PRIVATE $SrcMnt AS String 'normally /mnt/source
PRIVATE $InstallType AS Integer ' 0, 1, 2 (Full, Custom, Min)
PRIVATE $Partitions AS NEW String[]
PRIVATE $RootPartition AS String
PRIVATE $Bulks AS NEW string[]
PRIVATE $CD2Bulks AS NEW String[]
PRIVATE $Pkgs AS NEW string[]
PRIVATE $totalpkgs AS Integer
PRIVATE $InstalledPkgLog AS NEW String[]
PRIVATE $BulkObjects AS NEW Object[]
PRIVATE $Cd2BulkObjects AS NEW Object[]
PRIVATE $Config AS NEW Settings

PROPERTY Root AS String
PROPERTY TargetMount AS String
PROPERTY Name AS String
PROPERTY Version AS String
PROPERTY Source AS String
PROPERTY ConfFile AS String
PROPERTY SrcMnt AS String
PROPERTY InstallType AS Integer
PROPERTY Partitions AS String[]
PROPERTY RootPartition AS String
PROPERTY Bulks AS string[]
PROPERTY Packages AS string[]
PROPERTY TotalPkgs AS Integer
PROPERTY InstalledPkgLog AS String[]
PROPERTY CD2Bulks AS String[]
PROPERTY BulkObjects AS Object[]
PROPERTY CD2BulkObjects AS Object[]
PROPERTY Config AS Settings




PUBLIC SUB Get_CDrom_Section() AS String
  
  DIM sRes, ShellDump AS String
  DIM sDrives AS String[]
  DIM sCDOptions AS String = "iso9660 defaults,noauto,ro,user 0 0"
  DIM i AS Integer
  
  SHELL "cat /proc/sys/dev/cdrom/info | grep -i ^\"drive name:\" | cut -f2 -d: | xargs -n2" TO ShellDump
  'SHELL "cat /proc/sys/dev/cdrom/info | grep -i ^\"drive name:\" | awk \'{print $3}\'" TO ShellDump ''' Alternate shell string
  'SHELL "cat /proc/sys/dev/cdrom/info | grep -i ^\"drive name:\" | tr -d [:blank:] | cut -d:" TO ShellDump ''' yet another alternate
  
  
  IF Len(Trim(ShellDump)) <= 0 THEN ' return nothing... no cdrom devices found
    RETURN 
  END IF
  sDrives = Split(Trim(ShellDump), gb.NewLine) ' caution.. this may be wrong if te returned value is "hda hdb" rather than "hda \n hdb"
  FOR i = 0 TO sDrives.Max
    sRes = "/dev" &/ sDrives[i] & Space(10) & "/media" &/ sDrives[i] & Space(10) & sCDOptions & gb.NewLine
  NEXT 
  
  RETURN Trim(sRes)
  
  
  
END


STATIC PUBLIC SUB write_fstab()
  
  DIM cdroms, sPart, sMntPnt, sfs AS String
  DIM sUnit AS Action
  DIM sArr, sSwap AS string[]
  DIM i AS Integer
  DIM p AS Partition
  DIM sLine, sOut, sSwapLine, srootline AS String
  
  
  
      sOut = "# /etc/fstab: static file system information.\n" &
 "#\n" &
 "#The following is an example.Please see fstab(5) for further details.\n" &
 "#Please refer to mount(1) for a complete description OF mount options.\n" &
 "#\n" &
 "#Format:\n" &
 "# < file system > < mount point > < type > < options > < dump > < pass >\n" &
 "#\n" &
 "#dump(8)uses the < dump > field to determine which file systems need \n" &
 "# to be dumped.fsck(8)uses the < pass > column TO determine which file \n" &
 "#systems need TO be checked - - the root file system should have a 1 in \n" &
 "#this field, other file systems a 2, AND any file systems that should \n" &
 "#not be checked(such AS MS - initrd / mnt OR NFS file systems)a 0.\n\n\n" &
 "#The Linux partitions\n"
  
  FOR EACH p IN Main.Partitions_In_Host
    SHELL "mkdir -p " & Main.Install.TargetMount &/ p.SelectedMountpoint WAIT 
    IF p.IsUsed = TRUE AND p.SelectedMountpoint = "/" THEN 
      
        IF p.SelectedFilesystem = ("Not Formatted") THEN 
          sfs = srootline & p.CurrentFileSystem
        ELSE 
          sFs = srootline & p.SelectedFilesystem
        END IF
        srootline = p.BlockDevice & Space(10) & p.SelectedMountpoint & Space(10) & sfs & Space(10) & "defaults" & Space(5) & "0" & Space(5) & "1" & "\n"
      BREAK 
    END IF
  NEXT 
  
  sOut = Trim(sOut) & "\n" & srootline
  
  FOR EACH p IN Main.Partitions_In_Host
    IF p.IsUsed = TRUE AND p.SelectedMountpoint <> "/" THEN 
      IF p.SelectedFilesystem = ("Not Formatted") THEN 
        IF p.CurrentFileSystem = "fat32" THEN 
          sfs = "vfat"
        ELSE IF p.CurrentFileSystem = "fat16" OR p.CurrentFileSystem = "fat" THEN 
          sfs = "fat"
        ELSE 
          sFs = p.CurrentFileSystem
        END IF
      ELSE 
        sfs = p.SelectedFilesystem
      END IF
      EXEC ["mkdir", "-p", Main.Install.TargetMount &/ p.SelectedMountpoint] WAIT 
    sLine = p.BlockDevice & Space(10) & p.SelectedMountpoint & Space(10) & sfs & Space(10) & Main.Install.fS_oPTIONS(sfs) & Space(5) & "0" & Space(5) & "2" & "\n"
    sOut = sOut & sLine
  END IF
 NEXT 
  
  
  sOut = sOut & "\n" & 
 "# Shared Windows/Linux partition" &
 "#/dev/hda1   /mnt/dos  msdos  umask=0   0  0 \n" &
 "#/dev/hda1   /mnt/win  vfat   fmask=111,dmask=0,quiet,shortname=mixed,user  0  0 \n" &
 "#/dev/hda1   /mnt/win  ntfs   umask=0   0  0\n" &
 "# Floppy disks \n" &
 "# The 'noauto' option indicates that the file system should not be mounted \n" &
 "# with 'mount -a' 'user' indicates that normal users are allowed to mount \n" &
 "# the file system. \n" &
 "/dev/fd0   /mnt/floppy  auto  defaults,noauto,user  0 0 \n" &
 "#/dev/fd1  /mnt/floppy  auto  defaults,noauto,user  0 0 \n\n" &
 "# If you have a ls-120 floppy drive, it could be on /dev/hda b c d etc.\n" &
 "#/dev/hdd  /mnt/ls120  auto  defaults,noauto,user  0 0 \n\n" &
 "# CDROM, CDWRITER, DVD \n" &
 "#/dev/cdrom    /media/cdrom  iso9660  defaults,noauto,ro,user  0 0 \n" &
 "#/dev/cdwriter /media/cdwriter  iso9660  defaults,noauto,rw,user  0 0 \n" &
 "#/dev/dvd      /media/dvd   auto  defaults,noauto,ro,user  0 0\n\n" &
 "# NFS file systems:\n" &
 "#linux01.gwdg.de:/suse/6.3/i386.de  /mnt/nfs  nfs  defaults  0 0\n\n" &
 "# proc file system:\n" &
 "proc  /proc  proc  defaults  0 0\n\n" &
 "# Unix98 devpts filesystem: \n" &
 "none  /dev/pts  devpts  gid=5,mode=666  0 0\n\n" &
 "# Shared memory filesystem: \n" &
 "tmpfs   /dev/shm    tmpfs defaults 0  0 \n\n" &
 "# Basic USB filesystem\n" &
 "sysfs  /sys  sysfs  defaults  0 0\n" &
 "usbfs /proc/bus/usb usbfs rw,devmode=0666 0 0\n\n" &
 "# example of a VFAT USB pendrive\n" &
 "#/dev/sda1  /mnt/pendrive vfat   fmask=111,dmask=0,noauto,user,quiet,shortname=mixed 0 0\n\n" &
 "# Swap partitions\n" &
 "# The 'sw' option means auto activating with 'swapon -a'.\n"
  
  FOR EACH p IN Main.Swaps_in_host
    IF p.IsUsed = TRUE THEN 
      sSwapLine = p.BlockDevice & Space(10) & "none" & Space(10) & "swap" & Space(10) & "sw" & Space(10) & "0" & "\n"
      sOut = sOut & sSwapLine
    END IF
  NEXT 
  
  
 TRY File.Save(Main.Install.TargetMount &/ "etc" &/ "fstab", sOut)
  
  
END


STATIC PUBLIC FUNCTION fS_oPTIONS(sType AS String) AS String
   
 DIM sMntOpts AS String
      
 SELECT CASE LCase(sType)
 CASE "reiserfs"
 sMntOpts = "noatime"
 CASE "vfat", "fat32", "fat16"
 sMntOpts = "fmask=111,dmask=0,gid=users,shortname=mixed,quiet,user"
 CASE "ntfs"
 sMntOpts = "umask=0,gid=users,user"
 CASE "ntfs-3g"
 sMntOpts = "defaults,allow_other,umask=0,users,nls=utf8,noexec"
 CASE "ext2", "ext3"
 sMntOpts = "defaults"
 CASE ELSE 
 sMntOpts = "defaults"
 END SELECT 
      
 RETURN sMntOpts  
 END



PRIVATE FUNCTION Root_Read() AS String

  RETURN $root

END

PRIVATE SUB Root_Write(Value AS String)

  $root = Value

END

PRIVATE FUNCTION TargetMount_Read() AS String

  RETURN $targetmnt

END

PRIVATE SUB TargetMount_Write(Value AS String)

  $targetmnt = Value

END

PRIVATE FUNCTION Name_Read() AS String

  RETURN $name

END

PRIVATE SUB Name_Write(Value AS String)

  $name = Value

END

PRIVATE FUNCTION Version_Read() AS String

  RETURN $version

END

PRIVATE SUB Version_Write(Value AS String)

  $version = Value

END



PRIVATE FUNCTION Source_Read() AS String

  RETURN $Source
  

END

PRIVATE SUB Source_Write(Value AS String)

  $Source = Value

END

PRIVATE FUNCTION ConfFile_Read() AS String

  RETURN $ConfFile

END

PRIVATE SUB ConfFile_Write(Value AS String)

  $ConfFile = Value

END

PRIVATE FUNCTION SrcMnt_Read() AS String

  RETURN $SrcMnt 

END

PRIVATE SUB SrcMnt_Write(Value AS String)

  $SrcMnt = Value

END

PRIVATE FUNCTION InstallType_Read() AS Integer

  RETURN $InstallType

END

PRIVATE SUB InstallType_Write(Value AS Integer)

  $InstallType = Value

END

PRIVATE FUNCTION Partitions_Read() AS String[]

  RETURN $Partitions

END

PRIVATE SUB Partitions_Write(Value AS String[])

  $Partitions = Value

END

PRIVATE FUNCTION RootPartition_Read() AS String

  RETURN $RootPartition

END

PRIVATE SUB RootPartition_Write(Value AS String)

  $RootPartition = Value

END

PRIVATE FUNCTION Bulks_Read() AS string[]

  RETURN $Bulks

END

PRIVATE SUB Bulks_Write(Value AS string[])

  $Bulks = Value

END

PRIVATE FUNCTION Packages_Read() AS string[]

  RETURN $Pkgs

END

PRIVATE SUB Packages_Write(Value AS string[])

  $Pkgs = Value

END

PRIVATE FUNCTION TotalPkgs_Read() AS Integer

  RETURN $totalpkgs

END

PRIVATE SUB TotalPkgs_Write(Value AS Integer)

  $totalpkgs = Value

END

PRIVATE FUNCTION InstalledPkgLog_Read() AS String[]

  RETURN $InstalledPkgLog

END

PRIVATE SUB InstalledPkgLog_Write(Value AS String[])

  $InstalledPkgLog = Value

END

PRIVATE FUNCTION CD2Bulks_Read() AS String[]

  RETURN $CD2Bulks

END

PRIVATE SUB CD2Bulks_Write(Value AS String[])

  $CD2Bulks = Value

END



PRIVATE FUNCTION BulkObjects_Read() AS Object[]

  RETURN $BulkObjects

END

PRIVATE SUB BulkObjects_Write(Value AS Object[])

  $BulkObjects = Value

END


PRIVATE FUNCTION CD2BulkObjects_Read() AS Object[]

  RETURN $Cd2BulkObjects

END

PRIVATE SUB CD2BulkObjects_Write(Value AS Object[])

  $Cd2BulkObjects = Value

END


PRIVATE FUNCTION Config_Read() AS Settings

  RETURN $Config

END

PRIVATE SUB Config_Write(Value AS Settings)

  $Config = Value

END