vlocity-vinstall-gambas / Vlocity / .svn / text-base / MdlBootMngr.module.svn-base

  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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
' Gambas module 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/>.
'====================================================================================================

PUBLIC bMenuRan AS Boolean
PRIVATE $chroot AS Process
PUBLIC bScanned AS Boolean
PUBLIC sVidMode AS String
PUBLIC objMenuEntries AS NEW Object[]

PUBLIC SUB make_bootmenu_objects()
  
  DIM sDump, sLoc, sGrubLbl, sLiloLbl, ostype AS String
  DIM sLines, sLine AS String[]
  DIM i AS Integer
  DIM bm AS BootMenuEntry
    
  objMenuEntries.Clear
    SHELL "os-prober " TO sDump
    IF Len(Trim(sdump)) <= 0 THEN 
      bMenuRan = TRUE
      RETURN 
    END IF
    
    sLines = Split(Trim(sdump), gb.NewLine)
    FOR i = 0 TO sLines.Max
            sLine = Split(Trim(sLines[i]), ":")
              sLoc = Trim(sLine[0])
              sGrubLbl = Trim(sLine[1])
              ostype = Trim(sLine[3])
              
              IF InStr(sLine[2], "VectorLinux") AND Trim(sloc) <> main.Install.Root THEN 
                sLiloLbl = "Vector-" & Replace(sloc, "/dev/", "")
              ELSE 
                sLiloLbl = Trim(sLine[2])
              END IF

                bm = NEW BootMenuEntry
                bm.Root = sLoc
                bm.osType = ostype
                    bm.sGrubLabel = sGrubLbl
                    bm.sLIloLabel = sLiloLbl
                    bm.Label = bm.sLIloLabel
                    bm.Enabled = TRUE
                    IF bm.osType = "linux" THEN 
                    TRY MKDIR Replace(sLoc, "dev", "mnt")
                    SHELL "mount " & sLoc & Space(1) & Replace(sLoc, "dev", "mnt") WAIT 
                      bm.RamDisks = Dir(Replace(sLoc, "dev", "mnt") &/ "boot", "*initrd*").Sort(gb.Ascent)
                        IF bm.RamDisks.Count > 0 THEN bm.initrd = bm.RamDisks[0]
                      bm.Kernels = Dir(Replace(sLoc, "dev", "mnt") &/ "boot", "*vmlinuz*").Sort(gb.Descent)
                        IF bm.Kernels.Count > 0 THEN bm.kernel = bm.Kernels[0]
                    SHELL "umount " & Replace(sLoc, "dev", "mnt")
                  ELSE 
                    IF InStr(bm.sLIloLabel, "Windows") THEN 
                      bm.sLIloLabel = "Windows-" & Replace(bm.Root, "/dev/", "")
                      bm.Label = bm.sLIloLabel
                    END IF
                  ' bm.Label = bm.sLIloLabel
                  ' Message(bm.Label)
                  ' Message(bm.sGrubLabel)
                  ' Message(bm.sLIloLabel)
                    'Message("Non-linux os found in " & bm.Root)
                  END IF
                  
                objMenuEntries.Add(bm)
    NEXT 
                
    
  
  
END



PUBLIC FUNCTION RUN_GRUB_INSTALL() AS Integer
    DIM hproc AS Process
    
    ''' Install grub2 
        ' As of grub2, the boot menu entries must be changed in /etc/rc.d/grub.d/30_os-prober.
        ' The boot menu file can be changed, however, changes are lost once grub-mkconfig is ran again... so no point in changing them there.
    '''
    
    IF Exist(Main.Install.TargetMount &/ "usr/sbin/grub-install") THEN 
      hproc = SHELL "chroot " & Main.Install.TargetMount & " /usr/sbin/grub-install --no-floppy " & Main.BootLoader.Target WAIT 
        IF hproc.Value > 0 THEN RETURN hproc.Value
      hproc = SHELL "chroot " & Main.Install.TargetMount & " /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg" WAIT 
        IF hproc.Value > 0 THEN RETURN hproc.Value
    ELSE 
      
    SHELL "mkdir -p " & Main.Install.TargetMount &/ "boot/grub > /dev/null" WAIT  
    hproc = SHELL "grub-install --no-floppy --root-directory=" & Main.Install.TargetMount & Space(1) & Main.BootLoader.Target WAIT 
    
      IF hproc.Value > 0 THEN RETURN hproc.Value
    hproc = SHELL "grub-mkconfig -o " & Main.Install.TargetMount &/ "boot/grub/grub.cfg" WAIT 
    IF hproc.Value > 0 THEN RETURN hproc.Value
  END IF
  
