-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.module
505 lines (450 loc) · 18.8 KB
/
Functions.module
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
' Gambas module file
' ### SYSTEMWIDE FUNCTIONS ###
PUBLIC FUNCTION AutoUnits(value AS Float) AS String
'Function that will automatically turn a generic size value into something human-readable (in multiples of bytes):
DIM temp AS Long
IF value < 1000 THEN ' Bytes:
RETURN value & " B"
ELSE IF value < 1000000 THEN ' Kilobytes:
RETURN Round(value / 1024, -2) & " KB"
ELSE IF value < 1000000000 THEN ' Megabytes:
RETURN Round(value / 1048576, -2) & " MB"
ELSE IF value < 1000000000000 ' Gigabytes:
RETURN Round(value / 1073741824, -2) & " GB"
ELSE 'Terabytes
RETURN Round(value / 1099511627776, -2) & " TB"
END IF
END
PUBLIC FUNCTION HexToLong(sHexval AS String) AS Long
'Turn a hexadecimal number into a long integer (thanks to help from Timothy Marshal-Nichols)
DIM iHexVal AS Long
sHexval = "&H" & Right$(sHexval, 10)
iHexVal = CLng(Val(sHexval))
RETURN iHexVal
END
PUBLIC FUNCTION getPartType(t AS String) AS String
' Return partition type (t) string from partition type code:
IF Trim$(t) = "0" THEN RETURN "Empty"
IF Trim$(t) = "1" THEN RETURN "FAT12"
IF Trim$(t) = "2" THEN RETURN "XENIX root"
IF Trim$(t) = "3" THEN RETURN "XENIX usr"
IF Trim$(t) = "4" THEN RETURN "FAT16 <32MB"
IF Trim$(t) = "5" THEN RETURN "Extended"
IF Trim$(t) = "6" THEN RETURN "FAT16"
IF Trim$(t) = "7" THEN RETURN "HPFS/NTFS"
IF Trim$(t) = "8" THEN RETURN "AIX"
IF Trim$(t) = "9" THEN RETURN "AIX bootable"
IF Trim$(t) = "a" THEN RETURN "OS/2 Boot Manager"
IF Trim$(t) = "b" THEN RETURN "W95 FAT32"
IF Trim$(t) = "c" THEN RETURN "W95 FAT32 (LBA)"
IF Trim$(t) = "e" THEN RETURN "W95 FAT16 (LBA)"
IF Trim$(t) = "f" THEN RETURN "W95 Extended (LBA)"
IF Trim$(t) = "10" THEN RETURN "OPUS"
IF Trim$(t) = "11" THEN RETURN "Hidden FAT12"
IF Trim$(t) = "12" THEN RETURN "Compaq diagnostics"
IF Trim$(t) = "14" THEN RETURN "Hidden FAT16 <32MB"
IF Trim$(t) = "16" THEN RETURN "Hidden FAT16"
IF Trim$(t) = "17" THEN RETURN "Hidden HPFS/NTFS"
IF Trim$(t) = "18" THEN RETURN "AST SmartSleep"
IF Trim$(t) = "1b" THEN RETURN "Hidden W95 FAT32"
IF Trim$(t) = "1c" THEN RETURN "Hidden W95 FAT32 (LBA)"
IF Trim$(t) = "1e" THEN RETURN "Hidden W95 FAT16 (LBA)"
IF Trim$(t) = "24" THEN RETURN "NEC DOS"
IF Trim$(t) = "39" THEN RETURN "Plan 9"
IF Trim$(t) = "3c" THEN RETURN "PartitionMagic recovery"
IF Trim$(t) = "40" THEN RETURN "Venix 80286"
IF Trim$(t) = "41" THEN RETURN "PPC PReP Boot"
IF Trim$(t) = "42" THEN RETURN "SFS"
IF Trim$(t) = "4d" THEN RETURN "QNX4.x"
IF Trim$(t) = "4e" THEN RETURN "QNX4.x 2nd part"
IF Trim$(t) = "4f" THEN RETURN "QNX4.x 3rd part"
IF Trim$(t) = "50" THEN RETURN "OnTrack DM"
IF Trim$(t) = "51" THEN RETURN "OnTrack DM6 Aux1"
IF Trim$(t) = "52" THEN RETURN "CP/M"
IF Trim$(t) = "53" THEN RETURN "OnTrack DM6 Aux3"
IF Trim$(t) = "54" THEN RETURN "OnTrack DM6"
IF Trim$(t) = "55" THEN RETURN "EZ-Drive"
IF Trim$(t) = "56" THEN RETURN "Golden Bow"
IF Trim$(t) = "5c" THEN RETURN "Priam Edisk"
IF Trim$(t) = "61" THEN RETURN "SpeedStor"
IF Trim$(t) = "63" THEN RETURN "GNU HURD or SysV"
IF Trim$(t) = "64" THEN RETURN "Novell Netware 286"
IF Trim$(t) = "65" THEN RETURN "Novell Netware 386"
IF Trim$(t) = "70" THEN RETURN "DiskSecure Multi-Boot"
IF Trim$(t) = "75" THEN RETURN "PC/IX"
IF Trim$(t) = "80" THEN RETURN "Old Minix"
IF Trim$(t) = "81" THEN RETURN "Minix / old Linux"
IF Trim$(t) = "82" THEN RETURN "Linux swap"
IF Trim$(t) = "83" THEN RETURN "Linux"
IF Trim$(t) = "84" THEN RETURN "OS/2 hidden C: drive"
IF Trim$(t) = "85" THEN RETURN "Linux extended"
IF Trim$(t) = "86" THEN RETURN "NTFS volume set"
IF Trim$(t) = "87" THEN RETURN "NTFS volume set"
IF Trim$(t) = "88" THEN RETURN "Linux plaintext"
IF Trim$(t) = "8e" THEN RETURN "Linux LVM"
IF Trim$(t) = "93" THEN RETURN "Amoeba"
IF Trim$(t) = "94" THEN RETURN "Amoeba BBT"
IF Trim$(t) = "9f" THEN RETURN "BSD/OS"
IF Trim$(t) = "a0" THEN RETURN "IBM Thinkpad hibernate"
IF Trim$(t) = "a5" THEN RETURN "FreeBSD"
IF Trim$(t) = "a6" THEN RETURN "OpenBSD"
IF Trim$(t) = "a7" THEN RETURN "NeXTSTEP"
IF Trim$(t) = "a8" THEN RETURN "Darwin UFS"
IF Trim$(t) = "a9" THEN RETURN "NetBSD"
IF Trim$(t) = "ab" THEN RETURN "Darwin boot"
IF Trim$(t) = "b7" THEN RETURN "BSDI fs"
IF Trim$(t) = "b8" THEN RETURN "BSDI swap"
IF Trim$(t) = "bb" THEN RETURN "Boot Wizard hidden"
IF Trim$(t) = "be" THEN RETURN "Solaris boot"
IF Trim$(t) = "bf" THEN RETURN "Solaris"
IF Trim$(t) = "c1" THEN RETURN "DRDOS/sec (FAT-12)"
IF Trim$(t) = "c4" THEN RETURN "DRDOS/sec (FAT-16 <32MB)"
IF Trim$(t) = "c6" THEN RETURN "DRDOS/sec (FAT-16)"
IF Trim$(t) = "c7" THEN RETURN "Syrinx"
IF Trim$(t) = "da" THEN RETURN "Non-FS data"
IF Trim$(t) = "db" THEN RETURN "CP/M / CTOS / ..."
IF Trim$(t) = "de" THEN RETURN "Dell Utility"
IF Trim$(t) = "df" THEN RETURN "BootIt"
IF Trim$(t) = "e1" THEN RETURN "DOS access"
IF Trim$(t) = "e3" THEN RETURN "DOS R/O"
IF Trim$(t) = "e4" THEN RETURN "SpeedStor"
IF Trim$(t) = "eb" THEN RETURN "BeOS fs"
IF Trim$(t) = "ee" THEN RETURN "EFI GPT"
IF Trim$(t) = "ef" THEN RETURN "EFI (FAT-12/16/32)"
IF Trim$(t) = "f0" THEN RETURN "Linux/PA-RISC boot"
IF Trim$(t) = "f1" THEN RETURN "SpeedStor"
IF Trim$(t) = "f2" THEN RETURN "DOS secondary"
IF Trim$(t) = "f4" THEN RETURN "SpeedStor"
IF Trim$(t) = "fd" THEN RETURN "Linux raid autodetect"
IF Trim$(t) = "fe" THEN RETURN "LANstep"
IF Trim$(t) = "ff" THEN RETURN "BBT"
'IF Trim$(t) = "" THEN RETURN ""
RETURN "unknown"
END
PUBLIC FUNCTION MakeTree(BaseDir AS String) AS Boolean
' Create a full FHS dir tree within BaseDir:
MKDIR BaseDir &/ "bin"
MKDIR BaseDir &/ "boot"
MKDIR BaseDir &/ "etc"
MKDIR BaseDir &/ "etc/opt"
MKDIR BaseDir &/ "home"
MKDIR BaseDir &/ "lib"
MKDIR BaseDir &/ "media"
MKDIR BaseDir &/ "media/cdrom"
MKDIR BaseDir &/ "media/floppy"
MKDIR BaseDir &/ "mnt"
MKDIR BaseDir &/ "opt"
MKDIR BaseDir &/ "root"
MKDIR BaseDir &/ "sbin"
MKDIR BaseDir &/ "srv"
MKDIR BaseDir &/ "tmp"
MKDIR BaseDir &/ "usr"
MKDIR BaseDir &/ "usr/bin"
MKDIR BaseDir &/ "usr/include"
MKDIR BaseDir &/ "usr/lib"
MKDIR BaseDir &/ "usr/local"
MKDIR BaseDir &/ "usr/local/bin"
MKDIR BaseDir &/ "usr/local/include"
MKDIR BaseDir &/ "usr/local/lib"
MKDIR BaseDir &/ "usr/local/sbin"
MKDIR BaseDir &/ "usr/local/share"
MKDIR BaseDir &/ "usr/local/share/doc"
MKDIR BaseDir &/ "usr/local/share/info"
MKDIR BaseDir &/ "usr/local/share/locale"
MKDIR BaseDir &/ "usr/local/share/man"
MKDIR BaseDir &/ "usr/local/share/man/man1"
MKDIR BaseDir &/ "usr/local/share/man/man2"
MKDIR BaseDir &/ "usr/local/share/man/man3"
MKDIR BaseDir &/ "usr/local/share/man/man4"
MKDIR BaseDir &/ "usr/local/share/man/man5"
MKDIR BaseDir &/ "usr/local/share/man/man6"
MKDIR BaseDir &/ "usr/local/share/man/man7"
MKDIR BaseDir &/ "usr/local/share/man/man8"
MKDIR BaseDir &/ "usr/local/share/misc"
MKDIR BaseDir &/ "usr/local/share/terminfo"
MKDIR BaseDir &/ "usr/local/share/zoneinfo"
MKDIR BaseDir &/ "usr/local/src"
MKDIR BaseDir &/ "usr/sbin"
MKDIR BaseDir &/ "usr/share"
MKDIR BaseDir &/ "usr/share/doc"
LINK BaseDir &/ "usr/doc" TO BaseDir &/ "usr/share/doc"
LINK BaseDir &/ "usr/local/doc" TO BaseDir &/ "usr/local/share/doc"
MKDIR BaseDir &/ "usr/share/info"
LINK BaseDir &/ "usr/info" TO BaseDir &/ "usr/share/info"
LINK BaseDir &/ "usr/local/info" TO BaseDir &/ "usr/local/share/info"
MKDIR BaseDir &/ "usr/share/locale"
MKDIR BaseDir &/ "usr/share/man"
LINK BaseDir &/ "usr/man" TO BaseDir &/ "usr/share/man"
LINK BaseDir &/ "usr/local/man" TO BaseDir &/ "usr/local/share/man"
MKDIR BaseDir &/ "usr/share/man/man1"
MKDIR BaseDir &/ "usr/share/man/man2"
MKDIR BaseDir &/ "usr/share/man/man3"
MKDIR BaseDir &/ "usr/share/man/man4"
MKDIR BaseDir &/ "usr/share/man/man5"
MKDIR BaseDir &/ "usr/share/man/man6"
MKDIR BaseDir &/ "usr/share/man/man7"
MKDIR BaseDir &/ "usr/share/man/man8"
MKDIR BaseDir &/ "usr/share/misc"
MKDIR BaseDir &/ "usr/share/terminfo"
MKDIR BaseDir &/ "usr/share/zoneinfo"
MKDIR BaseDir &/ "usr/src"
MKDIR BaseDir &/ "var"
MKDIR BaseDir &/ "var/cache"
MKDIR BaseDir &/ "var/lib"
MKDIR BaseDir &/ "var/lib/locate"
MKDIR BaseDir &/ "var/lib/misc"
MKDIR BaseDir &/ "var/local"
MKDIR BaseDir &/ "var/lock"
MKDIR BaseDir &/ "var/log"
MKDIR BaseDir &/ "var/mail"
MKDIR BaseDir &/ "var/opt"
MKDIR BaseDir &/ "var/run"
MKDIR BaseDir &/ "var/spool"
MKDIR BaseDir &/ "var/tmp"
' Success:
RETURN TRUE
CATCH ' Failed, usually due to already existing dirs:
RETURN FALSE
END
PUBLIC FUNCTION getFreePartSpace(sDevice AS String, sFilesystem AS String) AS Long
'Calculate the free space on a partition based on its filesystem, and then return the value as a long integer
'This is basicaly a Gambas implementation of what GParted does for detecting free space on partitions in C++
DIM sTemp AS String
DIM sTemp2 AS String
DIM sFreeBlocks AS String
DIM sBlockSize AS String
DIM sUsedBlocks AS String
DIM arrTemp AS NEW String[]
DIM iFreeBytes AS Long
DIM i AS Integer
sDevice = Trim$(sDevice)
sFilesystem = Trim$(sFilesystem)
'The array's index used ([x]) to get the free blocks and the block size was obtained by studying the ouput of the commands used below
IF sFilesystem = "Ext2" OR sFilesystem = "Ext3" THEN
SHELL "dumpe2fs -h " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[13], RInStr(arrTemp[13], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[16], RInStr(arrTemp[16], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "XFS" THEN
SHELL "xfs_db -c 'sb 0' -c 'print blocksize' -c 'print fdblocks' -r " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[1], RInStr(arrTemp[1], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[0], RInStr(arrTemp[0], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "ReiserFS" THEN
SHELL "debugreiserfs " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[6], RInStr(arrTemp[6], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[5], RInStr(arrTemp[5], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "JFS" THEN
SHELL "echo dm | jfs_debugfs " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(Left$(arrTemp[8], RInStr(arrTemp[8], "[") - 1), InStr(arrTemp[8], ":") + 1))
sBlockSize = Trim$(Mid$(arrTemp[2], RInStr(arrTemp[2], Space$(1))))
iFreeBytes = HexToLong(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "FAT12" OR sFilesystem = "FAT16" OR sFilesystem = "FAT32" THEN 'Who even uses FAT12 on today's hard-drives anyway?!
SHELL "dosfsck -v " & sDevice TO sTemp 'The "-a" switch should also be used to automaticaly repair a FAT partition, but that can take ages...lets see how well it works without it.
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
'Debug
' FOR i = 0 TO arrTemp.Length - 1
' PRINT arrTemp[i]
' NEXT
'Reuse sTemp, can't get sFreeBlocks in one go
sTemp = Trim$(Mid$(Left$(arrTemp[arrTemp.Length - 1], RInStr(arrTemp[arrTemp.Length - 1], "/") - 1), InStr(arrTemp[arrTemp.Length - 1], ",") + 1))
'PRINT sTemp
sTemp2 = Trim$(Mid$(Left$(arrTemp[arrTemp.Length - 1], RInStr(arrTemp[arrTemp.Length - 1], Space$(1))), RInStr(arrTemp[arrTemp.Length - 1], "/") + 1))
'PRINT sTemp2
sFreeBlocks = Str(CLng(Val(sTemp2) - CLng(Val(sTemp))))
sBlockSize = Trim$(Left$(Trim$(arrTemp[7]), InStr(Trim$(arrTemp[7]), Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "NTFS" THEN
SHELL "ntfsresize --info --force --no-progress-bar " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
'It would be a lot easier to use an expression in the output of ntfsresize to identify the number of free bytes, but that is not i18n ready!
'So "chomp" away portions of the string until the first integer is found (this will be the free space value)
'PRINT arrTemp[10]
sTemp = arrTemp[10]
WHILE Len(sTemp) > 0
sTemp2 = Trim$(Left$(sTemp, InStr(sTemp, Space$(1))))
IF IsInteger(Val(sTemp2)) OR IsLong(Val(sTemp2)) THEN
sUsedBlocks = CLng(Val(sTemp2))
BREAK
ELSE
sTemp = Trim$(Mid$(sTemp, InStr(sTemp, Space$(1))))
ENDIF
WEND
'sBlockSize = Trim$(Mid$(Left$(arrTemp[3], RInStr(arrTemp[3], Space$(1))), InStr(arrTemp[3], ":") + 1))
sTemp = Trim$(Mid$(arrTemp[5], InStr(arrTemp[5], ":") + 1)) 'Get total partition size
sTemp2 = Trim$(Left(sTemp, InStr(sTemp, Space$(1))))
iFreeBytes = CLng(sTemp2) - CLng(sUsedBlocks)
ELSE
iFreeBytes = 0
ENDIF
RETURN iFreeBytes
END
PUBLIC FUNCTION CalcSwap(sysmem AS Long) AS Long
'Calculate the theoretical swap partition size based on system memory, in bytes
IF sysmem < 134217728 THEN
RETURN sysmem * 2.5
ELSE IF sysmem < 268435456 AND sysmem > 134217728 THEN
RETURN sysmem * 2
ELSE 'Don't return swap partition sizes above 512MB
RETURN 536870912
ENDIF
END
PUBLIC FUNCTION AutoRootSize(partmode AS Integer) AS Long
'Calculate the size of the theoretical root partition, for the automatic or free-space partitioning modes
DIM iRootSize AS Long
DIM iTotalSize AS Long
DIM sTemp AS String
IF partmode = 0 THEN 'Use entire drive
iTotalSize = Global.DiskInfo[Global.instDriveIndex - 1].Bytes
iRootSize = iTotalSize - CalcSwap(Global.SysMemory)
ELSE IF partmode = 1 'Use only free space on partition
'Do whatever needs to be done to get free space values from available partitions
ELSE
Message.Error("Unacceptable partition mode (" & partmode & ") for AutoRootSize function.")
ENDIF
RETURN iRootSize
END
PUBLIC FUNCTION EnoughSpace(partmode AS Integer) AS Boolean
'Check whether the space destined to the package installation is enough (with a 150MB "safety" margin)
DIM iAvailableSpace AS Long
IF partmode = 0 THEN
iAvailableSpace = AutoRootSize(0) - CalcSwap(Global.SysMemory) - 157286400
IF iAvailableSpace > Global.PkgTotalSize THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
'Do the same for other partition modes (nothing to be done for the other modes yet...)
ELSE IF partmode = 1 THEN
ELSE IF partmode = 2 THEN
ELSE IF partmode = 3 THEN
ELSE IF partmode = 4 THEN
ELSE IF partmode = 5 THEN
ELSE
Message.Error("Invalid partition mode: " & Global.enumPARTMODE)
ENDIF
END
PUBLIC FUNCTION ErasePartTable(device AS String) AS Boolean
'Dangerous stuff....this will erase the partition table on a given device, and create a new MSDOS table. Return true if all goes well
DIM sBuffer AS String
'And here goes one of the ugliest and dirtiest ways of process management:
SHELL "parted -s " & device & " mklabel msdos" TO sBuffer
IF Trim(sBuffer) = "" THEN
RETURN TRUE
ELSE IF InStr(sBuffer, "Err") THEN
RETURN FALSE
ENDIF
END
PUBLIC FUNCTION MkPart(device AS String, partnum AS Integer, size AS Long) AS Boolean
'Create a partition using fdisk. use size=0 to use fdisk's defaults (fill unfartitioned space with new partition)
DIM $fdisk_proc AS Process
DIM partsize AS String
'Check is the partition already exists:
IF Exist(global.installDrive & partnum) THEN
RETURN FALSE
ENDIF
IF size = 0 THEN
partsize = ""
ELSE
partsize = "+" & (size * 1024) & "K"
ENDIF
SHELL "fdisk " & device FOR WRITE AS "$fdisk_proc"
PRINT #$fdisk_proc, "n";
PRINT #$fdisk_proc, "p";
PRINT #$fdisk_proc, partnum;
PRINT #$fdisk_proc, "";
PRINT #$fdisk_proc, partsize;
WAIT 0.5
PRINT #$fdisk_proc, "w";
'Make sure it was created
IF Exist(global.installDrive & partnum) = FALSE THEN
RETURN FALSE
ELSE
RETURN TRUE
ENDIF
END
' PUBLIC SUB BootMngrSet()
' ' This must determine:
' ' * Where the root partition is
' ' * Where the kernel is installed
' ' * where to install lilo (from global.enumLILOMODE ?? )
' ' * Which OS's to display in the boot menu (From user input)
' ' * To use bootsplash or to use framebuffer
' ' We'll use message.info to display the values for now, we can move those values somewhere else, or dome something more useful with them later
' DIM sRoot_Part AS String
' DIM sKernel_Loc AS String
' DIM ROOT_DIR AS String = "/"
' DIM Boot_DIR AS String = Root_DIR & "boot"
' ' Locate the root Partition
' IF global.enumLILOMODE = 0 THEN
' locate_mbr()
' SHELL "cat /etc/fstab | awk '{if ($2 == \"/\") {print $1}}'" TO sRoot_Part
' IF NOT sRoot_Part OR sRoot_Part <> "" THEN
' SHELL "mount | awk '{if ($3 == \"/\") {print $1}}'" TO sRoot_Part
' END IF
' 'message.Info("I've identified your root partition as " & gb.newline & sRoot_Part)
' Global.RootPart = sRoot_Part ' Store the location of the root partition to the global module
' END IF
' ' Figure out where the kernel is
' IF Exist(Boot_DIR & "/vmlinuz") THEN
' sKernel_Loc = Boot_DIR & "/vmlinuz"
' ELSE IF Exist(ROOT_DIR & "/vmlinuz") THEN
' sKernel_Loc = Root_DIR & "/vmlinuz"
' ELSE
' Message.Info("I can't find a kernel !!! ")
' END IF
' IF sKernel_Loc OR sKernel_Loc <> "" THEN
' 'message.Info("I've located the kernel in " & gb.NewLine & sKernel_Loc)
' Global.KernelLoc = sKernel_Loc ' Store the location of the kernel to the global module
' END IF
'
' END
'
' PUBLIC SUB locate_mbr()
'
' ' If the user chooses to install bootmanager to MBR
' ' This routine will analyze whether there are more than 1 MBR available
' ' and which one to use if true, else, use the one available automatically
' 'SHELL "/sbin/vliloconf"
'
' DIM disks AS String ' list of the mbrs as string
' DIM MBRs AS String[] ' split the many MBR's
' DIM MBR AS String ' Hold a temporary MBR
' DIM MBRTotal AS Integer ' Total MBRS
' DIM MBRIndex AS Integer ' Current MBR (index)
' DIM UseMBR AS String ' MBR to use.... A better place for this is probabbly somewhere in Global
' DIM findcmd AS String = "fdisk -l | grep Disk | cut -d \" \" -f 2 | cut -c 1-8"
' '
' 'SHELL "fdisk -l | grep Disk | cut -d " " - f 2 | cut -c 1-8" TO disks
' SHELL findcmd TO disks
' 'message.Info(disks)
' MBRs = Split(disks, " ") ' Maybe use a blank space (ie " " ) instead ??
' MbrTotal = MBRs.Count
' IF MBRTotal = 0 THEN ' This should never happen.
' 'message.Info(disks)
' message.Error("Cannot find an MBR on this box... You must be on some kind of alien box... ;) ")
' 'ELSE IF MBRTotal = 1 ' Located only one MBR
' ' UseMBR = disks ' Obviously, use the one available MBR
' ' Message.Info("The boot manager will be installed to: " & disks)
' 'ELSE IF MBRTotal >= 2 THEN ' We found several MBR's here... Your box is loaded with drives out the whazoo!
' ELSE
' 'message.Info(disks)
' FOR MBRIndex = 0 TO MBRs.count - 1
' MBR = MBRs[MBRIndex]
' frmChooseMBR.MbrList.Add(MBR) ' populate the list in the form
' frmChooseMBR.Show ' This form will shoot out a value to Global
' NEXT
' END IF
'
' END