@@ -120,11 +120,23 @@ void MainWindow::setup()
120
120
ui->pushThemeFile ->setVisible (grubThemesExist);
121
121
ui->pushThemeFile ->setDisabled (true );
122
122
123
- // If running live, read Linux partitions and set chroot on the selected one
123
+ // If running live, prompt user to choose between changing options for the live system or the installed system
124
124
if (live) {
125
- QString part = selectPartiton (getLinuxPartitions ());
126
- if (!part.isEmpty ()) {
127
- createChrootEnv (part);
125
+ QMessageBox msgBox (this );
126
+ msgBox.setWindowTitle (tr (" Live System Detected" ));
127
+ msgBox.setText (tr (" You are currently running a live system. Would you like to modify the boot options for the live system "
128
+ " or for an installed system?" ));
129
+ QPushButton *liveButton = msgBox.addButton (tr (" Live System" ), QMessageBox::ActionRole);
130
+ QPushButton *installedButton = msgBox.addButton (tr (" Installed System" ), QMessageBox::ActionRole);
131
+ msgBox.exec ();
132
+
133
+ if (msgBox.clickedButton () == installedButton) {
134
+ QString partition = selectPartiton (getLinuxPartitions ());
135
+ if (!partition.isEmpty ()) {
136
+ createChrootEnv (partition);
137
+ }
138
+ } else if (msgBox.clickedButton () == liveButton) {
139
+ boot_location = QFileInfo::exists (" /live/config/did-toram" ) ? " /live/to-ram" : " /live/boot-dev" ;
128
140
}
129
141
}
130
142
@@ -665,6 +677,68 @@ bool MainWindow::replaceGrubArg(const QString &key, const QString &item)
665
677
return replaced; // Return whether a replacement occurred
666
678
}
667
679
680
+ void MainWindow::replaceSyslinuxArg (const QString &args)
681
+ {
682
+ const QStringList configFiles
683
+ = {boot_location + " /boot/syslinux/syslinux.cfg" , boot_location + " /boot/isolinux/isolinux.cfg" };
684
+
685
+ for (const QString &configFile : configFiles) {
686
+ QFile file (configFile);
687
+ if (!file.open (QIODevice::ReadOnly | QIODevice::Text)) {
688
+ qWarning () << " Failed to open" << configFile << " for reading." ;
689
+ continue ;
690
+ }
691
+
692
+ QStringList new_list;
693
+ bool replaced = false ;
694
+
695
+ while (!file.atEnd ()) {
696
+ QString line = file.readLine ().trimmed ();
697
+ if (!kernel_options.isEmpty () && line.contains (kernel_options)) {
698
+ line.replace (kernel_options, args);
699
+ replaced = true ;
700
+ } else if (kernel_options.isEmpty () && line.startsWith (" APPEND" ) && !replaced) {
701
+ QStringList parts = line.split (' ' , Qt::SkipEmptyParts);
702
+ if (parts.size () > 1 ) {
703
+ parts[1 ] = args;
704
+ } else {
705
+ parts.append (args);
706
+ }
707
+ line = parts.join (' ' );
708
+ replaced = true ;
709
+ }
710
+ new_list << line;
711
+ }
712
+
713
+ file.close ();
714
+
715
+ if (!replaced) {
716
+ qWarning () << " No" << (kernel_options.isEmpty () ? " APPEND line" : kernel_options) << " found to replace in"
717
+ << configFile << " ." ;
718
+ continue ;
719
+ }
720
+
721
+ // Write to a temporary file using QTemporaryFile
722
+ QTemporaryFile tempFile (QDir::tempPath () + " /XXXXXX.tmp" );
723
+ if (!tempFile.open ()) {
724
+ qWarning () << " Failed to open temporary file for writing." ;
725
+ continue ;
726
+ }
727
+
728
+ QTextStream stream (&tempFile);
729
+ stream.setCodec (" UTF-8" );
730
+ stream << new_list.join (" \n " ) << " \n " ;
731
+ tempFile.flush ();
732
+ tempFile.close ();
733
+
734
+ // Move the temporary file to the original file
735
+ QString tempFilePath = tempFile.fileName ();
736
+ if (!cmd.runAsRoot (" mv " + tempFilePath + " " + configFile)) {
737
+ qWarning () << " Failed to move" << tempFilePath << " to" << configFile << " ." ;
738
+ }
739
+ }
740
+ }
741
+
668
742
void MainWindow::readGrubCfg ()
669
743
{
670
744
QStringList content;
@@ -759,7 +833,7 @@ void MainWindow::readDefaultGrub()
759
833
ui->pushBgFile ->setDisabled (themeExists);
760
834
} else if (line.startsWith (" GRUB_CMDLINE_LINUX_DEFAULT=" )) {
761
835
QString cmdline = line.remove (" GRUB_CMDLINE_LINUX_DEFAULT=" ).remove (" \" " ).remove (" '" );
762
- ui->textKernel ->setText (cmdline);
836
+ ui->textKernel ->setText (live ? kernel_options : cmdline);
763
837
ui->radioLimitedMsg ->setChecked (cmdline.contains (" hush" ));
764
838
ui->radioDetailedMsg ->setChecked (cmdline.contains (" quiet" ));
765
839
ui->radioVeryDetailedMsg ->setChecked (!cmdline.contains (" hush" ) && !cmdline.contains (" quiet" ));
@@ -775,14 +849,14 @@ void MainWindow::readDefaultGrub()
775
849
}
776
850
777
851
// Read kernel line and options from /proc/cmdline
778
- void MainWindow::readKernelOpts ()
852
+ QString MainWindow::readKernelOpts ()
779
853
{
780
854
QFile file (" /proc/cmdline" );
781
855
if (!file.open (QIODevice::ReadOnly)) {
782
856
qWarning () << " Failed to open file:" << file.fileName () << " - Error:" << file.errorString ();
783
- return ;
857
+ return {} ;
784
858
}
785
- kernel_options = file.readAll ().trimmed ();
859
+ return file.readAll ().trimmed ();
786
860
}
787
861
788
862
void MainWindow::cmdStart ()
@@ -836,6 +910,9 @@ void MainWindow::pushApply_clicked()
836
910
837
911
if (kernel_options_changed) {
838
912
replaceGrubArg (" GRUB_CMDLINE_LINUX_DEFAULT" , " \" " + ui->textKernel ->text () + " \" " );
913
+ if (live) {
914
+ replaceSyslinuxArg (ui->textKernel ->text ());
915
+ }
839
916
}
840
917
841
918
if (options_changed) {
@@ -907,9 +984,15 @@ void MainWindow::pushApply_clicked()
907
984
writeDefaultGrub ();
908
985
progress->setLabelText (tr (" Updating grub..." ));
909
986
cmd.runAsRoot (chroot + " update-grub" );
987
+ if (live) {
988
+ cmd.runAsRoot (" cp /boot/grub/grub.cfg " + boot_location + " /boot/grub/grub.cfg" );
989
+ }
910
990
}
911
991
progress->close ();
912
- QMessageBox::information (this , tr (" Done" ), tr (" Changes have been successfully applied." ));
992
+ QString message = live && boot_location == " /live/to-ram"
993
+ ? tr (" You are currently running in live mode with the 'toram' option. Please remember to save the persistence file or remaster, otherwise any changes made will be lost." )
994
+ : tr (" Your changes have been successfully applied." );
995
+ QMessageBox::information (this , tr (" Operation Complete" ), message);
913
996
}
914
997
915
998
// Reset change flags
0 commit comments