END

PUBLIC FUNCTION Find_grub_stage1() AS String
  
  DIM stxt AS String
  DIM sdump AS String
  DIM sdumpar AS String[]
  stxt = "#!/bin/sh" & "\n" &
  "grub --batch <<EOT" & gb.NewLine &
  "find /boot/grub/stage1" & gb.NewLine &
  "quit" & gb.NewLine & "EOT"
  File.Save(Temp("grubstage1"), stxt)
  
  SHELL "sh " & Temp("grubstage1") & " | grep ^\" (\"" TO sdump
  RETURN Trim(sdump)

END


PUBLIC FUNCTION Convert_Lilo_to_grub(sLiloPartition AS String) AS String
  
  DIM i, ii AS Integer
  DIM hds AS String[] = Split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",")
  DIM spart AS String
  DIM snum AS Integer
  DIM sRet AS String
  
  spart = Right(sLiloPartition, Len(sLiloPartition) - Len("/dev/hd"))
  spart = Left(spart)
  snum = Right(sLiloPartition, Len(sLiloPartition) - Len("/dev/hda"))
    
    i = hds.Find(spart)
    sRet = "hd" & i & "," & snum
    
  RETURN sRet
  
END

PUBLIC SUB Get_Initrd_List(sLinuxRoot AS String) AS String[]
  
  DIM sResults, img AS String
  DIM slines, res AS NEW String[]
  DIM i AS Integer
  DIM sAdd, sBootPath AS String
    ' need to find the mounted address to this linux
    sAdd = Replace(sLinuxRoot, "/dev/", "/mnt/")
      IF sLinuxRoot = Main.Install.Root THEN 
        sBootPath = sadd &/ "boot"
      ELSE 
        sBootPath = sAdd &/ "boot"
      END IF
      DEBUG "Looking for initrds in " & sBootPath
      FOR EACH img IN Dir(sBootPath, "initrd*")
      
              res.Push(img)
      NEXT 
        res.Push(("None"))
      RETURN res

    ' 
END


PUBLIC SUB find_initrds_for_this_linux(sLinuxRoot AS String, object AS ComboBox)
  
  DIM sResults AS String
  DIM slines AS String[]
  DIM i AS Integer
  DIM sAdd, sBootPath AS String
    ' need to find the mounted address to this linux
    sAdd = Replace(sLinuxRoot, "/dev/", "/mnt/")
      IF sLinuxRoot = Main.Install.Root THEN 
        sBootPath = sadd &/ "boot"
      ELSE 
        sBootPath = sAdd &/ "boot"
      END IF
    SHELL "ls " & sBootPath & " | grep initrd" TO sResults
      sResults = Trim(sResults)
      'Message(sResults)
      IF NOT sResults THEN ' initrds are not located in the /boot directory
        SHELL "ls " & sadd & " | grep initrd" TO sResults
      END IF
      
      sResults = Trim(sResults)      
      
        slines = Split(sResults, "\n")
          FOR i = 0 TO slines.Max
            IF Len(Trim(slines[i])) > 0 THEN object.Add(Trim(slines[i]))
          NEXT 
          object.Add(("None"))
  
END

