root/pcbsd/trunk/PCInstall/pcinstall.cpp @ 3598

Revision 3598, 78.7 KB (checked in by kris, 11 months ago)

Fixed a bug loading component information in UTF-8 during the install

Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include <qimage.h>
13#include <qfile.h>
14#include <stdlib.h>
15#include <qtextstream.h>
16#include <Q3ListViewItem>
17#include <kio/job.h>
18#include "pcinstall.h"
19#include "addpartitiondialog.h"
20#include "dialogkeyboard.h"
21#include "editnetworkdialog.h"
22#include "selectnetserver.h"
23#include "ui_pcinstall.h"
24
25void PCInstall::ProgramInit()
26{
27    // Check the currently running language
28    if ( QFile::exists( "/PCBSDVERSION" ) )
29    {
30         QString Ver;
31
32         QFile file( "/PCBSDVERSION" );
33         if ( file.open( IO_ReadOnly ) ) {
34             QTextStream stream( &file );
35                 Ver = stream.readLine(); // line of text excluding '\n'
36             file.close();
37         }
38
39         VersionLabel->setText(tr("Version:") + " " + Ver); 
40    }
41
42   
43
44    // Set the variable to regenerate the custom slices
45    regenCustomSlices = 1;
46
47    // Default us to cd instead of DVD
48    usingDVDmedia = 0;
49
50    // Set our flag that we are not using a network install
51    networkInstall = false;
52
53    // Setup Translations
54    nextButton()->setText(tr("Next"));
55    backButton()->setText(tr("Back"));
56    finishButton()->setText(tr("Finish"));
57    cancelButton()->setText(tr("Cancel"));
58   
59    // Connect the Page changed Signal to the PageChangedSlot
60    connect( this, SIGNAL(selected( const QString &)), this, SLOT(PageChangedSlot(const QString &)) );
61    // Connect the checkLicAgree checkbox to slot for enabling next page access.
62    connect( checkLicAgree, SIGNAL( toggled(bool) ), this, SLOT( ChangeLicAgreeSlot( bool ) ) );
63   
64   
65    // Connect the various username objects and slots to the check function
66    connect( linePassword, SIGNAL( textChanged(const QString &) ), this, SLOT(passwordTextChanged() ) );
67    connect( linePassword2, SIGNAL( textChanged(const QString &) ), this, SLOT(passwordTextChanged() ) );
68    connect( linePassword2, SIGNAL(lostFocus()), this, SLOT(rootPasswordLineEditLostFocus()));
69   
70    // Connect the username fields to the enable / disable function for the pushbuttons
71     connect( lineUserName, SIGNAL( textChanged(const QString &) ), this, SLOT(checkUserLinesChanged(const QString & ) ) );
72     connect( lineFullName, SIGNAL( textChanged(const QString &) ), this, SLOT(checkUserLinesChanged(const QString & ) ) );
73     connect( lineUserPassword, SIGNAL( textChanged(const QString &) ), this, SLOT(checkUserLinesChanged(const QString & ) ) );
74     connect( lineUserPassword2, SIGNAL( textChanged(const QString &) ), this, SLOT(checkUserLinesChanged(const QString & ) ) );
75     connect( lineUserPassword2, SIGNAL(lostFocus()), this, SLOT(userPasswordLineEditLostFocus()));
76     connect( listBoxUsers, SIGNAL( selectionChanged ()  ), this, SLOT(listBoxUsersChanged() ) );
77   
78     
79 
80     
81    // Connect the buttons for user management
82    connect( pushAddUser, SIGNAL( clicked() ), this, SLOT( addUserButton() ) );
83    connect( pushRemoveUser, SIGNAL( clicked() ), this, SLOT( removeUserButton() ) );
84    connect( pushApplyUser, SIGNAL( clicked() ), this, SLOT(applyUserButton() ) );
85   
86    // Connect the drive boxes with slots that read drive info
87    connect( listDriveBox, SIGNAL( selectionChanged() ), this, SLOT( readFDISKFilesSlot() ) );
88
89   
90    // Connect the use entire disk checkbox.
91    connect( checkBoxEntireDisk,  SIGNAL(clicked() ), this, SLOT( useEntireDiskSlot()  ) );
92
93    // Connect the slice buttons
94    connect( pushSliceAdd,  SIGNAL(clicked() ), this, SLOT( sliceAddSlot() ) );   
95    connect( pushSliceEdit,  SIGNAL(clicked() ), this, SLOT( sliceEditSlot() ) ); 
96    connect( pushSliceRemove,  SIGNAL(clicked() ), this, SLOT( sliceRemoveSlot() ) ); 
97   
98    // Enable / disable the buttons and UI for custom slice setup
99    connect( checkCustomDiskSlice, SIGNAL( toggled(bool) ), this, SLOT( customDiskSliceSlot( bool ) ) );
100   
101    //Setup any regular expressions we will need
102    passwordRegExp.setPattern("([a-z]*[A-Z]*[0-9]*[!\"ᅵ$%^&*()_+=ᅵ#'`@~:?<>|{}\\-.]*)+");
103   
104    // Make sure the disk slice selector is disabled by default until clicked
105    customDiskSliceSlot( FALSE);
106   
107    // Set the default keyboard layouts
108    textKBLayout->setText("us - USA");
109    textKBModel->setText("pc105 - Generic 105-key PC");
110    textKBVariant->setText("off - Using default layout");
111           
112    // Load the Lang List
113    loadLangs();
114   
115    // Load the TimeZone Info
116    loadTZone();
117   
118    // List our filesystem types
119    comboFileSystem->insertItem("UFS2");
120    comboFileSystem->insertItem("UFS2 + Soft Updates");
121    comboFileSystem->insertItem("UFS2 + Journaling");
122
123    // Check if we booted with ZFS enabled or not
124    if ( QFile::exists( "/tmp/zfsEnabled" ) )
125    {
126       comboFileSystem->insertItem("ZFS (Experimental)");
127    }
128
129    // Set the default FS to UFS2 + Soft Updates
130    comboFileSystem->setCurrentItem(1);
131   
132    // Create our slot to check which FS the user has chosen
133    connect( comboFileSystem,  SIGNAL( currentIndexChanged(const QString &) ), this, SLOT( checkFileSystemSlot(const QString &) ) ); 
134
135   
136    // Load the HD info
137    runFindDisk();
138   
139    // Connect the Upgrade List Box
140    connect( listPartitionBoxUpgrade, SIGNAL( selectionChanged() ), this, SLOT( checkPartUpgradeBox() ) );
141
142   
143    // Set the variable indicating that we have no components ready to be installed.
144    installComponents = 0;
145       
146    // Load our list of available components
147    loadComponents();
148   
149   // Connection the listPartitionBox selection to a check slot
150   connect( listPartitionBox, SIGNAL( selectionChanged() ), this, SLOT( checkPartitionSelectionSlot() ) );
151   
152    // Hide the help button for now
153    helpButton()->setHidden(TRUE);
154   
155    // Read in the fdisk data
156    readFDISKFilesSlot();
157   
158       
159       
160
161        // Check if VMware is running
162        CheckVMware = new Q3Process( this );
163        CheckVMware->addArgument( "/usr/local/pcbsd/scripts/PCBSD.CheckVMware.sh" );
164
165        connect( CheckVMware, SIGNAL(processExited()), this, SLOT(checkVmwareSystemSlot()) );
166       
167        if ( !CheckVMware->start() ) {
168        }
169       
170        //Initilise colours
171        colourRed = QColor(255, 78, 78);
172        colourWhite = QColor(255, 255, 255);
173       
174       
175
176       
177
178    // Connect the list box languages to the slot
179    connect( listBoxLang, SIGNAL( selectionChanged () ), this, SLOT(listBoxLangChanged() ) );
180   
181
182    // Load the license text
183    loadLicense();
184
185   
186}
187
188
189
190
191
192
193void PCInstall::PageChangedSlot( const QString &Page )
194{
195   
196   
197    // Disable the HELP button
198    setHelpEnabled(currentPage(), FALSE);
199    helpButton()->setHidden(TRUE);
200   
201    if ( Page == tr("Select Language and Keyboard") )
202    {
203        //backButton()->setHidden(TRUE);
204       
205    }
206   
207     if ( Page == tr("License") )
208    {
209         backButton()->setHidden(FALSE);
210         
211        // Check if we need to disable the next button
212        if (! checkLicAgree->isChecked() )
213        {
214           setNextEnabled(currentPage(), FALSE);
215                }
216       
217       
218           NumlockProc = new Q3Process( this );
219           NumlockProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.EnableNumlock.sh" );
220           NumlockProc->start();
221    }
222   
223   
224    if ( Page == tr("Install or Update") )
225    {
226       //Removed, we sometimes need to go back to this page. Especially helpful in testing.
227       //setBackEnabled(currentPage(), FALSE);
228    }
229   
230    if ( Page == tr("System Components") )
231    {
232       
233    }
234   
235
236   
237    if ( Page == tr("User Accounts") )
238    {
239        // Stop the user from continuing until username and passwords are setup
240        CheckAccountInfo();
241       
242       
243    }
244   
245      if ( Page == tr("Disk Selection") )
246    {
247       
248        setNextEnabled(currentPage(), FALSE);
249       
250        // Dont let user go forward until they select a partition / drive
251          if ( checkBoxEntireDisk->isChecked() )
252          {
253           setNextEnabled(currentPage(), TRUE);
254                  } else {
255           // Save the status flag for the custom slice regen
256           int oldstatus = regenCustomSlices;
257           checkPartitionSelectionSlot();
258           regenCustomSlices = oldstatus;
259          }
260               
261    }
262   
263   
264        if ( Page == tr("Advanced Disk Setup") )
265    {
266       
267        if ( regenCustomSlices == 1) {
268           // Setup the initial slice layout
269           setupInitialSlices();
270           regenCustomSlices = 0;
271                }
272               
273        // Display slices on GUI
274        populateSlices();
275
276    }
277   
278   
279    if ( Page == tr("Select Update Partition") )
280    {
281       
282        listPartitionBoxUpgrade->clear();
283       
284        setNextEnabled(currentPage(), FALSE);
285        //setBackEnabled(currentPage(), FALSE);
286        textUpdatePart->setText(tr("Please wait.. Checking for existing PC-BSD Installs"));
287       
288        // Run the script to get PC-BSD installs
289        FindUpgradeParts = new Q3Process( this );
290        FindUpgradeParts->addArgument( "/usr/local/pcbsd/scripts/PCBSD.FindUpdateParts.sh" );
291
292        connect( FindUpgradeParts, SIGNAL(processExited()), this, SLOT(readAvailUpgradesSlot()) );
293        if ( !FindUpgradeParts->start() ) {
294            // error handling
295            //QMessageBox::warning( this, "PCBSD Installer",  SelectedDrive, "Retry", "Quit", 0, 0, 1 );
296        }
297       
298
299    }
300   
301    if ( Page == tr("Start Basic Install") )
302    {
303
304    }
305   
306
307   
308
309 
310    if ( Page == tr("Installing PC-BSD") )
311    {
312        // Check if we needed to regen the slices for ZFS
313        if ( regenCustomSlices == 1) {
314           // Setup the initial slice layout
315           setupInitialSlices();
316           regenCustomSlices = 0;
317           populateSlices();
318        }
319
320
321        setBackEnabled(currentPage(), FALSE);
322        setNextEnabled(currentPage(), FALSE);
323       
324        cancelButton()->setEnabled(TRUE);
325        cancelButton()->setHidden(FALSE);
326       
327        // Display the promo ads
328        PromoAd = 1;
329        changePromoAd();
330       
331         // Setup the length of our progress bars
332        calcProgressBarSize();
333
334        // If we are on a network install, skip the CD mount and format the drive first
335        if ( networkInstall) {
336          usingDVDmedia = 1;
337         
338     
339          // Now start the install / update
340          if ( radioFreshInstall->isChecked() )
341          {
342            // Skip the CD mount, will download direct from net instead
343            startFreshInstall();
344          } else {
345            startUpdateProcess();
346          }
347       
348
349        } else {
350          // Using a CD / DVD / USB, so mount it first
351          startMountCD();
352        }
353       
354    }
355   
356    if ( Page == tr("Installation Finished!") )
357    {
358        cancelButton()->setEnabled(FALSE);
359        cancelButton()->setHidden(TRUE);
360        finishButton()->setText(tr("&Reboot"));
361    }
362   
363   
364}
365
366
367void PCInstall::ChangeLicAgreeSlot( bool clicked )
368{
369   
370    if ( clicked)
371    {
372        // Enable the next button now
373        setNextEnabled(page(1), TRUE); 
374    } else {
375        // Disable the next button
376        setNextEnabled(page(1), FALSE);       
377    }
378   
379}
380
381
382
383void PCInstall::loadLangs()
384{
385    QString tmp;
386    QString Langcode;
387    QString Langdescr;
388    QString nlang = "";
389    int count = 0, found = 0;
390   
391    listBoxLang->clear();
392   
393    // Check the currently running language
394    if ( QFile::exists( "/root/.langchange" ) )
395    {
396
397             QFile file( "/root/.langchange" );
398             if ( file.open( IO_ReadOnly ) ) {
399                 QTextStream stream( &file );
400                     nlang = stream.readLine(); // line of text excluding '\n'
401                 file.close();
402             }
403
404    }
405
406
407
408    QFile file( "/root/Langs" );
409    if ( file.open( IO_ReadOnly ) ) {
410        QTextStream stream( &file );
411        QString line;
412        while ( !stream.atEnd() ) {
413            line = stream.readLine(); // line of text excluding '\n'
414            tmp = line;
415            tmp.truncate(tmp.find(" ") );
416            Langcode = tmp;
417           
418           
419           
420            Langdescr = line.remove(0, line.find(" ") + 1 );     
421           
422            listBoxLang->insertItem(Langdescr + " (" + Langcode + ")" );   
423
424            if ( nlang == Langcode ) {
425                listBoxLang->setSelected(count, TRUE); 
426                found = 1;
427            }
428
429            count++;
430        }
431        file.close();
432    }
433
434    if (found == 0) {
435        listBoxLang->setSelected(0, TRUE); 
436    }
437
438}
439
440
441void PCInstall::loadTZone()
442{
443   
444    QFile file( "/root/zones" );
445    if ( file.open( IO_ReadOnly ) ) {
446        QTextStream stream( &file );
447        QString line;
448        while ( !stream.atEnd() ) {
449            line = stream.readLine(); // line of text excluding '\n'
450           
451            comboTZone->insertItem(line);
452        }
453        file.close();
454    }
455   
456    comboTZone->setCurrentItem(124);
457}
458
459
460
461void PCInstall::CheckAccountInfo()
462{
463    int ok = 0;
464   
465    if ( linePassword->text() == "" )
466    {
467        textAcctNotify->setText("");
468        ok = 1;
469    }
470   
471    // Check if we hav e a username setup.
472    if ( AddUserName[0].isEmpty() )
473    {
474        textAcctNotify->setText(tr("You must setup at least one username to continue. "));
475        ok = 1;
476    }
477   
478    if ((linePassword->text() != linePassword2->text()) || linePassword->text().isEmpty())
479    {
480        ok = 1;
481    }
482   
483    if(ok == 0)
484    {
485        linePassword->unsetPalette();
486        linePassword2->unsetPalette();
487        textAcctNotify->setText("");
488        setNextEnabled(currentPage(), TRUE);   
489    } else {
490          setNextEnabled(currentPage(), FALSE); 
491    }
492   
493}
494
495
496void PCInstall::passwordTextChanged()
497{
498  CheckAccountInfo();
499}
500
501
502void PCInstall::reject()
503{
504    switch( QMessageBox::warning( this, tr("Exit Confirmation"), tr("Are you sure you want to quit? The system will be rebooted!"), tr("OK"), tr("Cancel"), 0, 0, 1 ) ) {
505             case 0: // The user clicked the OK again button or pressed Enter
506                 exit(1);
507                 break;
508             case 1: // The user clicked the Quit or pressed Escape
509                 break;
510             }
511}
512
513
514void PCInstall::addUserButton()
515{
516    int i = 0;
517
518    while ( i < 100)
519    {
520
521        if ( AddUserName[i] == "" )
522        {
523           break;   
524        }
525               
526        i++;
527    }
528   
529
530    AddUserName[i] = lineUserName->text();
531    AddRealName[i] = lineFullName->text();
532    AddPassword[i]    = lineUserPassword->text();
533   
534    if ( comboShell->currentItem() == 0)
535    {
536        AddShell[i] = "/bin/csh"; 
537    } else if ( comboShell->currentItem() == 1) {
538        AddShell[i] = "/bin/tcsh";
539    } else if ( comboShell->currentItem() == 2) {
540        AddShell[i] = "/bin/sh";
541    } else {
542        AddShell[i] = "/PCBSD/local/bin/bash";
543    }
544 
545
546   
547    refreshUsers();
548    CheckAccountInfo();
549   
550    lineUserName->setText("");
551    lineFullName->setText("");
552    lineUserPassword->setText("");
553    lineUserPassword2->setText("");
554    listBoxUsers->setCurrentItem(-1);
555   
556    checkUserLinesChanged("");
557   
558   
559}
560
561
562
563void PCInstall::removeUserButton()
564{
565   
566    int rmUser;
567    int i;
568   
569    if ( listBoxUsers->currentItem() != -1)
570    {
571        rmUser = listBoxUsers->currentItem();
572        i = rmUser;
573       
574        AddUserName[i] = "";
575        i++;
576       
577        while ( i < 100 )
578        {
579           
580            if ( AddUserName[i].isEmpty() )
581            {
582                break;
583            }
584           
585             AddUserName[i-1] = AddUserName[i];
586            AddRealName[i-1] = AddRealName[i];
587            AddPassword[i-1] = AddPassword[i];
588            AddShell[i-1] = AddShell[i];
589           
590            AddUserName[i]="";
591            AddRealName[i] = "";
592            AddPassword[i]="";
593            AddShell[i]="";
594           
595            i++;
596        }
597    }
598
599    refreshUsers();
600    CheckAccountInfo();
601    checkUserLinesChanged("");   
602}
603
604
605
606// Redraws the user box
607void PCInstall::refreshUsers()
608{
609   
610    listBoxUsers->clear();
611   
612
613        int i = 0;
614   
615    while ( i < 100)
616    {
617       
618        if ( AddUserName[i] == "" )
619        {
620           break;   
621        }
622
623        listBoxUsers->insertItem(AddUserName[i] + " (" + AddRealName[i] + ") - " + AddShell[i]);
624
625        i++;
626    }
627   
628   
629    if ( i > 0 )
630    {
631        listBoxUsers->setCurrentItem(0);       
632    }
633   
634   
635}
636
637
638void PCInstall::runFindDisk()
639{
640        // Start a process to get Disks from custom script output
641    FindDisk = new Q3Process( this );
642    FindDisk->addArgument( "/usr/local/pcbsd/scripts/PCBSD.FindDisk.sh" );
643
644    connect( FindDisk, SIGNAL(readyReadStdout()), this, SLOT(readFindDiskSlot()) );
645    if ( !FindDisk->start() ) {
646        // error handling
647        //QMessageBox::warning( this, "PCBSD Installer",  SelectedDrive, "Retry", "Quit", 0, 0, 1 );
648    }
649
650   
651   
652}
653
654
655void PCInstall::readFindDiskSlot()
656{
657    QString Buffer;
658     QString DevLabel;
659    int i = 0;
660   
661    while ( i< 100) 
662    {
663        if ( Drives[i].isEmpty() )
664        {
665         break;   
666        }
667        i++;
668    }
669   
670        // Loop while getting input
671    while (FindDisk->canReadLineStdout() )
672    {
673       
674       
675        // Read the line
676        Buffer = FindDisk->readLineStdout();
677        Drives[i] = Buffer;
678        Drives[i].truncate(Drives[i].find(":") );
679       
680        if (Buffer.find(">") < 90 && Buffer.find(">") != -1)
681        {
682            Buffer.truncate(Buffer.find(">") + 1);
683        } else {
684            Buffer.truncate(90);
685        }
686       
687       
688        if ( Buffer.find("ad", 0) != -1 )
689        {
690            DevLabel="(ATA / IDE Device)";
691        } else if (Buffer.find("da", 0) != -1 ) {
692            DevLabel="(SCSI / Removable Device)";
693        } else {
694            DevLabel="";
695        }
696       
697        listDriveBox->insertItem("/dev/" + Buffer + " " + DevLabel);
698       
699
700       
701        i++;
702    }
703
704}
705
706
707void PCInstall::readFDISKFilesSlot()
708{
709   
710    // Reset the list box
711    listPartitionBox->clear();
712   
713    // Make sure to set flag to regenerate slice layout for custom partitions
714    regenCustomSlices = 1;
715   
716   
717    if ( listDriveBox->currentItem() == -1)
718    {
719        checkBoxEntireDisk->setEnabled(FALSE);
720        return;
721    } else {
722        checkBoxEntireDisk->setEnabled(TRUE);
723    }
724   
725   
726    int item = listDriveBox->currentItem();
727    QString device = Drives[item];
728    QString Buffer;
729    QString Megabytes;
730    QString BlockLine;
731    QString StartBlock;
732    QString TotalBlocks;
733    QString tmp;
734   
735    Q_LLONG DriveBlks = 0;
736    Q_LLONG TotalDriveMB;
737    Q_LLONG AvailMB;
738    Q_LLONG tmpLong;
739   
740    int i = 1;
741    int usingExtended = 0;
742   
743   
744   
745QFile file( "/tmp/" + device );
746    if ( file.open( IO_ReadOnly ) ) {
747        QTextStream stream( &file );
748        while ( !stream.atEnd() ) {
749            Buffer = stream.readLine(); // line of text excluding '\n'
750         
751        //QMessageBox::warning( this, "Msg",  "StartBlock: " + StartBlock , "Retry", "Quit", 0, 0, 1 );
752
753        // Get the total blocks of the drive, to see if any free space available
754        if(Buffer.find("cylinders=") == 0)
755        {
756
757            // Get the cylinders
758            tmp = Buffer;
759            tmp = tmp.replace("cylinders=", "");
760            tmp.truncate(tmp.find(" "));
761            DriveBlks = tmp.toLongLong();
762            DriveCyl = tmp.toLongLong();
763            //QMessageBox::warning( this, "Msg",  "Cylinders " + tmp , "Retry", "Quit", 0, 0, 1 );
764
765            // Get the heads
766            tmp = Buffer;
767            tmp.remove(0, tmp.find("heads=") + 6 );
768            tmp.truncate(tmp.find(" "));
769            DriveBlks = DriveBlks * tmp.toLongLong();
770            DriveHead = tmp.toLongLong();
771            //QMessageBox::warning( this, "Msg",  "Heads " + tmp , "Retry", "Quit", 0, 0, 1 );
772
773            // Get the sectors / tracks
774            tmp = Buffer;
775            tmp.remove(0, tmp.find("sectors/track=") + 14);
776            tmp.truncate(tmp.find(" "));
777            DriveBlks = DriveBlks * tmp.toLongLong();
778            DriveSec = tmp.toLongLong();
779
780            TotalDriveBlocks.setNum(DriveBlks);
781
782            //QMessageBox::warning( this, "Msg",  "Sectors " + tmp , "Retry", "Quit", 0, 0, 1 );
783
784            //QMessageBox::warning( this, "Msg",  "TotalBlks " + tmp.setNum(DriveBlks) , "Retry", "Quit", 0, 0, 1 );
785        }
786
787        // Load the partition information
788        if (Buffer.find("The data for partition " +tmp.setNum(i) + " is:") != -1 )
789        {
790            // Get the next line, which has critical info
791            Buffer = stream.readLine(); // line of text excluding '\n'
792           
793            if ( Buffer.find("Extended") != -1 )
794            {
795                usingExtended = 1;
796            }
797           
798            if (Buffer.find("<UNUSED>") == -1 && Buffer.find("Extended") == -1 && i < 5 )
799            {
800                // Start picking apart line for information
801                Buffer.remove(0, Buffer.find(",") + 1 );
802
803                // Get the next fdisk line,  blocks and MB size
804                BlockLine = stream.readLine(); // line of text excluding '\n'
805                BlockLine = BlockLine.stripWhiteSpace();
806                Megabytes = BlockLine.section(" ", 4, 4);
807                Megabytes.remove(0, 1);
808
809                //QMessageBox::warning( this, "Msg",  "MB: " + Megabytes, "Retry", "Quit", 0, 0, 1 );
810                PartitionMB[i] = Megabytes;
811               
812                // Add info to partition list box.
813                listPartitionBox->insertItem("/dev/" + device + "s" + tmp.setNum(i) + ": " + Megabytes + " MB "  + Buffer);
814
815                StartBlock = BlockLine.section(" ", 1, 1);
816                StartBlock.truncate(StartBlock.length() -1 );
817
818                PartitionStartBlk[i] = StartBlock;
819
820                //QMessageBox::warning( this, "Msg",  "StartBlock: " + StartBlock , "Retry", "Quit", 0, 0, 1 );
821                TotalBlocks = BlockLine.section(" ", 3, 3);
822
823                PartitionTotalBlk[i] = TotalBlocks;
824
825                //QMessageBox::warning( this, "Msg",  "TotalBlock: " + TotalBlocks , "Retry", "Quit", 0, 0, 1 );
826
827            }
828
829
830            i++;
831        }
832
833
834   
835           
836           
837        }
838        file.close();
839       
840       
841        // Now check for any additional free space on this drive
842        // KPM 8-12-08, change method to determine size of disk
843        //tmp = listDriveBox->currentText();
844        //tmp.remove(0, tmp.find(" ") + 1);
845        //tmp.truncate(tmp.find("MB"));
846        tmp = BlocksToMB(TotalDriveBlocks);
847        TotalDriveMB = tmp.toLongLong();
848        //QMessageBox::warning( this, "Msg",  "Drive MB: " + tmp , "Retry", "Quit", 0, 0, 1 );
849       
850               AvailMB = TotalDriveMB;
851        tmpLong = 63;
852       
853        i = 1;
854        while ( ! PartitionMB[i].isEmpty() ) {
855           
856            AvailMB = AvailMB - PartitionMB[i].toLongLong();
857            tmpLong = tmpLong + PartitionTotalBlk[i].toLongLong();
858           
859           
860            i++;
861        }
862       
863        //QMessageBox::warning( this, "Msg",  "Avail MB: " + Buffer.setNum(AvailMB) , "Retry", "Quit", 0, 0, 1 );
864       
865        if ( AvailMB > 1  && i <= 4 && usingExtended == 0)
866        {           
867                PartitionMB[i] = tmp.setNum(AvailMB);
868                PartitionStartBlk[i] = tmp.setNum(tmpLong);
869                PartitionTotalBlk[i] = tmp.setNum(DriveBlks - tmpLong);
870                // Add info to partition list box.
871                listPartitionBox->insertItem("/dev/" + device + "s" + tmp.setNum(i) + ": " + PartitionMB[i] + " MB "  + "Free Space");
872        }
873       
874       
875       
876    }
877}
878
879
880
881void PCInstall::useEntireDiskSlot()
882{
883     // Make sure to set flag to regenerate slice layout for custom partitions
884    regenCustomSlices = 1;
885   
886    if ( checkBoxEntireDisk->isChecked() )
887    {
888        listPartitionBox->setEnabled(FALSE);
889        setNextEnabled(currentPage(), TRUE);
890    } else { 
891        listPartitionBox->setEnabled(TRUE);
892        setNextEnabled(currentPage(), FALSE);
893        checkPartitionSelectionSlot();
894    }
895
896}
897
898
899void PCInstall::checkPartitionSelectionSlot()
900{
901   // Make sure to set flag to regenerate slice layout for custom partitions
902   regenCustomSlices = 1;
903   
904    textPartInfo->setText("");
905    int SelPartition;
906    QString tmp;
907    Q_LLONG PartMB;
908   
909    int item = listPartitionBox->currentItem();
910 
911   
912    if ( item == -1 )
913    {
914        setNextEnabled(currentPage(), FALSE);
915        return;
916    }
917   
918        tmp= listPartitionBox->currentText();
919        tmp.truncate(tmp.find(":") );
920        tmp.remove(0, tmp.length() -1 );
921        SelPartition = tmp.toInt();
922   
923   
924      // item++;
925     //QMessageBox::warning( this, "Msg",  "MB" + PartitionMB[SelPartition], "Retry", "Quit", 0, 0, 1 );
926     PartMB = PartitionMB[SelPartition].toLongLong();
927     
928
929    if ( PartMB < 4000 )
930   {
931        textPartInfo->setText(tr("Error: PC-BSD needs a partition with at least 4GB of space."));
932        setNextEnabled(currentPage(), FALSE);
933        return;
934    }
935
936    setNextEnabled(currentPage(), TRUE);
937   
938}
939
940
941void PCInstall::startFreshInstall()
942{
943    QString Geom;
944    QString tmp;
945    int item = listDriveBox->currentItem();
946    QString device = Drives[item];
947   
948    // Get the current partition
949    int PartNum = 1;
950   
951
952   
953    // We are setting up entire drive with PC-BSD
954    if (checkBoxEntireDisk->isChecked() )
955    {
956            // Set the PC-BSD Partition
957           RootPartition = "/dev/" + device + "s1";
958           
959        Geom = Sanitize_Bios_Geom(DriveCyl, DriveHead, DriveSec, TotalDriveBlocks);
960       
961        QFile file2( "/tmp/fdiskconfig" );
962        if ( file2.open( IO_WriteOnly ) ) {
963            QTextStream stream2( &file2 );
964           // stream2 <<  "nonInteractive=YES\nnoWarn=YES\ndisk=" +device + "\ngeometry=" + Geom + "\npartition=all\nbootManager=boot\ndiskPartitionEditor\ndiskPartitionWrite";
965            stream2 << "g " + Geom + "\np       1       165     1       " + TotalDriveBlocks + "\na     1";
966            file2.close();
967       
968       
969        textFileProgress->setText(tr("Running fdisk on /dev/") + device);
970        installProgress->setProgress(2);
971        FormatDrive = new Q3Process(this);
972        FormatDrive->addArgument( "/usr/local/pcbsd/scripts/PCBSD.FormatDisk.sh" );
973        FormatDrive->addArgument( device );
974                connect( FormatDrive, SIGNAL(processExited()), this, SLOT(startCustomLabel()) );
975                if ( !FormatDrive->start() ) {
976          // error handling
977        //QMessageBox::warning( this, "PCBSD Installer",  SelectedDrive, "Retry", "Quit", 0, 0, 1 );
978                }
979
980       
981            } // End of File Open
982       
983    // Only setting up the partition with PC-BSD       
984    } else {
985       
986        // Get the current partition
987        QString PartNumText = listPartitionBox->currentText();
988        PartNumText.truncate(PartNumText.find(":") );
989        PartNumText.remove(0, PartNumText.length() -1 );
990        PartNum = PartNumText.toInt();
991   
992        // Set the PC-BSD Partition
993        RootPartition = "/dev/" + device + "s" + tmp.setNum(PartNum);
994
995       
996       
997            // If the partition is the first one, then set starting block to 63
998            if (PartNum == 1)
999           {
1000              PartitionStartBlk[1]="63";
1001           }
1002           
1003           
1004     // If we have the bootloader checkbox specified, go ahead and make the file now
1005    if ( checkBootloader->isChecked())
1006    {
1007            QFile file1( "/tmp/StampBoot.sh" );
1008            if ( file1.open( IO_WriteOnly ) ) {
1009                QTextStream stream1( &file1 );
1010                stream1 <<  "#!/bin/sh\nboot0cfg -B -v -o packet " + device;
1011                file1.close();
1012            }
1013       
1014    }
1015           
1016           
1017        // Now run the FormatPartition.sh script to set this partition type to 165(FBSD)
1018        textFileProgress->setText(tr("Running fdisk on ") + RootPartition);
1019        installProgress->setProgress(2);
1020        FormatPartition = new Q3Process(this);
1021        FormatPartition->addArgument( "/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh" );
1022        FormatPartition->addArgument( device );
1023        FormatPartition->addArgument( RootPartition );
1024       
1025                connect( FormatPartition, SIGNAL(processExited()), this, SLOT(startCustomLabel()) );
1026                if ( !FormatPartition->start() ) {
1027          // error handling
1028        //QMessageBox::warning( this, "PCBSD Installer",  SelectedDrive, "Retry", "Quit", 0, 0, 1 );
1029                }
1030           
1031           
1032    }
1033   
1034   
1035}
1036
1037
1038
1039
1040QString PCInstall::Sanitize_Bios_Geom( QString cyl, QString head, QString sec, QString block )
1041{
1042  int sane;
1043  sane = 1;
1044
1045  Q_LLONG Cyl = cyl.toLongLong();
1046  Q_LLONG Head = head.toLongLong();
1047  Q_LLONG Sec = sec.toLongLong();
1048  Q_LLONG Block = block.toLongLong();
1049
1050        if (Cyl > 1024)
1051                sane = 0;
1052
1053        if (Head > 16)
1054                sane = 0;
1055
1056        if (Sec > 63)
1057                sane = 0;
1058
1059        if (Cyl * Head * Sec != Block)
1060                sane = 0;
1061        if (sane)
1062                return cyl + "/" + head + "/" + sec;
1063
1064        /* First try something that IDE can handle */
1065        Sec = 63;
1066        Head = 16;
1067        Cyl = Block / (Sec * Head);
1068
1069        if (Cyl < 1024)
1070        {
1071            cyl.setNum(Cyl);
1072            head.setNum(Head);
1073            sec.setNum(Sec);
1074
1075             return cyl + "/" + head + "/" + sec;
1076
1077        }
1078
1079        /* Hmm, try harder... */
1080        /* Assume standard SCSI parameter */
1081        Head = 255;
1082        Cyl = Block / (Sec * Head);
1083
1084        cyl.setNum(Cyl);
1085        head.setNum(Head);
1086        sec.setNum(Sec);
1087
1088        return "c" + cyl + " h" + head + " s" + sec;
1089}
1090
1091
1092void PCInstall::readFormatDiskSlot()
1093{
1094
1095}
1096
1097
1098void PCInstall::startCustomLabel()
1099{
1100   
1101    int i = 2;
1102    QString PartLetter;
1103   
1104    // Use a custom disk label if the user selected it, or if we are using ZFS since we need a seperate /boot filesystem
1105     if ( (checkCustomPartition->isChecked() && checkCustomDiskSlice->isChecked()) || comboFileSystem->currentItem() == 3 )
1106    {
1107            QFile file( "/tmp/BSDLabel" );
1108            if ( file.open( IO_WriteOnly ) ) {
1109                QTextStream stream( &file );
1110                stream <<  "# " << RootPartition << ":\n";
1111                stream << "8 partitions:\n";
1112                stream << "#    size    offset  fstype          bsize   bps/cpg\n";
1113                stream << "a:   " + SliceMB[0] + "M     0       4.2BSD  0       0\n";
1114                stream << "b:   " + SliceMB[1] + "M     *       swap\n";
1115                stream << "c:    *      *       unused\n";
1116               
1117        while ( i < 10) {
1118           
1119            if ( SliceMB[i].isEmpty() )
1120            {
1121                break;
1122            } 
1123                       
1124                switch( i ) {
1125                case 2:
1126                    PartLetter = "d";
1127                    break;
1128                case 3:
1129                    PartLetter = "e";
1130                    break;
1131                case 4:
1132                    PartLetter = "f";
1133                    break;
1134                case 5:
1135                    PartLetter = "g";
1136                    break;
1137                case 6:
1138                    PartLetter = "h";
1139                    break;
1140                }       
1141               
1142                if ( SliceMB[i + 1].isEmpty() )
1143                {
1144                    stream << PartLetter +":    *       *       4.2BSD\n";
1145                } else {
1146                    stream << PartLetter +":    " + SliceMB[i] + "M             *       4.2BSD\n";
1147                }
1148               
1149                i++;
1150            }
1151                file.close();
1152            }
1153       
1154       
1155    } else {
1156       
1157
1158             // Use the standard disk label for a desktop install       
1159            QFile file( "/tmp/BSDLabel" );
1160            if ( file.open( IO_WriteOnly ) ) {
1161                QTextStream stream( &file );
1162                stream <<  "# " << RootPartition << ":\n";
1163                stream << "8 partitions:\n";
1164                stream << "#    size    offset  fstype          bsize   bps/cpg\n";
1165                stream << "a:   *       0       4.2BSD  0       0\n";
1166                stream << "b:   512M    *       swap\n";
1167                stream << "c:    *      *       unused\n";
1168
1169                file.close();
1170            }
1171       
1172       
1173    }
1174   
1175   
1176       
1177            textFileProgress->setText(tr("Writing BSD Label to ") + RootPartition);
1178            installProgress->setProgress(3);
1179            WriteBSDLab = new Q3Process( this );
1180            WriteBSDLab->addArgument( "bsdlabel" );
1181            WriteBSDLab->addArgument( "-R" );
1182            WriteBSDLab->addArgument( "-B" );
1183            WriteBSDLab->addArgument( RootPartition );
1184            WriteBSDLab->addArgument( "/tmp/BSDLabel" ); 
1185                   
1186            connect( WriteBSDLab, SIGNAL(processExited()), this, SLOT(RunNewfsSlot() ) );
1187           // QMessageBox::warning( this, "PCBSD Installer",  "running bsdlabel", "Retry", "Quit", 0, 0, 1 );
1188            if ( !WriteBSDLab->start() ) {
1189//
1190            }
1191   
1192
1193}
1194
1195
1196void PCInstall::RunNewfsSlot()
1197{
1198    QString tmp;
1199     // QMessageBox::warning( this, "PCBSD Installer",  "running newfs", "Retry", "Quit", 0, 0, 1 );
1200   
1201       textFileProgress->setText(tr("Running newfs on ") + RootPartition);
1202       installProgress->setProgress(4);
1203       NewFSProc = new Q3Process( this );
1204       NewFSProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.NewFS.sh" );
1205       NewFSProc->addArgument( RootPartition );
1206       NewFSProc->addArgument( tmp.setNum(comboFileSystem->currentItem()) );
1207       
1208    connect( NewFSProc, SIGNAL(processExited()), this, SLOT(MountPartSlot() ) );
1209
1210    if ( !NewFSProc->start() ) {
1211
1212    }
1213       
1214       
1215}
1216
1217
1218void PCInstall::MountPartSlot()
1219{
1220    QString tmp;
1221   
1222    textFileProgress->setText(tr("Mounting drive ") + RootPartition);
1223    installProgress->setProgress(5);
1224         int i = 2;
1225         
1226    // Check if we need to create the /tmp/encSwap file
1227    if (checkEncryptedSwap->isChecked() )
1228    {
1229            QFile file( "/tmp/encSwap" );
1230            if ( file.open( IO_WriteOnly ) ) {
1231                QTextStream stream( &file );
1232                stream <<  "Y";
1233                file.close();
1234            }
1235
1236    }
1237         
1238
1239    //Setup Process to mount the root partition
1240    MountDisk = new Q3Process( this );
1241    MountDisk->addArgument( "/usr/local/pcbsd/scripts/PCBSD.MountDisk.sh" );
1242    MountDisk->addArgument( RootPartition );
1243    MountDisk->addArgument( tmp.setNum(comboFileSystem->currentItem()) );
1244
1245
1246
1247    while ( ! SliceMnt[i].isEmpty() )
1248    {
1249        MountDisk->addArgument( SliceMnt[i] );
1250        i++;
1251    }
1252
1253
1254
1255
1256    connect( MountDisk, SIGNAL(processExited()), this, SLOT(finishedMountSlot() ) );
1257
1258    if ( !MountDisk->start() ) {
1259        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting Mount", "Retry", "Quit", 0, 0, 1 );
1260    }
1261     
1262     
1263}
1264
1265
1266void PCInstall::finishedMountSlot()
1267{
1268      startTarExtractSlot();
1269}
1270
1271
1272void PCInstall::customDiskSliceSlot( bool ok )
1273{
1274   
1275    if ( ok )
1276    {
1277        listViewSlices->setEnabled(TRUE);
1278        pushSliceAdd->setEnabled(TRUE);
1279        pushSliceEdit->setEnabled(TRUE);
1280        pushSliceRemove->setEnabled(TRUE);
1281    } else {
1282        listViewSlices->setEnabled(FALSE);
1283        pushSliceAdd->setEnabled(FALSE);
1284        pushSliceEdit->setEnabled(FALSE);
1285        pushSliceRemove->setEnabled(FALSE);
1286    }
1287
1288}
1289
1290
1291void PCInstall::FinishedMountCDSlot()
1292{
1293    if(MountCD->normalExit() && MountCD->exitStatus() == 0 )
1294    {
1295      // Check if we are using a DVD or a CD
1296      QFile testDVD("/tmp/foundDVD");
1297      if ( testDVD.exists() )
1298      {
1299        usingDVDmedia = 1;
1300      } else {
1301        usingDVDmedia = 0;
1302      }
1303
1304      // Now start the install / update
1305      if ( radioFreshInstall->isChecked() )
1306       {
1307        // Start normal install
1308        startFreshInstall();
1309       } else {
1310        startUpdateProcess();
1311       }
1312       
1313       
1314    } else {
1315       
1316        switch( QMessageBox::warning( this, tr("CD Mount Error"), tr("Error: Could not load the install disc. Please check that the CD/DVD is in the drive.\n Press OK to try again, or Cancel to reboot the system."), tr("OK"), tr("Cancel"), 0, 0, 1 ) ) {
1317             case 0: // The user clicked the OK again button or pressed Enter
1318                startMountCD();
1319                 break;
1320             case 1: // The user clicked the Quit or pressed Escape
1321                  exit(1);
1322                 break;
1323             }
1324    }
1325   
1326   
1327}
1328
1329
1330// Function which calculates the total size of our progress bar, and sets it
1331void PCInstall::calcProgressBarSize()
1332{
1333    int totalLength = 0;
1334
1335     QString line;
1336   
1337    // Get the size of the first lzma file
1338    QFile file( "/usr/local/pcbsd/scripts/PCBSD.ExtractSize" );
1339    if ( file.open( IO_ReadOnly ) ) {
1340        QTextStream stream( &file );
1341        line = stream.readLine(); // line of text excluding '\n'
1342        totalLength = totalLength + line.toInt();
1343        file.close();
1344    }
1345
1346
1347    // Get the lzma2 size now
1348    QFile file1( "/usr/local/pcbsd/scripts/PCBSD.ExtractSize2" );
1349    if ( file1.open( IO_ReadOnly ) ) {
1350        QTextStream stream1( &file1 );
1351        line = stream1.readLine(); // line of text excluding '\n'
1352        totalLength = totalLength + line.toInt();
1353        file1.close();
1354    }
1355       
1356       
1357
1358    // Get the number of components we have
1359    for ( int i = 0; !ComponentDir[i].isEmpty(); i++ )
1360    {
1361       if ( ComponentSelected[i] == 1 )
1362          totalLength++;
1363    }
1364
1365
1366    // Set our current progress variable to 0
1367    ExtractSize = 0;
1368
1369
1370    // Add a few extra steps for misc items, like kernel setup, etc
1371    totalLength = totalLength + 10;
1372   
1373    // Set our total steps to the found size
1374    installProgress->setTotalSteps(totalLength);
1375   
1376    // Zero out the progress bars now
1377    installProgress->setProgress(0);
1378
1379}
1380
1381
1382void PCInstall::startMountCD()
1383{
1384
1385   
1386    textFileProgress->setText(tr("Mounting CD..."));
1387   
1388      //Setup Process to mount the root partition
1389    MountCD = new Q3Process( this );
1390    MountCD->addArgument( "/usr/local/pcbsd/scripts/PCBSD.MountCD.sh" );
1391
1392    connect( MountCD, SIGNAL(processExited()), this, SLOT(FinishedMountCDSlot() ) );
1393
1394    if ( !MountCD->start() ) {
1395        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting MountCD", "Retry", "Quit", 0, 0, 1 );
1396    }
1397}
1398
1399
1400void PCInstall::startTarExtractSlot()
1401{
1402 
1403
1404    TarProc = new Q3Process( this );
1405    TarProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.InstallCD1.sh" );
1406   
1407
1408    connect( TarProc, SIGNAL(readyReadStdout() ), this, SLOT(readTarStdoutSlot() ) );
1409    connect( TarProc, SIGNAL(processExited()), this, SLOT(TarFinishedSlot() ) );
1410
1411    if ( !TarProc->start() ) {
1412        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting PCBSD.InstallCD1.sh"), tr("Retry"), tr("Quit"), 0, 0, 1 );
1413    } 
1414}
1415
1416
1417
1418void PCInstall::readTarStdoutSlot()
1419{
1420    QString Buffer;
1421    QString tmp;
1422
1423    // Loop while getting input
1424    while (TarProc->canReadLineStdout() )
1425    {
1426        // Read the line
1427        Buffer = TarProc->readLineStdout();
1428       
1429        // Remove the "x" from the start
1430        if ( Buffer.find("x", 0) == 0)
1431        {
1432            Buffer.remove(0, 3);
1433            tmp = Buffer;
1434            Buffer = tmp;
1435        } 
1436       
1437       
1438        // Set the Label to current file
1439        textFileProgress->setText(Buffer);
1440        // Get size for Progress Bar
1441        ExtractSize = ExtractSize + 1;
1442        installProgress->setProgress(ExtractSize);
1443
1444    } // End while loop
1445}
1446
1447
1448void PCInstall::setupUsersSlot()
1449{
1450
1451    int i = 0;
1452   
1453    textFileProgress->setText(tr("Setting up Users..."));
1454    ExtractSize = ExtractSize + 1;
1455    installProgress->setProgress(ExtractSize);
1456   
1457    QFile userList( "/mnt/tmp/users");
1458    if ( userList.open( IO_WriteOnly) ) {
1459        QTextStream userStream( &userList);
1460       
1461       
1462   // Save the root password
1463   QFile filePassRoot( "/mnt/tmp/setPass-Root" );
1464    if ( filePassRoot.open( IO_WriteOnly ) ) {
1465        QTextStream streamPassRoot( &filePassRoot );
1466        streamPassRoot << linePassword->text();
1467        filePassRoot.close();
1468    }
1469   
1470   // Set our variables for the user passwords
1471   QFile filePassUser; 
1472   QString fileNameUser, tmp;
1473
1474   QFile file( "/mnt/tmp/setPass" );
1475    if ( file.open( IO_WriteOnly ) ) {
1476        QTextStream stream( &file );
1477        stream << "cat /tmp/setPass-Root | pw usermod root -h 0\n" ;
1478        stream << "rm /tmp/setPass-Root\n" ;
1479        while ( i < 100)
1480        {
1481       
1482            if ( AddUserName[i] == "" )
1483            {
1484                break;   
1485            }
1486   
1487            // Save the password text to file
1488            fileNameUser = "/mnt/tmp/setPass-User" + tmp.setNum(i);
1489            filePassUser.setFileName( fileNameUser );
1490            if ( filePassUser.open( IO_WriteOnly ) ) {
1491                QTextStream streamPassUser( &filePassUser );
1492                streamPassUser << AddPassword[i];
1493                filePassUser.close();
1494            }
1495   
1496               
1497            stream << "cat /tmp/setPass-User" + tmp.setNum(i) + " | pw useradd -n " << AddUserName[i] << " -G wheel,operator -h 0 -s " + AddShell[i] + " -d /home/" << AddUserName[i] << " -m -c \"" << AddRealName[i] << "\"\n";
1498            stream << "rm /tmp/setPass-User" + tmp.setNum(i) + "\n";
1499       
1500            stream << "chown -R " << AddUserName[i] << " /home/" << AddUserName[i] << "\n";
1501            stream << "chgrp -R " << AddUserName[i] << " /home/" << AddUserName[i] << "\n";
1502            userStream << AddUserName[i] << "\n";
1503   
1504                    i++;
1505        }
1506   
1507
1508
1509        file.close();
1510     }
1511
1512          userList.close();
1513     }
1514    AddUserProc = new Q3Process( this );
1515    AddUserProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.AddUser.sh" );
1516   
1517    if ( checkAutoLogon->isChecked() ) {
1518        AddUserProc->addArgument( "0" );
1519    } else {
1520        AddUserProc->addArgument( "2" );
1521    }
1522   
1523
1524    connect( AddUserProc, SIGNAL(processExited()), this, SLOT(setupTimeSlot() ) );
1525
1526
1527    if ( !AddUserProc->start() ) {
1528        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting AddUserProc"), tr("Retry"), tr("Quit"), 0, 0, 1 );
1529    }
1530   
1531
1532}
1533
1534
1535void PCInstall::slotRunLastScripts()
1536{
1537    QString tmp;
1538    QString tmp2;
1539   
1540    textFileProgress->setText(tr("Running System config..."));
1541    ExtractSize = ExtractSize + 1;
1542    installProgress->setProgress(ExtractSize);
1543
1544    tmp = listBoxLang->currentText();
1545    tmp.remove(0, tmp.find("(") + 1 );
1546    tmp.truncate(tmp.find(")") );
1547   
1548   // Start with the update system config script
1549   SystemConfig= new Q3Process( this );
1550   SystemConfig->addArgument( "/usr/local/pcbsd/scripts/PCBSD.SysConfig.sh" );
1551   SystemConfig->addArgument( tmp );
1552
1553   if ( checkAllowBSDSTATS->isChecked() )
1554   {
1555     SystemConfig->addArgument("1");
1556   } else {
1557     SystemConfig->addArgument("0");
1558   }
1559
1560
1561    connect( SystemConfig, SIGNAL(processExited()), this, SLOT(setupFinishedSlot() ) );
1562
1563    if ( !SystemConfig->start() ) {
1564        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting SystemConfig"), tr("Retry"), tr("Quit"), 0, 0, 1 );
1565    }
1566   
1567   
1568}
1569
1570
1571
1572
1573void PCInstall::setupFinishedSlot()
1574{
1575    showPage(page(10));
1576    setBackEnabled(currentPage(), FALSE);
1577    setFinishEnabled(currentPage(), TRUE);
1578}
1579
1580
1581void PCInstall::TarFinishedSlot()
1582{
1583    if ( ! TarProc->normalExit() || TarProc->exitStatus() != 0 )
1584    {
1585            QMessageBox::critical( 0, "Install Error!",
1586        tr("An error occured while extracting the system image! Please check the install CD, or try selecting 'Safe Mode' \nwhen the installation CD begins booting. The system will now reboot.") );
1587            exit(1);
1588     } else {
1589         if ( usingDVDmedia == 0 )
1590         {
1591           slotStartMountCD2();
1592         } else {
1593           // Looks like we have a DVD, lets install from it now
1594           slotInstallCD2();
1595         }
1596     }
1597}
1598
1599
1600
1601void PCInstall::populateSlices()
1602{
1603    int i = 0;
1604    Q_LLONG UsedMB = 0;
1605    Q_LLONG AvailMB = 0;
1606    QString PartLetter;
1607    QString Device;
1608    QString tmp;
1609    QString Type;
1610   
1611    listViewSlices->clear();
1612
1613   
1614    if ( checkBoxEntireDisk->isChecked() )
1615    {
1616        tmp= listDriveBox->currentText();
1617        tmp.truncate(tmp.find(":") );
1618        Device = tmp + "s1";       
1619    } else {
1620        tmp= listPartitionBox->currentText();
1621        tmp.truncate(tmp.find(":") );
1622        Device = tmp;   
1623    }
1624   
1625
1626   
1627   
1628    while (i < 10) {
1629        if ( SliceMB[i].isEmpty() )
1630        {
1631         break;   
1632        }
1633       
1634        UsedMB = UsedMB + SliceMB[i].toLongLong();
1635       
1636        switch( i ) {
1637           case 0:
1638               PartLetter = "a";
1639               tmp = comboFileSystem->currentText();
1640               if ( tmp.indexOf("ZFS") == -1)
1641               {
1642                 Type = tmp; 
1643               } else {
1644                 Type = "UFS2";
1645               }
1646               break;
1647           case 1:
1648               PartLetter = "b";
1649               Type = "Swap";
1650               break;
1651           case 2:
1652               PartLetter = "d";
1653               Type = comboFileSystem->currentText();
1654               break;
1655           case 3:
1656               PartLetter = "e";
1657               Type = comboFileSystem->currentText();
1658               break;
1659           case 4:
1660               PartLetter = "f";
1661               Type = comboFileSystem->currentText();
1662               break;
1663           case 5:
1664               PartLetter = "g";
1665               Type = comboFileSystem->currentText();
1666               break;
1667           case 6:
1668               PartLetter = "h";
1669               Type = comboFileSystem->currentText();
1670               break;
1671           }
1672       
1673       
1674        (void) new Q3ListViewItem( listViewSlices, Device + PartLetter, SliceMnt[i], SliceMB[i] + " MB", Type );
1675
1676       
1677       
1678        i++;
1679    }
1680   
1681   
1682    AvailMB = TotalSliceMB.toLongLong() - UsedMB;
1683   
1684    textSliceAvailSpace->setText(tmp.setNum(AvailMB) + tr("MB available out of ") + TotalSliceMB + tr("MB")); 
1685   
1686   
1687   
1688}
1689
1690
1691// Converts Blocksizes to MB
1692QString PCInstall::BlocksToMB( QString Blocks )
1693{
1694    Q_LLONG BlockNum = Blocks.toLongLong();
1695    Q_LLONG MBNum;
1696    QString MegaByte;
1697
1698    MBNum = BlockNum / 2048;
1699    MegaByte.setNum(MBNum);
1700    return MegaByte;
1701}
1702
1703
1704void PCInstall::setupInitialSlices()
1705{
1706    QString tmp;
1707    int SelPartition;
1708   
1709
1710        tmp= listPartitionBox->currentText();
1711        tmp.truncate(tmp.find(":") );
1712        tmp.remove(0, tmp.length() -1 );
1713        SelPartition = tmp.toInt();
1714   
1715   
1716    if ( checkBoxEntireDisk->isChecked() )
1717    {
1718        TotalSliceMB = BlocksToMB(TotalDriveBlocks);
1719    } else {
1720         
1721        TotalSliceMB = PartitionMB[SelPartition];           
1722    }
1723       
1724    // Check if we are using ZFS and create a 100MB /bootdir slice
1725    if ( comboFileSystem->currentItem() == 3 )
1726    {
1727            SliceMB[0] = "200";
1728            SliceMnt[0] = "/bootdir";
1729            SliceMB[1] = "512";
1730            SliceMnt[1] = "SWAP";
1731            SliceMB[2] = tmp.setNum((TotalSliceMB.toLongLong() - 712));
1732            SliceMnt[2] = "/";
1733            SliceMB[3] = "";
1734            SliceMnt[3] = "";
1735            SliceMB[4] = "";
1736            SliceMnt[4] = "";
1737            SliceMB[5] = "";
1738            SliceMnt[5] = "";
1739    } else {
1740        SliceMB[0] = tmp.setNum((TotalSliceMB.toLongLong() - 512));
1741        SliceMnt[0] = "/";
1742        SliceMB[1] = "512";
1743        SliceMnt[1] = "SWAP";
1744        SliceMB[2] = "";
1745        SliceMnt[2] = "";
1746        SliceMB[3] = "";
1747        SliceMnt[3] = "";
1748        SliceMB[4] = "";
1749        SliceMnt[4] = "";
1750        SliceMB[5] = "";
1751        SliceMnt[5] = ""; 
1752   }
1753
1754   
1755       
1756}
1757
1758
1759void PCInstall::sliceAddSlot()
1760{
1761    int i = 0;
1762    Q_LLONG UsedMB = 0;
1763    Q_LLONG AvailMB = 0;
1764    QString tmp;
1765   
1766    while ( ! SliceMB[i].isEmpty() )
1767    {
1768        UsedMB = UsedMB + SliceMB[i].toLongLong();
1769        i++;
1770    }
1771
1772    // The total available blocks
1773    AvailMB = TotalSliceMB.toLongLong() - UsedMB;
1774    tmp.setNum(AvailMB);
1775   
1776    if ( AvailMB > 0 )
1777    {
1778
1779        // Launch our AddPartitionDialog to add a new device
1780        AddPartDialog = new AddPartitionDialog();
1781        connect( AddPartDialog, SIGNAL(Saved(QString &, QString &)), this, SLOT(AddLabelSlot(QString &, QString &)) );
1782        AddPartDialog->ProgramInit(tmp);
1783        AddPartDialog->SetEditValues( "1", tr("Add Partition"), tr("Please select the size you wish to use for this new partition."), "/" );
1784        AddPartDialog->EnableMountBox();
1785        AddPartDialog->exec();
1786
1787    }
1788}
1789
1790
1791void PCInstall::sliceEditSlot()
1792{
1793   
1794    int i = 0;
1795    Q_LLONG UsedMB = 0;
1796    Q_LLONG AvailMB = 0;
1797    QString tmp;
1798    int SelPart = 0;
1799
1800    if ( listViewSlices->currentItem() != 0)
1801    {
1802       
1803        while ( ! SliceMB[i].isEmpty() )
1804        {
1805            UsedMB = UsedMB + SliceMB[i].toLongLong();
1806
1807            if ( listViewSlices->currentItem()->text(1) == SliceMnt[i] )
1808            {
1809                SelPart = i;
1810            }
1811
1812            i++;
1813        }
1814
1815        // The total available blocks
1816        AvailMB = (TotalSliceMB.toLongLong() - UsedMB) + SliceMB[SelPart].toLongLong();
1817        tmp.setNum(AvailMB);
1818
1819        // Save the item we are working on
1820        CurrentEditLabel = SelPart;
1821
1822        // Launch our AddPartitionDialog to edit the device
1823        AddPartDialog = new AddPartitionDialog();
1824        connect( AddPartDialog, SIGNAL(Saved(QString &)), this, SLOT(EditLabelSlot(QString &)) );
1825        AddPartDialog->ProgramInit(tmp);
1826        AddPartDialog->SetEditValues( SliceMB[SelPart], tr("Editing Partition"), tr("Please select the size you wish to allocate to this mount"), SliceMnt[SelPart] );
1827        AddPartDialog->exec();
1828
1829    }
1830
1831}
1832
1833
1834void PCInstall::sliceRemoveSlot()
1835{
1836    int i = 0;
1837    int copy = 0;
1838    QString PartLetter;
1839
1840    if ( listViewSlices->currentItem() != 0)
1841    {
1842        if ( listViewSlices->currentItem()->text(1) == "/" )
1843        {
1844            QMessageBox::information( this, tr("DiskLabel Error:"), tr("You cannot remove the '/' partition. ") );
1845            return;
1846        }
1847        if (listViewSlices->currentItem()->text(1) == "SWAP" )
1848        {
1849            QMessageBox::information( this, tr("DiskLabel Error:"), tr("You cannot remove the 'SWAP' partition. ") );
1850            return;
1851        }
1852        if (listViewSlices->currentItem()->text(1) == "/bootdir" )
1853        {
1854            QMessageBox::information( this, tr("DiskLabel Error:"), tr("You cannot remove the '/bootdir' partition. ") );
1855            return;
1856        }
1857
1858        while ( ! SliceMnt[i].isEmpty() )
1859        {
1860            if (SliceMnt[i] == listViewSlices->currentItem()->text(1) )
1861            {
1862                copy = 1;
1863            }
1864
1865            // Start moving over saved info
1866            if ( copy == 1)
1867            {
1868
1869                if (  SliceMB[i+1].isEmpty() ) {
1870                    SliceMB[i] = "";
1871                    SliceMnt[i] = "";
1872                } else {
1873                    SliceMnt[i] = SliceMnt[i+1];
1874                    SliceMB[i] = SliceMB[i+1];   
1875                }
1876            }
1877
1878            i++;
1879        }
1880
1881        populateSlices();
1882
1883    }
1884
1885}
1886
1887
1888void PCInstall::AddLabelSlot( QString &Blocks, QString &Mount )
1889{
1890    int i = 0;
1891    QString PartLetter;
1892   
1893    if (Mount == "/home" )
1894    {
1895        QMessageBox::information( this, tr("Invalid Partition"), tr("Warning: /home is a link to /usr/home. This entry will be adjusted.") );
1896        Mount = "/usr/home";
1897    }
1898   
1899    if (Mount == "/boot" )
1900    {
1901        QMessageBox::information( this, tr("Invalid Partition"), tr("Warning: The '/boot' directory must be on the '/' partition.") );
1902        return;
1903    }
1904
1905    while ( ! SliceMB[i].isEmpty() )
1906    {
1907        // Make sure we are not adding the same partition mount-point
1908        if ( SliceMnt[i] == Mount)
1909        {
1910           QMessageBox::information( this, tr("Error!"), tr("You already have a partition setup for this mount point!") );
1911           return;
1912        }
1913        i++;
1914    }
1915
1916
1917    switch( i ) {
1918                   case 2:
1919                       PartLetter = "d";
1920                       break;
1921                   case 3:
1922                       PartLetter = "e";
1923                       break;
1924                   case 4:
1925                       PartLetter = "f";
1926                       break;
1927                   case 5:
1928                       PartLetter = "g";
1929                       break;
1930                   case 6:
1931                       PartLetter = "h";
1932                       break;
1933                   }
1934
1935    if (PartLetter.isEmpty() )
1936    {
1937        QMessageBox::information( this, tr("Max Partitions:"), tr("You exceeded the max number of partitions.") );
1938        return;
1939    }
1940
1941   
1942
1943
1944    SliceMnt[i] = Mount;
1945    SliceMB[i] = Blocks;
1946
1947    populateSlices();
1948
1949}
1950
1951
1952void PCInstall::EditLabelSlot( QString &Blocks )
1953{
1954    SliceMB[CurrentEditLabel] = Blocks;
1955    populateSlices();
1956}
1957
1958
1959
1960void PCInstall::setupTimeSlot()
1961{
1962    QString tmp;
1963   
1964    textFileProgress->setText(tr("Setting up Timezone..."));
1965         ExtractSize = ExtractSize + 1;
1966         installProgress->setProgress(ExtractSize);
1967
1968         // Send our arguments to the timezone script
1969         TimeProc= new Q3Process( this );
1970         TimeProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.TimeZone.sh" );
1971         if ( checkTimeSync->isChecked() )
1972         {
1973             TimeProc->addArgument( "0" );
1974         } else {
1975             TimeProc->addArgument( "1" );
1976         }
1977         
1978         
1979         tmp = comboTZone->currentText();
1980         tmp.truncate(tmp.find(" "));
1981         
1982         TimeProc->addArgument(tmp);
1983         
1984          // Conect to the slot to finish up the install
1985          connect( TimeProc, SIGNAL(processExited()), this, SLOT(slotRunLastScripts() ) );
1986
1987         
1988
1989
1990         if ( !TimeProc->start() ) {
1991             QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting TimeZone.sh"), tr("Retry"), tr("Quit"), 0, 0, 1 );
1992         }
1993   
1994   
1995
1996}
1997
1998
1999
2000void PCInstall::readAvailUpgradesSlot()
2001{
2002    listPartitionBoxUpgrade->clear();
2003 
2004    QFile file( "/tmp/AvailUpgrades" );
2005    if ( file.open( IO_ReadOnly ) ) 
2006    {
2007        QTextStream stream( &file );
2008        QString line;
2009        while ( !stream.atEnd() ) 
2010        {
2011            line = stream.readLine(); // line of text excluding '\n'
2012           
2013            // Insert the string
2014            listPartitionBoxUpgrade->insertItem(line);
2015
2016        }
2017        file.close();
2018       
2019        textUpdatePart->setText("");
2020    } else {
2021        textUpdatePart->setText(tr("No existing PC-BSD partitions detected!"));
2022        setNextEnabled(currentPage(), FALSE);
2023    }
2024}
2025
2026
2027void PCInstall::checkPartUpgradeBox()
2028{
2029    int item = listPartitionBoxUpgrade->currentItem();
2030 
2031   
2032    if ( item == -1 )
2033    {
2034        setNextEnabled(currentPage(), FALSE);
2035    } else {
2036        setNextEnabled(currentPage(), TRUE);
2037    }
2038
2039}
2040
2041
2042void PCInstall::startUpdateProcess()
2043{
2044   
2045    QString tmp;
2046   
2047    tmp= listPartitionBoxUpgrade->currentText();
2048    tmp.truncate(tmp.find(":") - 1);
2049   
2050// Now run our scripts to remove pkgs and start upgrade
2051         //Setup Process to mount the root partition
2052    RunUpgradeProc = new Q3Process( this );
2053    RunUpgradeProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.MountUpgrade.sh" );
2054    RunUpgradeProc->addArgument( tmp );
2055
2056    connect( RunUpgradeProc, SIGNAL(processExited()), this, SLOT(startTarExtractSlot()) );
2057
2058    if ( !RunUpgradeProc->start() ) {
2059        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting MountCD", "Retry", "Quit", 0, 0, 1 );
2060    }
2061   
2062}
2063
2064void PCInstall::slotRunFinalScriptUpgrade()
2065{
2066    textFileProgress->setText(tr("Running System config..."));
2067    ExtractSize = ExtractSize + 1;
2068    installProgress->setProgress(ExtractSize);
2069
2070    // Start with the update system config script
2071   SystemConfig= new Q3Process( this );
2072   SystemConfig->addArgument( "/usr/local/pcbsd/scripts/PCBSD.SysConfig.sh" );
2073   SystemConfig->addArgument( "IGNORE" );
2074   SystemConfig->addArgument( "IGNORE" );
2075   SystemConfig->addArgument(tr("Start"));
2076
2077   if ( checkAllowBSDSTATS->isChecked() )
2078   {
2079     SystemConfig->addArgument("1");
2080   } else {
2081     SystemConfig->addArgument("0");
2082   }
2083
2084
2085   
2086
2087
2088     connect( SystemConfig, SIGNAL(processExited()), this, SLOT(upgradeFinishedSlot() ) );
2089    if ( !SystemConfig->start() ) {
2090        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting SystemConfig"), tr("Retry"), tr("Quit"), 0, 0, 1 );
2091    }
2092}
2093
2094
2095void PCInstall::upgradeFinishedSlot()
2096{
2097   
2098    showPage(page(10));
2099    setBackEnabled(currentPage(), FALSE);
2100    setFinishEnabled(currentPage(), TRUE);
2101}
2102
2103
2104void PCInstall::FinishedMountLangCDSlot()
2105{
2106   
2107    // If the CD mounted successfully
2108    if(FindLangCD->normalExit() && FindLangCD->exitStatus() == 0 )
2109    {
2110
2111         // Looks like we have CD2, lets install from it now
2112         slotInstallCD2();
2113       
2114    } else {
2115       
2116        switch( QMessageBox::warning( this, tr("CD Mount Error"), tr("Error: Could not locate CD #2. Please check that the CD is in the drive. Press OK to try again, or Cancel to abort install."), tr("OK"), tr("Cancel"), 0, 0, 1 ) ) {
2117             case 0: // The user clicked the OK again button or pressed Enter
2118                 slotStartMountCD2();
2119                 break;
2120             case 1: // The user clicked the Quit or pressed Escape
2121                 
2122               
2123                 exit(5);
2124                 return;
2125                 break;
2126             }
2127    }
2128}
2129
2130
2131
2132void PCInstall::readLangInstallSlot()
2133{
2134  QString Buffer;
2135
2136    // Loop while getting input
2137    while (AddLangFiles->canReadLineStdout() )
2138    {
2139        // Read the line
2140        Buffer = AddLangFiles->readLineStdout();
2141        // Check if we need to display the output and increment the progress bar
2142        if ( Buffer.find("CP:") != -1)
2143        {
2144            Buffer.remove(0, 3 );
2145            textFileProgress->setText(tr("Copying ") + Buffer);
2146            // Get size for Progress Bar
2147            ExtractSize = ExtractSize + 1;
2148            installProgress->setProgress(ExtractSize);
2149           
2150        }
2151       
2152        if (Buffer.find("PKG:") != -1 )
2153        {
2154            Buffer.remove(0,4 );
2155           
2156            textFileProgress->setText(tr("Installing ") + Buffer);
2157            // Get size for Progress Bar
2158            ExtractSize = ExtractSize + 1;
2159            installProgress->setProgress(ExtractSize);
2160        }
2161       
2162       
2163       
2164
2165
2166    } // End while loop
2167}
2168
2169
2170void PCInstall::checkUserLinesChanged( const QString & )
2171{
2172    bool ok = TRUE;
2173    textAcctNotify->setText("");
2174
2175    lineUserName->unsetPalette();
2176   
2177            // Check if we are missing  some values
2178    if ( lineUserName->text().isEmpty() )
2179    {
2180        textAcctNotify->setText("");
2181        ok = FALSE;
2182    }
2183     
2184    if ( lineFullName->text().isEmpty() )
2185    {
2186        textAcctNotify->setText("");
2187        ok = FALSE;
2188    }
2189   
2190    if ( lineUserPassword->text().isEmpty() )
2191    {
2192        textAcctNotify->setText("");
2193        ok = FALSE;
2194    }
2195   
2196   
2197   
2198    //Check username contains only letters and numbers
2199    if ((! passwordRegExp.exactMatch(lineUserName->text())) && (lineUserName->text() != "")) {
2200        textAcctNotify->setText(tr("Username may contain only letters and numbers!"));
2201        lineUserName->setPaletteBackgroundColor(colourRed);
2202        ok = FALSE;
2203    }
2204   
2205   
2206    if ( (lineUserPassword->text() != lineUserPassword2->text()) || lineUserPassword->text().isEmpty())
2207    {
2208        ok = FALSE;
2209    }
2210   
2211    QString Username = lineUserName->text();
2212   
2213        if ( Username == "root" || Username == "toor" || Username == "daemon" || Username == "operator" || Username == "bin" || Username == "tty" || Username == "kmenu" || Username == "games" || Username == "news" || Username == "man" || Username == "sshd" || Username == "smmsp" || Username == "mailnull" || Username == "bind" || Username == "proxy" || Username == "_pflog" || Username == "_dhcp" || Username == "pop" || Username == "www" || Username == "nobody" || Username == "cyrus" || Username == "cups")
2214    {
2215          ok = FALSE;   
2216          textAcctNotify->setText( tr("Error: The username \"" + Username + "\" is reserved."));
2217          lineUserName->setPaletteBackgroundColor(colourRed);
2218    }
2219   
2220   
2221   
2222   
2223   
2224    int i = 0;
2225    bool ok2 = TRUE;
2226   
2227    while ( i < 100)
2228    {
2229       
2230        if ( AddUserName[i] == "" )
2231        {
2232           break;   
2233        }
2234
2235        if(AddUserName[i] == lineUserName->text() )
2236        {
2237            ok2 = FALSE;
2238            break;
2239        }
2240
2241        i++;
2242    }
2243   
2244 
2245   
2246   
2247    if ( ok)
2248    {
2249        if (ok2)
2250        {
2251          pushAddUser->setEnabled(TRUE);
2252          pushApplyUser->setEnabled(FALSE);
2253                } else {
2254          pushAddUser->setEnabled(FALSE);
2255          pushApplyUser->setEnabled(TRUE);
2256                }
2257       
2258     } else {
2259         pushApplyUser->setEnabled(FALSE);
2260         pushAddUser->setEnabled(FALSE);
2261     }
2262   
2263
2264}
2265
2266
2267void PCInstall::listBoxUsersChanged()
2268{
2269    int i;
2270   
2271    if ( listBoxUsers->currentItem() != -1)
2272    {
2273        i = listBoxUsers->currentItem();
2274        lineUserName->setText(AddUserName[i]);
2275        lineFullName->setText(AddRealName[i]);
2276        lineUserPassword->setText(AddPassword[i]);     
2277        lineUserPassword2->setText(AddPassword[i]);
2278       
2279        if ( AddShell[i] == "/bin/csh")
2280        {
2281            comboShell->setCurrentItem(0);
2282        } else if(AddShell[i] == "/bin/tcsh") {
2283            comboShell->setCurrentItem(1);
2284        } else if(AddShell[i] == "/bin/sh") {
2285            comboShell->setCurrentItem(2);
2286        } else if(AddShell[i] == "/PCBSD/local/bin/bash") {
2287            comboShell->setCurrentItem(3);
2288        }
2289       
2290       
2291       
2292    }
2293}
2294
2295
2296void PCInstall::applyUserButton()
2297{
2298    QString Shell;
2299    int i;
2300   
2301    if ( listBoxUsers->currentItem() != -1)
2302    {
2303       
2304      i = listBoxUsers->currentItem(); 
2305      AddUserName[i] = lineUserName->text();
2306      AddRealName[i] = lineFullName->text();
2307      AddPassword[i]    = lineUserPassword->text();
2308     
2309    if ( comboShell->currentItem() == 0)
2310    {
2311        AddShell[i] = "/bin/csh"; 
2312    } else if ( comboShell->currentItem() == 1) {
2313        AddShell[i] = "/bin/tcsh";
2314    } else if ( comboShell->currentItem() == 2) {
2315        AddShell[i] = "/bin/sh";
2316    } else {
2317        AddShell[i] = "/PCBSD/local/bin/bash";
2318    }
2319     
2320     
2321    }
2322   
2323    refreshUsers();
2324    CheckAccountInfo();
2325    checkUserLinesChanged("");
2326   
2327}
2328
2329
2330
2331
2332void PCInstall::listBoxLangChanged()
2333{
2334    QString tmp;
2335
2336
2337
2338
2339   
2340    tmp = listBoxLang->currentText();
2341    tmp.remove(0, tmp.find("(") + 1 );
2342    tmp.truncate(tmp.find(")") );
2343   
2344   
2345    // Save the file
2346     QFile file( "/root/.langchange" );
2347    if ( file.open( IO_WriteOnly ) ) {
2348        QTextStream stream( &file );
2349        stream <<  tmp;
2350        file.close();
2351    }
2352   
2353    exit(3);     
2354
2355}
2356
2357
2358void PCInstall::changePromoAd()
2359{
2360   QString FileName;
2361   
2362    switch ( PromoAd )
2363    {
2364        case 1:
2365            FileName = "/usr/local/pcbsd/graphics/secure.png";
2366            textLabelAd->setText(tr("Secure by design"));
2367            PromoAd++;
2368                    break;
2369        case 2:
2370            FileName = "/usr/local/pcbsd/graphics/movies.png";
2371            textLabelAd->setText(tr("Watch your favorite movies"));
2372            PromoAd++;
2373            break;
2374        case 3:
2375            FileName = "/usr/local/pcbsd/graphics/music.png";     
2376            textLabelAd->setText(tr("Listen to your music"));
2377            PromoAd++;
2378                    break;
2379        case 4:
2380            FileName = "/usr/local/pcbsd/graphics/schools-universities.png";
2381            textLabelAd->setText(tr("Ideal for schools and universities"));
2382            PromoAd++;
2383            break;
2384        case 5:
2385            FileName = "/usr/local/pcbsd/graphics/developer.png";
2386            textLabelAd->setText(tr("Developer-friendly platform"));
2387            PromoAd++;
2388                    break;
2389        case 6:
2390            FileName = "/usr/local/pcbsd/graphics/reliable.png";
2391            textLabelAd->setText(tr("Enterprise-class stability"));
2392            PromoAd++;
2393            break;
2394        case 7:
2395            FileName = "/usr/local/pcbsd/graphics/support.png";   
2396            textLabelAd->setText(tr("Outstanding commercial support"));
2397            PromoAd++;
2398                    break;
2399        case 8:
2400            FileName = "/usr/local/pcbsd/graphics/docs.png";
2401            textLabelAd->setText(tr("Check out the quick-guide"));
2402            PromoAd++;
2403            break;
2404        case 9:
2405            FileName = "/usr/local/pcbsd/graphics/forums.png";
2406            textLabelAd->setText(tr("Join the community"));
2407            PromoAd++;
2408            break;
2409         case 10:
2410            FileName = "/usr/local/pcbsd/graphics/pbis.png";
2411            textLabelAd->setText(tr("Install software with a click"));
2412            PromoAd = 1;
2413            break;
2414        default:
2415            PromoAd = 1;
2416            return;
2417            break;
2418    }
2419   
2420   
2421
2422   frameDisplayAd->setStyleSheet(QString::fromUtf8("background-image: url(" + FileName + ");"));
2423
2424    QTimer::singleShot( 15000, this, SLOT(changePromoAd()) );
2425   
2426   
2427}
2428
2429
2430void PCInstall::checkVmwareSystemSlot()
2431{
2432    // If we are NOT running on vmware
2433   if(CheckVMware->normalExit() && CheckVMware->exitStatus() == 1 )
2434    {
2435        QFont f( "Sans Serif", 11);
2436        //setFont( f );   
2437    }
2438   
2439}
2440
2441
2442
2443
2444
2445void PCInstall::listBoxLayoutChanged()
2446{
2447    /*
2448    QString tmp;
2449   
2450    tmp = listBoxKeyLayout->currentText();
2451    tmp.truncate(tmp.find(" ") );
2452   
2453        // Start with the update system config script
2454   SetKeyboard= new Q3Process( this );
2455   SetKeyboard->addArgument( "/usr/local/pcbsd/scripts/PCBSD.SetKeyboard.sh" );
2456   SetKeyboard->addArgument( tmp );
2457   
2458    if ( !SetKeyboard->start() ) {
2459        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting SetKeyboard.sh"), tr("Retry"), tr("Quit"), 0, 0, 1 );
2460    }
2461   
2462    */
2463}
2464
2465void PCInstall::accept()
2466{
2467 exit(0);
2468
2469}
2470
2471
2472
2473
2474void PCInstall::back()
2475{
2476
2477        QString Page = title( currentPage() );
2478//    QMessageBox::warning( this, tr("PCBSD Installer"), Page, tr("Retry"), tr("Quit"), 0, 0, 1 );
2479   
2480    if ( Page == tr("Select Language and Keyboard") ) // Page 0
2481    {
2482       
2483    }
2484   
2485     if ( Page == tr("License") ) // Page 1
2486    {
2487        // Go back to the first page
2488         showPage(page(0));
2489    }
2490   
2491   
2492    if ( Page == tr("Install or Update") ) // Page 2
2493    {
2494         showPage(page(1));
2495    }
2496   
2497
2498    if ( Page == tr("User Accounts") )  // Page 3
2499    {
2500         showPage(page(2));     
2501    }
2502   
2503      if ( Page == tr("Disk Selection") ) // Page 4
2504    {
2505          showPage(page(3));
2506    }
2507   
2508   
2509     if ( Page == tr("Advanced Disk Setup") ) // Page 5
2510    {
2511          showPage(page(4));
2512    }
2513   
2514   
2515    if ( Page == tr("Select Update Partition") ) // Page 6
2516    {
2517         showPage(page(2) ); 
2518
2519    }
2520   
2521     if ( Page == tr("System Components") )  // Page 7
2522    {
2523        // If the user wanted to  upgrade, jump to that screen
2524        if ( ! radioFreshInstall->isChecked() )
2525        {
2526            showPage(page(6));
2527            return;
2528        } else {
2529            if ( checkCustomPartition->isChecked() )
2530            {
2531             showPage(page(5) );
2532            } else {
2533             showPage(page(4) );
2534            }
2535        }
2536    }
2537   
2538   
2539    if ( Page == tr("Start Basic Install") ) // Page 8
2540    {
2541        showPage(page(7));
2542    }
2543   
2544    if ( Page == tr("Installing PC-BSD") ) // Page 9
2545    {
2546       
2547    }
2548   
2549    if ( Page == tr("Installation Finished!") ) // Page 10
2550    {
2551
2552    }
2553   
2554}
2555
2556
2557
2558
2559void PCInstall::next()
2560{
2561    QString Page = title( currentPage() );
2562//    QMessageBox::warning( this, tr("PCBSD Installer"), Page, tr("Retry"), tr("Quit"), 0, 0, 1 );
2563   
2564    if ( Page == tr("Select Language and Keyboard") ) // Page 0
2565    {
2566        showPage(page(1));
2567    }
2568   
2569     if ( Page == tr("License") ) // Page 1
2570    {
2571         showPage(page(2));
2572    }
2573   
2574   
2575    if ( Page == tr("Install or Update") ) // Page 2
2576    {
2577        if ( radioNetworkInstall->isChecked() )
2578        {
2579            // Bring up the network dialog NIC selector
2580            networkDialog = new EditNetworkDialog();
2581            connect(networkDialog, SIGNAL(saved(QString, QString, QString, QString)), this, SLOT(nicSavedSlot(QString, QString, QString, QString)) );
2582            networkDialog->ProgramInit();
2583            networkDialog->exec();
2584            return; 
2585        } else {
2586           // Make sure we don't have a network file tripping us up
2587           system("rm /tmp/networkURL 2>/dev/null");
2588        }
2589       
2590       
2591        // If the user wanted to  upgrade, jump to that screen
2592        if ( ! radioFreshInstall->isChecked() )
2593        {
2594            showPage(page(6));
2595            return;
2596        } else {
2597            showPage(page(3) ); 
2598        }
2599    }
2600   
2601    if ( Page == tr("User Accounts") ) // Page 3
2602    {
2603
2604        showPage(page(4));
2605    }
2606   
2607      if ( Page == tr("Disk Selection") ) // Page 4
2608    {
2609        if ( checkCustomPartition->isChecked() )
2610        {
2611           showPage( page(5) );
2612        } else {
2613           showPage( page(7) );
2614        }
2615    }
2616   
2617     if ( Page == tr("Advanced Disk Setup") ) // Page 5
2618    {
2619        showPage(page(7));
2620    }
2621   
2622    if ( Page == tr("Select Update Partition") ) // Page 6
2623    {
2624        showPage(page(7));
2625    }
2626   
2627     if ( Page == tr("System Components") ) // Page 7
2628    {
2629        showPage(page(8) ); 
2630    }
2631     
2632    if ( Page == tr("Start Basic Install") ) // Page 8
2633    {
2634        showPage(page(9));
2635    }
2636   
2637    if ( Page == tr("Installing PC-BSD") ) // Page 9
2638    {
2639       
2640    }
2641   
2642    if ( Page == tr("Installation Finished!") ) // Page 10
2643    {
2644
2645    }
2646
2647}
2648
2649
2650void PCInstall::loadComponents()
2651{
2652       
2653        int found = 0;
2654   
2655        QDir d( "/usr/local/pcbsd/Components");
2656        QString CompFile;
2657
2658        QString CurLang = listBoxLang->currentText();
2659        CurLang.remove(0, CurLang.find("(") + 1 );
2660        CurLang.truncate(CurLang.find(")") );
2661
2662       
2663        d.setFilter( QDir::Dirs );
2664        d.setSorting( QDir::Name );
2665       
2666        for ( uint i = 0; i < d.count(); i++ )
2667        {
2668            CompFile="component.cfg."+CurLang;
2669            if (!QFile::exists("/usr/local/pcbsd/Components/" + d[i] + "/" + CompFile))
2670              CompFile="component.cfg";
2671            QFile file( "/usr/local/pcbsd/Components/" + d[i] + "/"+ CompFile );
2672            if ( file.open( IO_ReadOnly ) ) {
2673               
2674                ComponentDir[found]=d[i];
2675               
2676                QTextStream stream( &file );
2677                stream.setCodec("UTF-8");
2678                QString line;
2679                while ( !stream.atEnd() ) {
2680                    line = stream.readLine(); // line of text excluding '\n'
2681                   
2682                    if ( line.find("name:") == 0)
2683                    {
2684                        ComponentName[found] = line.replace("name: ", "");
2685                    }
2686                   
2687                    if ( line.find("description:") == 0)
2688                    {
2689                        ComponentDescr[found] = line.replace("description: ", "");
2690                    }
2691                   
2692                   
2693                }
2694                file.close();
2695
2696                ComponentSelected[found] = 0;   
2697                found++;
2698            }
2699        }
2700   
2701       
2702         refreshComponents();
2703       
2704}
2705
2706
2707// Adds a selected component when the user clicks the icon
2708void PCInstall::selectComponentSlot()
2709{
2710   
2711    int foundItem = 0;
2712        for ( int i = 0; i < 100; i++ )
2713        {
2714            if ( ComponentDir[i].isEmpty() )
2715            {
2716                break;
2717            }
2718           
2719               if ( ComponentSelected[i] == 0 )
2720               {
2721                   // Looks for the item selected and matches it in the list
2722                   if (listAvailComponents->isSelected(foundItem)) {
2723                       ComponentSelected[i] = 1;
2724                   }
2725                   foundItem++;
2726               }
2727           
2728        }
2729
2730   
2731    refreshComponents();
2732}
2733
2734// Removes a selected component when the user clicks the remove icon
2735void PCInstall::removeComponentSlot()
2736{
2737   
2738    int foundItem = 0;
2739   
2740        for ( int i = 0; i < 100; i++ )
2741        {
2742            if ( ComponentDir[i].isEmpty() )
2743            {
2744                break;
2745            }
2746           
2747               if ( ComponentSelected[i] == 1 )
2748               {
2749                   // Looks for the item selected and matches it in the list
2750                   if (listSelectedComponents->isSelected(foundItem)) {
2751                       ComponentSelected[i] = 0;
2752                   }
2753                   foundItem++;
2754               }
2755           
2756        }
2757   
2758    refreshComponents();
2759}
2760
2761
2762// Clears the components boxes and redraws them
2763void PCInstall::refreshComponents()
2764{
2765   
2766     listAvailComponents->clear();
2767     listSelectedComponents->clear();
2768     installComponents = 0;
2769       
2770        for ( int i = 0; i < 100; i++ )
2771        {
2772            if ( ComponentDir[i].isEmpty() )
2773            {
2774                break;
2775            }
2776
2777               // Insert a new item here,
2778               QImage *Icon = new QImage("/usr/local/pcbsd/Components/" + ComponentDir[i] + "/component.png");
2779               QPixmap PixmapIcon;
2780               PixmapIcon.convertFromImage(Icon->smoothScale(40,40));
2781             
2782
2783             //  listAvailComponents->insertItem(PixmapIcon, ComponentName[found] + " (" + ComponentDescr[found] + ")");
2784               if ( ComponentSelected[i] == 0 )
2785               {
2786                  listAvailComponents->insertItem(PixmapIcon, ComponentName[i] + " (" + ComponentDescr[i] + ")" ); 
2787               } else {
2788                  installComponents = 1;
2789                  listSelectedComponents->insertItem(PixmapIcon, ComponentName[i] + " (" + ComponentDescr[i] + ")" );
2790               }
2791
2792        }
2793
2794 //  listAvailComponents->setCurrentItem(0);
2795//   listSelectedComponents->setCurrentItem(0);
2796
2797}
2798
2799
2800void PCInstall::slotRunInstallComponents()
2801{
2802    textFileProgress->setText(tr("Installing additional components..."));
2803   
2804    int totalItems = 0;
2805   
2806    QFile file( "/tmp/loadComponents" );
2807    if ( file.open( IO_WriteOnly ) ) {
2808        QTextStream stream( &file );
2809
2810       for ( int i = 0; i < 100; i++ )
2811      {
2812            if ( ComponentDir[i].isEmpty() )
2813           {
2814        break;
2815            }
2816           
2817            if ( ComponentSelected[i] == 1 )
2818           {
2819        totalItems++;
2820        stream <<  ComponentDir[i] + "\n";
2821            }
2822           
2823      }
2824       
2825       
2826       
2827        file.close();
2828    }
2829       
2830 
2831      InstallComponentsProc = new Q3Process( this );
2832      InstallComponentsProc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.InstallCD3.sh" );
2833     
2834       // connect our slots
2835      connect( InstallComponentsProc, SIGNAL(processExited()), this, SLOT(slotFinishedInstallCD3() ) );
2836      connect( InstallComponentsProc, SIGNAL(readyReadStdout()), this, SLOT(readInstallComponentSlot() ) );
2837
2838         if ( !InstallComponentsProc->start() ) {
2839          QMessageBox::warning( this, "PCBSD Installer", "Failed Starting InstallComponentSlot", "Retry", "Quit", 0, 0, 1 );
2840        }
2841   
2842
2843   
2844
2845}
2846
2847
2848void PCInstall::readInstallComponentSlot()
2849{
2850  QString Buffer;
2851
2852    // Loop while getting input
2853    while (InstallComponentsProc->canReadLineStdout() )
2854    {
2855        // Read the line
2856        Buffer = InstallComponentsProc->readLineStdout();
2857        // Check if we need to display the output and increment the progress bar
2858
2859            textFileProgress->setText(tr("Installing ") + Buffer);
2860            // Get size for Progress Bar
2861            ExtractSize = ExtractSize + 1;
2862            installProgress->setProgress(ExtractSize);
2863    } // End while loop
2864   
2865}
2866
2867
2868void PCInstall::loadLicense()
2869{
2870    QString lic;
2871    QString line;
2872    QString tmp;
2873
2874    tmp = listBoxLang->currentText();
2875    tmp.remove(0, tmp.find("(") + 1 );
2876    tmp.truncate(tmp.find(")") );
2877    tmp="//usr/local/pcbsd/resources/license-"+tmp+".txt";
2878   
2879    if (!QFile::exists(tmp))
2880      tmp="//usr/local/pcbsd/resources/license-us.txt";
2881    QFile file(tmp); 
2882    if ( file.open( IO_ReadOnly ) ) {
2883        QTextStream stream( &file );
2884        stream.setCodec("UTF-8");
2885        QString line;
2886        while ( !stream.atEnd() ) {
2887            line = stream.readLine(); // line of text excluding '\n'
2888            lic = lic + line + "\n";
2889
2890            }
2891                   file.close();
2892     }
2893   
2894    textLicense->setText(lic);
2895   
2896}
2897
2898
2899void PCInstall::rootPasswordLineEditLostFocus()
2900{
2901    //Check if passwords match
2902    if (linePassword->text() != linePassword2->text() && ! linePassword->text().isEmpty() && ! linePassword2->text().isEmpty() )
2903    {
2904        textAcctNotify->setText(tr("Root passwords must match to continue."));
2905        linePassword->setPaletteBackgroundColor(colourRed);
2906        linePassword2->setPaletteBackgroundColor(colourRed);
2907    }
2908    else
2909    {
2910        textAcctNotify->setText(tr(""));
2911        linePassword->unsetPalette();
2912        linePassword2->unsetPalette();
2913    }
2914}
2915
2916
2917void PCInstall::userPasswordLineEditLostFocus()
2918{
2919    //Check if passwords match
2920    if (lineUserPassword->text() != lineUserPassword2->text() && ! lineUserPassword->text().isEmpty() && ! lineUserPassword2->text().isEmpty() )
2921    {
2922        lineUserPassword->setPaletteBackgroundColor(colourRed);
2923        lineUserPassword2->setPaletteBackgroundColor(colourRed);
2924        textAcctNotify->setText(tr("Error: User passwords do not match!"));
2925    }
2926    else
2927    {
2928        lineUserPassword->unsetPalette();
2929        lineUserPassword2->unsetPalette();
2930    }
2931   
2932}
2933
2934
2935void PCInstall::slotChangeKeyboard()
2936{
2937   
2938               QString layout, model, variant;
2939               
2940        layout = textKBLayout->text();
2941        model = textKBModel->text();
2942        variant = textKBVariant->text();
2943   
2944        layout.truncate(layout.find(" "));
2945        model.truncate(model.find(" "));
2946        variant.truncate(variant.find(" "));
2947       
2948        // Launch our AddPartitionDialog to add a new device
2949        keyboardDialog = new dialogKeyboard();
2950        connect(keyboardDialog, SIGNAL(saved(QString &, QString &, QString &)), this, SLOT(changeKeyboardSlot(QString &, QString &, QString &)) );
2951        keyboardDialog->programInit();
2952        keyboardDialog->setKeyboard( layout, model, variant);
2953        keyboardDialog->exec();
2954
2955}
2956
2957
2958void PCInstall::changeKeyboardSlot( QString &layout, QString &model, QString &variant )
2959{
2960    QString tmp, tmp2, tmp3;
2961   
2962    // Save the new settings to the GUI
2963    textKBLayout->setText(layout);
2964    textKBModel->setText(model);
2965    textKBVariant->setText(variant);
2966   
2967    // Now run the SetKeyboard.sh
2968    tmp = textKBLayout->text();
2969    tmp.truncate(tmp.find(" ") );
2970   
2971    tmp2 = textKBModel->text();
2972    tmp2.truncate(tmp2.find(" ") );
2973   
2974    tmp3 = textKBVariant->text();
2975    tmp3.truncate(tmp3.find(" ") );
2976   
2977
2978    // Start with the update system config script
2979   SetKeyboard= new Q3Process( this );
2980   SetKeyboard->addArgument( "/usr/local/pcbsd/scripts/PCBSD.SetKeyboard.sh" );
2981   SetKeyboard->addArgument( tmp );
2982   SetKeyboard->addArgument( tmp2 );
2983   SetKeyboard->addArgument( tmp3 );
2984   
2985    if ( !SetKeyboard->start() ) {
2986        QMessageBox::warning( this, tr("PCBSD Installer"),  tr("Failed Starting SetKeyboard.sh"), tr("Retry"), tr("Quit"), 0, 0, 1 );
2987    }
2988
2989   
2990}
2991
2992
2993void PCInstall::slotStartMountCD2()
2994{
2995    // Slot to start the mount process for CD2 to finish the install from it     
2996    textFileProgress->setText(tr("Unmounting CD #1..."));
2997   
2998    EjectCD = new Q3Process( this );
2999    EjectCD->addArgument( "/usr/local/pcbsd/scripts/PCBSD.EjectCD.sh" );
3000
3001     if ( !EjectCD->start() ) {
3002        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting EjectCD", "Retry", "Quit", 0, 0, 1 );
3003    }
3004   
3005   
3006   
3007    QMessageBox::information( this, tr("Insert CD #2"), tr("Insert CD #2 and click OK to continue. ") );
3008           
3009   
3010   
3011    textFileProgress->setText(tr("Mounting CD #2..."));
3012   
3013      //Setup Process to mount the root partition
3014    FindLangCD = new Q3Process( this );
3015    FindLangCD->addArgument( "/usr/local/pcbsd/scripts/PCBSD.MountCD2.sh" );
3016
3017    connect( FindLangCD, SIGNAL(processExited()), this, SLOT(FinishedMountLangCDSlot() ) );
3018
3019    if ( !FindLangCD->start() ) {
3020        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting MountCD2", "Retry", "Quit", 0, 0, 1 );
3021    }
3022
3023}
3024
3025
3026void PCInstall::slotInstallCD2()
3027{
3028     textFileProgress->setText(tr("Installing CD2..."));
3029   
3030     // We have mounted CD2, now lets kick off the installer for it
3031    installCD2proc = new Q3Process( this );
3032    installCD2proc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.InstallCD2.sh" );
3033    // Additional options will be here to indicate a server / desktop install
3034    if ( radioDesktop->isChecked() )
3035    {
3036        installCD2proc->addArgument("DESKTOP");
3037    } else {
3038        installCD2proc->addArgument("SERVER");
3039    }
3040
3041     connect( installCD2proc, SIGNAL(processExited()), this, SLOT(slotFinishedInstallCD2() ) );
3042
3043     connect( installCD2proc, SIGNAL(readyReadStdout()), this, SLOT(slotReadCD2Status() ) );
3044   
3045    if ( !installCD2proc->start() ) {
3046        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting PCBSD.InstallCD2.sh", "Retry", "Quit", 0, 0, 1 );
3047    }
3048   
3049   
3050   
3051
3052}
3053
3054
3055void PCInstall::slotFinishedInstallCD2()
3056{
3057      // Check if we need to proceede to CD3 now and load the optional stuff
3058      if ( installComponents == 1 || listBoxLang->currentItem() != 0 )
3059      {
3060         if ( usingDVDmedia == 0 )
3061         {
3062            // Run the slot to install the components
3063            slotStartMountCD3();
3064         } else {
3065           // Looks like we have a DVD, lets install from it now
3066           slotRunInstallComponents();
3067         }
3068      } else {
3069          // If no extra components, then lets finish up the install
3070        if ( radioFreshInstall->isChecked() )
3071        {
3072            // Run our setup scripts now, starting with the user add slot
3073            setupUsersSlot();
3074        } else {
3075            slotRunFinalScriptUpgrade();
3076        } 
3077      }
3078
3079}
3080
3081
3082void PCInstall::slotReadCD2Status()
3083{
3084  QString Buffer, tmp;
3085
3086    // Loop while getting input
3087    while (installCD2proc->canReadLineStdout() )
3088    {
3089        // Read the line
3090        Buffer = installCD2proc->readLineStdout();
3091       
3092        if (Buffer.find("MSG:") != -1 )
3093        {
3094            Buffer.remove(0,4 );
3095           
3096            textFileProgress->setText(Buffer);
3097
3098        } 
3099       
3100        // Remove the "x" from the start
3101        if ( Buffer.find("x", 0) == 0)
3102        {
3103            Buffer.remove(0, 3);
3104            tmp = Buffer;
3105            Buffer = tmp;
3106            textFileProgress->setText(Buffer);
3107                    ExtractSize = ExtractSize + 1; 
3108             // Get size for Progress Bar
3109
3110            installProgress->setProgress(ExtractSize);
3111        }
3112    } // End while loop
3113}
3114
3115
3116void PCInstall::slotStartMountCD3()
3117{
3118    // Slot to start the mount process for CD2 to finish the install from it     
3119    textFileProgress->setText(tr("Unmounting CD #2..."));
3120   
3121    EjectCD = new Q3Process( this );
3122    EjectCD->addArgument( "/usr/local/pcbsd/scripts/PCBSD.EjectCD.sh" );
3123
3124     if ( !EjectCD->start() ) {
3125        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting EjectCD", "Retry", "Quit", 0, 0, 1 );
3126    }
3127   
3128   
3129   
3130    QMessageBox::information( this, tr("Insert CD #3"), tr("Insert CD #3 and click OK to continue. ") );
3131           
3132   
3133   
3134    textFileProgress->setText(tr("Mounting CD #3..."));
3135   
3136      //Setup Process to mount the root partition
3137    findCD3proc = new Q3Process( this );
3138    findCD3proc->addArgument( "/usr/local/pcbsd/scripts/PCBSD.MountCD3.sh" );
3139
3140    connect( findCD3proc, SIGNAL(processExited()), this, SLOT(slotFinishedMountCD3() ) );
3141
3142    if ( !findCD3proc->start() ) {
3143        QMessageBox::warning( this, "PCBSD Installer", "Failed Starting MountCD3", "Retry", "Quit", 0, 0, 1 );
3144    }
3145}
3146
3147
3148void PCInstall::slotFinishedMountCD3()
3149{
3150     // If the CD mounted successfully
3151    if(findCD3proc->normalExit() && findCD3proc->exitStatus() == 0 )
3152    {
3153      // We are ready to install the optional components now
3154      slotRunInstallComponents();
3155    } else {
3156
3157        switch( QMessageBox::warning( this, tr("CD Mount Error"), tr("Error: Could not locate CD #3. Please check that the CD is in the drive. Press OK to try again, or Cancel to abort install."), tr("OK"), tr("Cancel"), 0, 0, 1 ) ) {
3158             case 0: // The user clicked the OK again button or pressed Enter
3159                 slotStartMountCD3();
3160                 break;
3161             case 1: // The user clicked the Quit or pressed Escape
3162                 exit(5);
3163                 return;
3164                 break;
3165             }
3166    }
3167}
3168
3169
3170void PCInstall::slotFinishedInstallCD3()
3171{
3172       // All ready to finish up the install, check the type of install we were doing, and finish it now
3173      if ( radioFreshInstall->isChecked() )
3174      {
3175            // Setup our users and run final scripts now
3176            setupUsersSlot();
3177      } else {
3178           slotRunFinalScriptUpgrade();
3179     } 
3180}
3181
3182
3183// Slot which is called when a user selects the NIC configuration he wants
3184// to use to install PCBSD
3185void PCInstall::nicSavedSlot(QString NIC, QString IP, QString NM, QString Gate)
3186{
3187   // Apply the network configuration, and display a popup letting the user know what we are
3188   // doing
3189   workDialog = new WorkingDialog();
3190   workDialog->setModal(true);
3191   workDialog->setText(tr("Enabling NIC"));
3192   workDialog->setTitle(tr("Network Setup"));
3193   workDialog->show();     
3194
3195   // Create our process now and start it
3196   enableNICproc = new QProcess(this);
3197   QString program = "/usr/local/pcbsd/scripts/PCBSD.SetNic.sh";
3198   QStringList arguments;
3199   arguments << NIC << IP << NM << Gate;
3200   connect( enableNICproc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(nicFinishedSlot(int, QProcess::ExitStatus) ) );
3201   enableNICproc->start(program, arguments);
3202
3203}
3204
3205
3206// Get the results from our NIC enable process
3207void PCInstall::nicFinishedSlot(int exitCode, QProcess::ExitStatus exitStatus)
3208{
3209  if ( exitCode != 0 )
3210  {
3211     QMessageBox::warning( this, tr("Network Setup"), tr("Failed to setup a network connection!") );
3212     radioCDInstall->setChecked(true);
3213     workDialog->doClose();
3214  } else {
3215     // Close the working dialog
3216     workDialog->doClose();
3217
3218     // Now bring up the dialog which asks for the source media of this install
3219     selectNetDialog = new dialogSelectNetServer();
3220     selectNetDialog->setModal(true);
3221     selectNetDialog->programInit();
3222     connect( selectNetDialog, SIGNAL(saved(bool, QString)), this, SLOT(netDialogSlot(bool, QString) ) );
3223     selectNetDialog->show(); 
3224  }
3225
3226}
3227
3228void PCInstall::netDialogSlot(bool internet, QString ServerURL)
3229{
3230  QString tmp;
3231  networkServerURL = ServerURL;
3232  usingInternetInstall = internet;
3233
3234
3235  if ( networkServerURL.lastIndexOf("/") != networkServerURL.size() )
3236  {
3237       networkServerURL = networkServerURL + "/";
3238  } 
3239
3240  // Save our tmp file with the URL of the images we want to use
3241  QFile file2( "/tmp/networkURL" );
3242  if ( file2.open( IO_WriteOnly ) ) {
3243      QTextStream stream2( &file2 );
3244      stream2 << networkServerURL;
3245      file2.close();
3246  }
3247
3248
3249   // Now lets go ahead and confirm that we have a valid network install path
3250   workDialog = new WorkingDialog();
3251   workDialog->setModal(true);
3252   workDialog->setText(tr("Confirming valid network location"));
3253   workDialog->setTitle(tr("Network Setup"));
3254   workDialog->show();
3255
3256   // Create our process now and start it
3257   confirmNetproc = new QProcess(this);
3258   QString program = "/usr/local/pcbsd/scripts/PCBSD.ConfirmNetFiles.sh";
3259   QStringList arguments;
3260   connect( confirmNetproc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(netFinishedConfirmSlot(int, QProcess::ExitStatus) ) );
3261   confirmNetproc->start(program, arguments);
3262
3263   
3264
3265}
3266
3267void PCInstall::netFinishedConfirmSlot(int exitCode, QProcess::ExitStatus exitStatus)
3268{
3269 
3270  // Close the working dialog
3271  workDialog->doClose();
3272
3273  // Check if we found valid install data at this location
3274  if ( exitCode == 0)
3275  {
3276
3277    networkInstall = true;
3278
3279    // Now move us to the next wizard page, the network setup is complete.
3280    // If the user wanted to upgrade, jump to that screen
3281    if ( ! radioFreshInstall->isChecked() )
3282    {
3283       showPage(page(6));
3284       return;
3285    } else {
3286       showPage(page(3));
3287       return;
3288    }
3289
3290  } else {
3291    // Looks like we have a bad network install path, PCBSD.tar.lzma and / or
3292    // PCBSD.tar.lzma2 could not be found
3293    networkInstall = false;
3294     
3295    QMessageBox::warning( this, tr("Network Setup"), tr("The specified URL does not appear to be a valid install location. Please check the network location and try again.") );
3296
3297  }
3298
3299}
3300
3301void PCInstall::checkFileSystemSlot(const QString &text)
3302{
3303   if ( text.indexOf("ZFS") != -1)
3304   {
3305    QMessageBox::warning( this, tr("ZFS Warning"), tr("Warning: ZFS usage is primarily for high-end systems with a 64 bit processor and 4+ GB of memory. It may run on lesser hardware, but is not recommended.") );
3306   }
3307}
Note: See TracBrowser for help on using the browser.