'PUBLIC SUB GENERATE_LILO_HEADER(sDefOs AS String, sVidMode AS String, iTimeOut AS Integer, sTarget AS String)
PUBLIC SUB GENERATE_LILO_HEADER(iTimeOut AS Integer)
  
  DIM sTmp AS String
  DIM sVGA, sVidImput, sDefBoot, sVidText, sOutput, sTarget AS String
  DIM sOsList AS String
  DIM entry AS BootMenuEntry
  
  sVidImput = Main.BootLoader.VideoResolution
  sDefBoot = Main.BootLoader.DefaultOS
  sTarget = Main.BootLoader.Target
  'iTimeout = Main.BootLoader.TimeOut
  'Message(sVidImput)
    IF iTimeout = 0 OR NOT (iTimeout) THEN iTimeout = 5 ' set default timeout value to 5 seconds.

    SELECT CASE sVidImput
      CASE ("Standard")
        svga = "normal"
      CASE ("Bootsplash Med")
        svga = "788"
      CASE ("Bootsplash High")
        svga = "791"
      CASE ("Bootsplash Extra High")
        svga = "794"
      END SELECT 
      
    sVidText = "# VESA framebuffer console @ 1024x768x64k \n" &
"vga = " & svga & "\n" &
"# Normal VGA console \n" &
"#vga = normal \n" &
"#VESA framebuffer console @ 1024 x768x64k \n" &
"#vga = 791 \n" &
"#VESA framebuffer console @ 1024 x768x32k \n" &
"#vga = 790 \n" &
"#VESA framebuffer console @ 1024 x768x256 \n" &
"#vga = 773 \n" &
"#VESA framebuffer console @ 800 x600x64k \n" &
"#vga = 788 \n" &
"#VESA framebuffer console @ 800 x600x32k \n" &
"#vga = 787 \n" &
"#VESA framebuffer console @ 800 x600x256 \n" &
"#vga = 771 \n" &
"#VESA framebuffer console @ 640 x480x64k \n" &
"#vga = 785 \n" &
"#VESA framebuffer console @ 640 x480x32k \n" &
"#vga = 784 \n" &
"#VESA framebuffer console @ 640 x480x256 \n" &
"#vga = 769 \n" &
"# Begin listing OS Choices \n"

    IF Conf0.rbLilo.Value = TRUE THEN 
      sOsList = ME.GENERATE_LILO_OS_LIST("lilo")
    ELSE 
      'sOsList = ME.GENERATE_LILO_OS_LIST("grub")
    END IF
    'sDefBoot = 
  ' FOR EACH entry IN MdlBootMngr.objMenuEntries
  '   IF entry.IsDefault = TRUE THEN 
  '     sDefBoot = entry.Label
  '   END IF
  ' NEXT 
  iTimeOut = iTimeOut * 10
  
  sOutput = "# LILO Configuration File \n" &
  "# Generated by the " & Main.Install.Name & " Installer \n \n" &
  "# Begin lilo global configuration \n \n" &
  "boot = " & sTarget & "\n" &
  "default = " & sDefBoot & "\n" &
  "prompt \n" &
  "compact \n" &
  "timeout = " & iTimeOut & "\n" &
  "#\n#\n#\n" &
  "# Override dangerous defaults that require the partition table: \n" &
  "change-rules \n" &
  "reset \n"
  IF Exist(Main.Install.TargetMount &/ "boot" &/ "bitmap" &/ "boot.bmp") THEN 
   sOutput = sOutput & "bitmap = /boot/bitmap/boot.bmp \n \n"
  END IF

  sOutput = sOutput & sVidText & gb.NewLine & sOsList & gb.NewLine
  
  
  
  File.Save(Temp("lilo.in"), sOutput)
  
  'Message(sOutput)
  File.Save(Main.Install.TargetMount &/ "etc" &/ "lilo.conf", sOutput)
  
  
  'Message(File.Load(Temp("lilo.in")))

END

PUBLIC FUNCTION get_Final_OS_list_for_lilo() AS String
  
  DIM sOutput AS String
  DIM cb AS CheckBox
  DIM tb AS TextBox
  DIM comb AS ComboBox
  DIM tl AS TextLabel
  DIM ThisEntry AS String
  DIM entry AS BootMenuEntry
  DIM Entries AS NEW Object[]
  
  FOR EACH cb IN Conf0.objMenuObjects
    entry = NEW BootMenuEntry
      entry.Enabled = cb.Value
      entry.Root = cb.Tag
        FOR EACH tl IN Conf0.objNames
          IF tl.Name = cb.Tag THEN entry.kernel = tl.tag
        NEXT 
        FOR EACH comb IN Conf0.objinitrds
          IF comb.Tag = cb.Tag THEN entry.initrd = comb.Text
        NEXT 
        FOR EACH tb IN Conf0.objappends
          IF tb.tag = cb.tag THEN entry.StartupOptions = tb.Text
        NEXT 
    Entries.Add(entry)
  NEXT 
    
    ' generate the list
    FOR EACH entry IN Entries
      IF entry.Enabled = TRUE THEN 
        ThisEntry = "# Menu entry for " & entry.Label & "\n" &
        "image = " & entry.kernel & "\n" &
        "root = " & entry.Root & "\n" &
        "label = " & entry.Label & "\n" &
        "initrd = " & entry.initrd & "\n" &
        "append = " & entry.StartupOptions & "\n" & 
        "read-only" & gb.NewLine
        sOutput = sOutput & ThisEntry
      END IF
    NEXT 
    
    RETURN sOutput

END


PUBLIC SUB DO_BIND_MOUNTING() 
  
  DIM sMounts AS String[] = Split("sys,proc,dev", ",")
  DIM i AS Integer
  DIM sarch AS String
  
    'RETURN 
  DEBUG "Performing bind mounts ... Please wait"
    EXEC ["uname", "-r"] TO sarch
      IF Exist("/lib/modules" &/ Trim(sarch)) = FALSE THEN ' hosted install detected
        EXEC ["mkdir", "-p", "/lib/modules" &/ Trim(sarch)] WAIT 
        EXEC ["mount", "-o", "bind", "/lib/modules" &/ Trim(sarch), Main.Install.TargetMount &/ "lib" &/ "modules" &/ Trim(sarch)] WAIT 
        SHELL "depmod -aq &" ' send this to the background
      END IF
      
    FOR i = 0 TO sMounts.Max
      EXEC ["mount", "-o", "bind", "/" & Trim(sMounts[i]), Main.Install.TargetMount &/ Trim(sMounts[i])] WAIT 
    NEXT 
      'EXEC ["mount", "-o", "tmpfs", "/tmp", main.Install.TargetMount &/ "tmp"] WAIT 
        
  ' make sure /mnt/target/home is mounted if it was selected.
  MdlMain.doublecheck_home_mount()
  
END


PUBLIC SUB SETUP_LILO_BOOT_MANAGER() AS Integer
  
  DIM cbx AS CheckBox
  DIM cb AS ComboBox
  DIM tl AS TextLabel
  DIM bootloc, sKernel, sInitrd, sArch, sTmpMnt, sHostPart, sDUmp AS String
  DIM entry AS BootMenuEntry
  
  ' find kernels and initrds, copy them to /boot on the target dir
  ' can't use /boot/tamu anymore... all has to go into /boot
  
  ' determine wether we need to update modules
  ' EXEC ["uname", "-r"] TO sArch
  '   IF Exist("/lib" &/ "modules" &/ Trim(sArch)) = FALSE THEN ' hosted install detected
  '     EXEC ["mkdir", "-p", "/lib" &/ "modules" &/ Trim(sArch)] WAIT 
  '     SHELL "mount -o bind " & Main.Install.TargetMount &/ "lib/modules" &/ Trim(sArch) & Space(1) & "/lib/modules" &/ Trim(sarch) & " && depmod -aq" WAIT 
  '   END IF
  '     
  ' 
  ' ' now that kernels have been copied, I need to run lilo
  ' ' Bind mount the target /tmp and sys dirs  now
  ' ' See PUBLIC SUB_PERFORM_BINDING on iVL branch
  ' EXEC ["mount", "-o", "bind", "/sys", Main.Install.TargetMount &/ "sys"] WAIT 
  ' EXEC ["mount", "-o", "bind", "/proc", Main.Install.TargetMount &/ "proc"] WAIT 
  ' EXEC ["mount", "-o", "bind", "/tmp", Main.Install.TargetMount &/ "tmp"] WAIT 
  ' EXEC ["mount", "-o", "bind", "/dev", Main.Install.TargetMount &/ "dev"] WAIT 
  ' 
  ' now, we need to run the lilo command itself
  DEBUG "Chroot into target, load modules and execute lilo"
  'SHELL "chroot " & ClsGlobal.sTargetPath & "; sleep 1; echo \' Done chrooting\'; /sbin/depmod -aq ; lilo " WAIT 
  DEBUG "Opening chroot shell for lilo setup."
    
    ' /* FIXME:
    '   This may not be the best approach to this... not all that great for error detection.
    '   This does however allow the process to run on the background, so the gui feels a bit
    '   snappier ;) */
  SHELL "cp /mnt/target/etc/lilo.conf /tmp/lilo.conf_target" WAIT 
  'RETURN 
          
    
    
  
  '$chroot = SHELL "chroot " & Main.Install.TargetMount FOR READ WRITE 
    $chroot = SHELL "chroot " & Main.Install.TargetMount & " /sbin/depmod -aq" WAIT 
    $chroot = SHELL "chroot " & Main.Install.TargetMount & " /sbin/lilo -P ignore 2> /tmp/lilores" WAIT 
      IF $chroot.Value > 0 THEN 
        SHELL "cat /tmp/lilores | grep ^Fatal | cut -f2-10 -d:" TO sDump
         Message.Error("Lilo returned an error..." & gb.NewLine & "Check your values in this step and try again" & gb.NewLine &
         gb.NewLine & Trim(sdump))
         RETURN 1
      ELSE 
        'Message.Info("Bootloader setup ended successfully")
        MdlMain.Set_App_Status(("Bootloader was correctly installed and configured"))
      END IF

  
END

PUBLIC SUB Process_Read()
  
  DIM sLine AS String
  READ #LAST, sLine, -256
  PRINT sLine
  
END
PUBLIC SUB Process_Error(Errormessage AS String)

  PRINT Errormessage
  
  
END

PUBLIC SUB GENERATE_LILO_OS_LIST(sBootManager AS String) AS String
  
  DIM entry AS BootMenuEntry
  DIM sRet, tempentry, clientry, sKernpath, sdump, short AS String
  DIM sLine AS String[]
  
    FOR EACH sdump IN main.Install.Partitions
      sLine = Split(sdump, "-")
      IF Trim(sLine[2]) = "/" THEN main.Install.Root = Trim(sLine[0])
    NEXT 
    TRY MKDIR main.Install.TargetMount &/ "boot" &/ "tamu"
    
    FOR EACH entry IN MdlBootMngr.objMenuEntries
    short = Replace(entry.Root, "/dev/", "")
    clientry = ""
      IF entry.Enabled = FALSE THEN CONTINUE 
      IF entry.osType LIKE "linux" THEN 
        IF entry.Root = main.Install.Root THEN 
          sKernpath = "/boot"
          clientry = "# Safe mode boot option for " & entry.sGrubLabel & "\n" &
          "image = " & sKernpath &/ Trim(entry.kernel) & "\n" &
          Space(5) & "root = " & Trim(entry.Root) & "\n" &
          Space(5) & "label = " & Left(entry.Label, 11) & "-cli \n" &
          Space(5) & "append = \"2 splash=verbose\"\n" 
            IF Len(entry.initrd) > 0 AND InStr(entry.initrd, ("None")) = FALSE THEN 
                clientry = clientry &
                Space(5) & "initrd = " & sKernpath &/ entry.initrd & "\n"
              END IF
            clientry = clientry & Space(5) & "read-only \n" 

        ELSE ' import other kernels and initrd's
          sKernpath = "/boot/tamu"
          clientry = ""
              ' copy kernel and initrd quickly here
            TRY MKDIR Replace(entry.Root, "dev", "mnt")
            SHELL "mount " & entry.Root & Space(1) & Replace(entry.Root, "dev", "mnt") WAIT 
              'IF Exist(Replace(entry.Root, "dev", "mnt") &/ "boot" &/ entry.kernel) THEN
                SHELL "cp " & Replace(entry.Root, "dev", "mnt") &/ "boot" &/ Trim(entry.kernel) & Space(1) & main.Install.TargetMount &/ sKernpath &/ "vmlinuz-" & short WAIT 
                entry.kernel = "vmlinuz-" & short
             ' END IF
              'IF Exist(Replace(entry.Root, "dev", "mnt") &/ "boot" &/ entry.initrd) THEN 
              IF Len(entry.initrd) > 0 AND InStr(entry.initrd, ("None")) = FALSE THEN 
                IF Stat(Replace(entry.root, "dev", "mnt") &/ "boot" &/ Trim(entry.initrd)).Size > 0 THEN ' ONLY COPY INITRD WHEN THEIR SIZE  > 0
                  SHELL "cp " & Replace(entry.Root, "dev", "mnt") &/ "boot" &/ Trim(entry.initrd) & Space(1) & main.Install.TargetMount &/ sKernPath &/ "initrd-" & short WAIT 
                  entry.initrd = "initrd-" & short
                END IF
              END IF
              'END IF
            SHELL "umount " & Replace(entry.Root, "dev", "mnt") 'umount  the partition now"
            
        END IF
        tempentry = "# Menu entry for " & entry.sGrubLabel & Space(1) & "installed to " & entry.Root & "\n" &
         "image = " & sKernpath &/ Trim(entry.kernel) & "\n" &
        Space(5) & "root = " & Trim(entry.Root) & "\n" &
        Space(5) & "label = " & Trim(entry.Label) & "\n" 
              IF main.TargetSwaps.Count > 0 THEN 
                ' Enable resume because our kernel can do it ;)
                tempentry = tempentry & 
                Space(5) & "append = \"resume=swap:" & main.TargetSwaps[0] & " splash=silent\" \n"
              END IF
              IF Len(entry.initrd) > 0 AND InStr(entry.initrd, ("None")) = FALSE THEN 
                tempentry = tempentry & 
                Space(5) & "initrd = " & sKernpath &/ entry.initrd & "\n"
              END IF
        tempentry = tempentry & Space(5) & "read-only" & "\n"
        
      ELSE ' non linux os
        tempentry = "# Menu entry for " & entry.sGrubLabel & " installed in " & entry.Root & "\n" &
        Space(5) & "other = " & entry.Root & "\n" &
        Space(5) & "label = " & entry.Label & "\n" &
        Space(5) & "table = " & Left(entry.Root, 8) & "\n"
      END IF
      
      sRet = sRet & clientry & tempentry
    NEXT 
  RETURN Trim(sRet)
END


PUBLIC FUNCTION Get_OS_Boot_Params(sOsRoot AS String) AS String
  
  DIM $kern, $initrd, $append, sDump AS String
  DIM i AS Integer
  DIM $dumparr, $linearr AS String[]
  DIM $file AS String = "/tmp/bootargs.lst"
  DIM $line AS String
  'dim sListarr as String[] = Split(Trim(File.Load("/tmp/bootargs.
  
  SHELL "cat " & $file & " | grep ^" & sOsRoot TO sDump
    sDump = Trim(sDump)
      $dumparr = Split(sDump, gb.NewLine)
      'IF NOT ($dumparr) THEN RETURN 
      IF $dumparr.Count <= 0 THEN RETURN 
      
      ' always grab the first line only for each os
        'IF NOT Trim($dumparr[0]) THEN RETURN 
      $line = Trim($dumparr[0])
        IF NOT ($line) THEN RETURN 

      $linearr = Split($line, ":")
                IF InStr($line, "append") THEN 
            $append = Right($line, Len($line) - InStr($line, "append") + 1) & "\"" ' this works for LILO booted os's only.
          ELSE 
            $append = Trim($linearr[5]) ' for grub botted os's
          END IF
        $kern = Trim($linearr[3])
        $initrd = Trim($linearr[4])
        
  
  RETURN $kern & "," & $initrd & "," & $append
        
END

PUBLIC FUNCTION CHECK_LILO_VALUES(bquiet AS Boolean) AS Integer
  
  ' will return 0 for clear
  ' 1 for error
  DIM tb, tb1, tb2 AS TextBox
  DIM cb AS CheckBox
  DIM sTag AS String = Conf0.TsOsList.Current.Text
    IF NOT (ClsGlobal.sDefBoot) THEN 
          IF bquiet = FALSE THEN 
            Message.Error(("You must select one operating system to be started by default"))
          END IF
        ' FOR EACH cb IN Conf0.objDefOs
        '   IF cb.Tag = sTag THEN 
        '     IF bquiet = FALSE THEN 
        '       Balloon.Error(("Check this box to make this your default operating system, or select another tab."), cb, cb.Left + 24)
        '       'RETURN 1
        '     END IF
        '   END IF
        ' NEXT 
        'DEBUG "No default OS selected"
        
      RETURN 1
    END IF
  IF Conf0.objNames.Count > 1 THEN 
  FOR EACH tb IN Conf0.objNames
    FOR EACH tb1 IN Conf0.objNames
      IF tb <> tb1 AND IF tb.Text = tb1.Text THEN 
        IF bquiet = FALSE THEN Message.Error(("Found duplicate operating system names. Please use unique labels for each menu entry"))
          FOR EACH tb2 IN Conf0.objNames
            IF tb2.Tag = sTag THEN 
              IF bquiet = FALSE THEN Balloon.Error(("Check these boxes to make sure they have unique names"), tb2, tb2.Left + 24)
            END IF
          NEXT 
        RETURN 1
      END IF
    NEXT 
  NEXT 
END IF
    RETURN 0
  
END

PRIVATE FUNCTION initrd_hunter(LinuxMountLoc AS String) AS String[]
  
    DIM res AS String[]
  DIM sFile AS String
    FOR EACH sFile IN Dir(LinuxMountLoc &/ "boot", "initrd*")
      IF Stat(LinuxMountLoc &/ "boot" &/ sFile).Size > 0 THEN res.Push(sFile)
    NEXT 
    
    RETURN res
  
END

PRIVATE FUNCTION kernel_hunter(LinuxMountLoc AS String) AS String[]
  
  DIM res AS NEW String[]
  DIM sFile AS String
  FOR EACH sFile IN Dir(LinuxMountLoc &/ "boot", "vmlinu*")
    IF Stat(LinuxMountLoc &/ "boot" &/ sFile).Size > 0 THEN res.Push(sFile)
  NEXT 
  RETURN res
  
  
END



PUBLIC SUB CREATE_MENU_ENTRY_OBJECTS()
  
  DIM sRawList, sRawEntry, sRawLine, sOptions AS String[]
  DIM cb AS ComboBox
  DIM sDump, sHostPart, sDump2 AS String
  DIM i, ii AS Integer
  DIM entry AS BootMenuEntry
  DIM initrds AS NEW String[]
  
  make_bootmenu_objects()
  RETURN 
  
objMenuEntries.Clear

  SHELL "os-prober " TO sdump
    IF Len(Trim(sdump)) <= 0 THEN 
      ERROR "Unable to probe for existing operating systems"
      bMenuRan = TRUE
      RETURN 
    END IF
  sDump = Trim(sDump)  
  sRawList = Split(Trim(sDump), gb.NewLine)
  
  FOR i = 0 TO sRawList.Max
    sRawLine = Split(Trim(sRawList[i]), ":")
      IF NOT (sRawLine) THEN CONTINUE 
      entry = NEW BootMenuEntry
      entry.Root = sRawLine[0]
      entry.sLIloLabel = sRawLine[2]
      entry.osType = Trim(sRawLine[3])
        'IF entry.sLIloLabel LIKE "vectorlinux" THEN 
        IF InStr(entry.sLIloLabel, "VectorLinux") THEN 
          entry.sLIloLabel = "Vector-" & Replace(entry.Root, "/dev/", "")
          entry.Label = "Vector-" & Replace(entry.Root, "/dev/", "")
        END IF
      entry.sGrubLabel = sRawLine[1]
      'IF entry.sGrubLabel LIKE "VectorLinux" THEN 
      IF InStr(entry.sGrubLabel, "VectorLinux") THEN 
        entry.sLIloLabel = "Vector-" & Replace(entry.Root, "/dev/", "")
        entry.Label = "Vector-" & Replace(entry.Root, "/dev/", "")
      END IF
      entry.osType = sRawLine[sRawLine.Max]
      IF NOT (entry.Label) THEN entry.Label = entry.sLIloLabel
    IF sRawLine[3] LIKE "linux" THEN 
      SHELL "linux-boot-prober " & Trim(sRawLine[0]) TO sDump2
        sDump2 = Trim(sDump2)
        
      IF NOT (sdump2) THEN 
        ' linux-boot-prober can't figure out how to boot this thing... let's see if we can help
        ' search manually
            'CONTINUE 
             IF IsDir(Replace(entry.root, "dev", "mnt")) = FALSE THEN TRY MKDIR Replace(entry.root, "dev", "mnt")
            SHELL "mount " & entry.Root & Space(1) & Replace(entry.root, "dev", "mnt") WAIT 
            SHELL "mount | grep " & Replace(entry.Root, "dev", "mnt") TO sdump
            IF Len(Trim(sdump)) > 0 THEN 
                entry.RamDisks = Dir(Replace(entry.Root, "dev", "mnt") &/ "boot", "*initrd*")
                'entry.RamDisks = initrd_hunter(Replace(entry.Root, "dev", "mnt"))
                entry.kernel = kernel_hunter(Replace(entry.Root, "dev", "mnt"))[0]
            END IF
            SHELL "umount " & Replace(entry.Root, "dev", "mnt") WAIT 
      
      ELSE 
      
            ' now we try to find out details about this linux
            
              sHostPart = Right(entry.Root, Len(entry.Root) - Len("/dev/"))
              SHELL "linux-boot-prober " & entry.Root TO sDump
                IF Trim(sDump) THEN 
                  sOptions = Split(Trim(sDump), ":")
                  entry.kernel = sOptions[3]
                  'entry.initrd = sOptions[4]
                  entry.StartupOptions = Replace(sOptions[5], "append", "")
                END IF
                  ' -===== Hunt for the initrd choices =-
                  IF entry.RamDisks.Count <= 0 THEN 
             
                    SHELL "mkdir -p /mnt" &/ sHostPart WAIT 
                    SHELL "mount " & entry.Root & Space(1) & Replace(entry.Root, "dev", "mnt") WAIT 
                      initrds = Get_Initrd_List(entry.Root)
                      
                      IF initrds.Count > 0 THEN entry.RamDisks = initrds
                          SHELL "umount /mnt" &/ sHostPart WAIT 
                          SHELL "sync" WAIT 
                          'SHELL "rm -r /mnt" &/ sHostPart WAIT 
                END IF
              END IF

        ELSE ' OS is not windows
        
         DEBUG "Found Non-Linux OS in " & entry.Root
      END IF
      ME.objMenuEntries.Add(entry)
    NEXT
bMenuRan = TRUE
  
END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.