Git commit f008456b4a7819d2f374d4f59cbd5ab155be478b by Konstantinos Smanis. Committed on 10/10/2013 at 20:26. Pushed by ksmanis into branch 'master'. *FIXED: Improved security by detecting GRUB paths at compile-time. GRUB paths are no longer detected at run-time and passed around to the helper. They remain fixed after compilation. This is a strict rule so that the helper cannot read/write to an arbitrary file. It also allows package maintainers to fine-tune the module according to each distribution's naming conventions. If no user interaction is detected, CMake will automatically try and resolve these paths. Package maintainers are *highly* encouraged to manually specify these paths. For more information check the updated INSTALL file. M +1 -0 CMakeLists.txt M +60 -5 INSTALL A +59 -0 cmake/modules/GRUBPaths.cmake M +17 -0 config.h.cmake M +24 -48 src/helper/helper.cpp M +0 -1 src/helper/helper.h M +1 -4 src/installDlg.cpp M +1 -2 src/installDlg.h M +23 -83 src/kcm_grub2.cpp M +2 -13 src/kcm_grub2.h M +589 -614 ui/kcm_grub2.ui http://commits.kde.org/kcm-grub2/f008456b4a7819d2f374d4f59cbd5ab155be478b diff --git a/CMakeLists.txt b/CMakeLists.txt index ee3bbbb..a94864d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${C= MAKE_MODULE_PATH}) find_package(Qt4 4.6.0 REQUIRED) find_package(KDE4 4.4.0 REQUIRED) include(KDE4Defaults) +include(GRUBPaths) = add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) = diff --git a/INSTALL b/INSTALL index 66411ff..1d3204a 100644 --- a/INSTALL +++ b/INSTALL @@ -1,3 +1,7 @@ +/=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D\ +| Build & Run Instructions | +\=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D/ + Enter the directory where you extracted the source code and run: = $ mkdir build @@ -6,19 +10,70 @@ $ cmake .. -DCMAKE_INSTALL_PREFIX=3D`kde4-config --prefi= x` $ make $ sudo make install = -You may then find the GRUB2 KCModule under "Startup and Shutdown" in Syste= m Settings. -You may also launch it running: +You may then find the GRUB2 KCModule under "Startup and Shutdown" in +System Settings. You may also launch it running: = $ kcmshell4 kcm_grub2 = -In order to appear in System Settings the first time you install the GRUB2= KCModule, you may have to run: +In order to appear in System Settings the first time you install the +GRUB2 KCModule, you may have to run: = $ kbuildsycoca4 = +Note: '$' indicates a shell prompt. + +/=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D\ +| Dependencies & Requirements | +\=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D/ + Requires KDE >=3D 4.4, Qt >=3D 4.6, GRUB2. Suggests ImageMagick for GRUB splash image management. Suggests hwinfo for valid GRUB resolution detection. Suggests LibQApt or QPackageKit for removing old entries. -Minimum requirement is kdebase-runtime. Install kdebase-workspace for Syst= em Settings integration. = -Note: '$' indicates a shell prompt. +Minimum KDE requirement is kdebase-runtime. +Install kdebase-workspace instead for System Settings integration. + +/=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\ +| GRUB Path Resolution | +\=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D/ + +Almost every distribution has different paths for GRUB executable and +configuration files. Thus, the need to automatically detect them arises. +Hopefully the most prevalent naming schemes boil down to three cases: + +* vanilla grub-foo executables and boot directory, +* modified grub2-foo executables and boot directory (allows for parallel + installation of both major versions of GRUB), +* and as a third, last case we consider BURG installations with vanilla + burg-foo executables and boot directory. + +CMake will detect the above cases in the order specified and +appropriately fill in the following variables: + +* GRUB_INSTALL_EXE =3D executable which installs GRUB +* GRUB_MKCONFIG_EXE =3D executable which generates GRUB's menu file +* GRUB_PROBE_EXE =3D executable which probes devices for GRUB information +* GRUB_SET_DEFAULT_EXE =3D executable which sets the default entry in + GRUB's environment file +* GRUB_MENU =3D GRUB's menu file +* GRUB_CONFIG =3D GRUB's main configuration file +* GRUB_ENV =3D GRUB's environment file +* GRUB_MEMTEST =3D script installed by memtest (usually under /etc/grub.d) + +For security reasons these variables can only be set at compile time and +will be embedded in the binary, so that they cannot be altered +afterwards. + +The following options exist: + +* Do not manually specify any of the above variables, in which case + CMake will try to resolve them automatically. If it fails you will be + prompted to manually specify them all. +* If you specify at least one of the *_EXE variables, you will have to + specify all other variables as well. +* You can make changes to the non-EXE variables as long as you don't + alter any of the *_EXE ones. + +Package maintainers are encouraged to manually specify all of the above +variables in order to fit with each distribution's naming scheme. diff --git a/cmake/modules/GRUBPaths.cmake b/cmake/modules/GRUBPaths.cmake new file mode 100644 index 0000000..7c30e1d --- /dev/null +++ b/cmake/modules/GRUBPaths.cmake @@ -0,0 +1,59 @@ +if(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GRUB_SET_= DEFAULT_EXE AND GRUB_MENU AND GRUB_CONFIG AND GRUB_ENV AND GRUB_MEMTEST) + message(STATUS "All GRUB paths were defined in the CMake cache. By-pas= sing automatic resolution.") +elseif(NOT (GRUB_INSTALL_EXE OR GRUB_MKCONFIG_EXE OR GRUB_PROBE_EXE OR GRU= B_SET_DEFAULT_EXE)) + find_program(GRUB_INSTALL_EXE NAMES grub-install DOC "GRUB install exe= cutable file path.") + find_program(GRUB_MKCONFIG_EXE NAMES grub-mkconfig DOC "GRUB mkconfig = executable file path.") + find_program(GRUB_PROBE_EXE NAMES grub-probe DOC "GRUB probe executabl= e file path.") + find_program(GRUB_SET_DEFAULT_EXE NAMES grub-set-default DOC "GRUB set= -default executable file path.") + if(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GRUB_= SET_DEFAULT_EXE) + set(GRUB_MENU "/boot/grub/grub.cfg" CACHE FILEPATH "GRUB menu file= path.") + set(GRUB_CONFIG "/etc/default/grub" CACHE FILEPATH "GRUB configura= tion file path.") + set(GRUB_ENV "/boot/grub/grubenv" CACHE FILEPATH "GRUB environment= file path.") + set(GRUB_MEMTEST "/etc/grub.d/20_memtest86+" CACHE FILEPATH "GRUB = memtest file path.") + else(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GRU= B_SET_DEFAULT_EXE) + unset(GRUB_INSTALL_EXE CACHE) + unset(GRUB_MKCONFIG_EXE CACHE) + unset(GRUB_PROBE_EXE CACHE) + unset(GRUB_SET_DEFAULT_EXE CACHE) + find_program(GRUB_INSTALL_EXE NAMES grub2-install DOC "GRUB instal= l executable file path.") + find_program(GRUB_MKCONFIG_EXE NAMES grub2-mkconfig DOC "GRUB mkco= nfig executable file path.") + find_program(GRUB_PROBE_EXE NAMES grub2-probe DOC "GRUB probe exec= utable file path.") + find_program(GRUB_SET_DEFAULT_EXE NAMES grub2-set-default DOC "GRU= B set-default executable file path.") + if(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND G= RUB_SET_DEFAULT_EXE) + set(GRUB_MENU "/boot/grub2/grub.cfg" CACHE FILEPATH "GRUB menu= file path.") + set(GRUB_CONFIG "/etc/default/grub" CACHE FILEPATH "GRUB confi= guration file path.") + set(GRUB_ENV "/boot/grub2/grubenv" CACHE FILEPATH "GRUB enviro= nment file path.") + set(GRUB_MEMTEST "/etc/grub.d/20_memtest86+" CACHE FILEPATH "G= RUB memtest file path.") + else(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND= GRUB_SET_DEFAULT_EXE) + unset(GRUB_INSTALL_EXE CACHE) + unset(GRUB_MKCONFIG_EXE CACHE) + unset(GRUB_PROBE_EXE CACHE) + unset(GRUB_SET_DEFAULT_EXE CACHE) + find_program(GRUB_INSTALL_EXE NAMES burg-install DOC "GRUB ins= tall executable file path.") + find_program(GRUB_MKCONFIG_EXE NAMES burg-mkconfig DOC "GRUB m= kconfig executable file path.") + find_program(GRUB_PROBE_EXE NAMES burg-probe DOC "GRUB probe e= xecutable file path.") + find_program(GRUB_SET_DEFAULT_EXE NAMES burg-set-default DOC "= GRUB set-default executable file path.") + if(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE A= ND GRUB_SET_DEFAULT_EXE) + set(GRUB_MENU "/boot/burg/burg.cfg" CACHE FILEPATH "GRUB m= enu file path.") + set(GRUB_CONFIG "/etc/default/burg" CACHE FILEPATH "GRUB c= onfiguration file path.") + set(GRUB_ENV "/boot/burg/burgenv" CACHE FILEPATH "GRUB env= ironment file path.") + set(GRUB_MEMTEST "/etc/burg.d/20_memtest86+" CACHE FILEPAT= H "GRUB memtest file path.") + else(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE= AND GRUB_SET_DEFAULT_EXE) + message(FATAL_ERROR "Could not automatically resolve GRUB = paths. Please specify all of them manually.") + endif(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EX= E AND GRUB_SET_DEFAULT_EXE) + endif(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AN= D GRUB_SET_DEFAULT_EXE) + endif(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GR= UB_SET_DEFAULT_EXE) +else(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GRUB_SE= T_DEFAULT_EXE AND GRUB_MENU AND GRUB_CONFIG AND GRUB_ENV AND GRUB_MEMTEST) + message(FATAL_ERROR "Some, but not all, GRUB paths were defined in the= CMake cache. Please define them all or let CMake do it. In the latter case= define none.") +endif(GRUB_INSTALL_EXE AND GRUB_MKCONFIG_EXE AND GRUB_PROBE_EXE AND GRUB_S= ET_DEFAULT_EXE AND GRUB_MENU AND GRUB_CONFIG AND GRUB_ENV AND GRUB_MEMTEST) + +message(STATUS "----------------------------------------------------------= ----------------") +message(STATUS "GRUB_INSTALL_EXE: ${GRUB_INSTALL_EXE}") +message(STATUS "GRUB_MKCONFIG_EXE: ${GRUB_MKCONFIG_EXE}") +message(STATUS "GRUB_PROBE_EXE: ${GRUB_PROBE_EXE}") +message(STATUS "GRUB_SET_DEFAULT_EXE: ${GRUB_SET_DEFAULT_EXE}") +message(STATUS "GRUB_MENU: ${GRUB_MENU}") +message(STATUS "GRUB_CONFIG: ${GRUB_CONFIG}") +message(STATUS "GRUB_ENV: ${GRUB_ENV}") +message(STATUS "GRUB_MEMTEST: ${GRUB_MEMTEST}") +message(STATUS "----------------------------------------------------------= ----------------") diff --git a/config.h.cmake b/config.h.cmake index fabe1a4..5d57a67 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -2,10 +2,27 @@ #define CONFIG_H = #define KCM_GRUB2_VERSION "@KCM_GRUB2_VERSION@" + #define HAVE_IMAGEMAGICK @HAVE_IMAGEMAGICK@ #define HAVE_HD @HAVE_HD@ #define HAVE_QAPT @HAVE_QAPT@ #define HAVE_QPACKAGEKIT @HAVE_QPACKAGEKIT@ #define QAPT_VERSION_MAJOR @QAPT_VERSION_MAJOR@ = +#define GRUB_INSTALL_EXE "@GRUB_INSTALL_EXE@" +#define GRUB_MKCONFIG_EXE "@GRUB_MKCONFIG_EXE@" +#define GRUB_PROBE_EXE "@GRUB_PROBE_EXE@" +#define GRUB_SET_DEFAULT_EXE "@GRUB_SET_DEFAULT_EXE@" +#define GRUB_MENU "@GRUB_MENU@" +#define GRUB_CONFIG "@GRUB_CONFIG@" +#define GRUB_ENV "@GRUB_ENV@" +#define GRUB_MEMTEST "@GRUB_MEMTEST@" + +enum GrubFile { + GrubMenuFile, + GrubConfigurationFile, + GrubEnvironmentFile, + GrubMemtestFile +}; + #endif diff --git a/src/helper/helper.cpp b/src/helper/helper.cpp index 5136cc7..20316a9 100644 --- a/src/helper/helper.cpp +++ b/src/helper/helper.cpp @@ -26,9 +26,9 @@ = //KDE #include +#include #include #include -#include #include = //Project @@ -39,23 +39,13 @@ #endif = //The $PATH environment variable is emptied by D-Bus activation, -//so let's provide a sane default. To be used as a fallback. +//so let's provide a sane default. Needed for os-prober to work. static const QString path =3D QLatin1String("/usr/sbin:/usr/bin:/sbin:/bin= "); = Helper::Helper() { KGlobal::locale()->insertCatalog("kcm-grub2"); - //-l stands for --login. A login shell is needed in order to properly - //source /etc/profile, ~/.profile and/or other shell-specific login - //scripts (such as ~/.bash_profile for Bash). - //Not all shells implement this option, in which case we have the fall= back. - //Bash, DASH, ksh and Zsh seem to work properly. - ActionReply pathReply =3D executeCommand(QStringList() << findShell() = << "-l" << "-c" << "echo $PATH"); - if (pathReply.succeeded()) { - qputenv("PATH", pathReply.data().value("output").toByteArray().tri= mmed()); - } else { - qputenv("PATH", path.toLatin1()); - } + qputenv("PATH", path.toLatin1()); } = ActionReply Helper::executeCommand(const QStringList &command) @@ -76,31 +66,12 @@ ActionReply Helper::executeCommand(const QStringList &c= ommand) reply.addData("output", process.readAll()); return reply; } -QString Helper::findShell() -{ - QString shell =3D QFile::symLinkTarget(QLatin1String("/bin/sh")); - if (shell.isEmpty()) { - shell =3D KStandardDirs::findExe(QLatin1String("bash"), path); - if (shell.isEmpty()) { - shell =3D KStandardDirs::findExe(QLatin1String("dash"), path); - if (shell.isEmpty()) { - shell =3D KStandardDirs::findExe(QLatin1String("ksh"), pat= h); - if (shell.isEmpty()) { - shell =3D KStandardDirs::findExe(QLatin1String("zsh"),= path); - if (shell.isEmpty()) { - shell =3D QLatin1String("/bin/sh"); - } - } - } - } - } - return shell; -} = ActionReply Helper::defaults(QVariantMap args) { + Q_UNUSED(args) ActionReply reply; - QString configFileName =3D args.value("configFileName").toString(); + QString configFileName =3D GRUB_CONFIG; QString originalConfigFileName =3D configFileName + ".original"; = if (!QFile::exists(originalConfigFileName)) { @@ -123,7 +94,6 @@ ActionReply Helper::defaults(QVariantMap args) ActionReply Helper::install(QVariantMap args) { ActionReply reply; - QString installExePath =3D args.value("installExePath").toString(); QString partition =3D args.value("partition").toString(); QString mountPoint =3D args.value("mountPoint").toString(); bool mbrInstall =3D args.value("mbrInstall").toBool(); @@ -142,7 +112,7 @@ ActionReply Helper::install(QVariantMap args) } = QStringList grub_installCommand; - grub_installCommand << installExePath << "--root-directory" << mountPo= int; + grub_installCommand << GRUB_INSTALL_EXE << "--root-directory" << mount= Point; if (mbrInstall) { grub_installCommand << partition.remove(QRegExp("\\d+")); } else { @@ -153,7 +123,18 @@ ActionReply Helper::install(QVariantMap args) ActionReply Helper::load(QVariantMap args) { ActionReply reply; - QString fileName =3D args.value("fileName").toString(); + QString fileName; + switch (args.value("grubFile").toInt()) { + case GrubMenuFile: + fileName =3D GRUB_MENU; + break; + case GrubConfigurationFile: + fileName =3D GRUB_CONFIG; + break; + case GrubEnvironmentFile: + fileName =3D GRUB_ENV; + break; + } = QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -167,13 +148,12 @@ ActionReply Helper::load(QVariantMap args) ActionReply Helper::probe(QVariantMap args) { ActionReply reply; - QString probeExePath =3D args.value("probeExePath").toString(); QStringList mountPoints =3D args.value("mountPoints").toStringList(); = QStringList grubPartitions; HelperSupport::progressStep(0); for (int i =3D 0; i < mountPoints.size(); i++) { - ActionReply grub_probeReply =3D executeCommand(QStringList() << pr= obeExePath << "-t" << "drive" << mountPoints.at(i)); + ActionReply grub_probeReply =3D executeCommand(QStringList() << GR= UB_PROBE_EXE << "-t" << "drive" << mountPoints.at(i)); if (grub_probeReply.failed()) { return grub_probeReply; } @@ -211,13 +191,9 @@ ActionReply Helper::probevbe(QVariantMap args) ActionReply Helper::save(QVariantMap args) { ActionReply reply; - QString mkconfigExePath =3D args.value("mkconfigExePath").toString(); - QString set_defaultExePath =3D args.value("set_defaultExePath").toStri= ng(); - QString configFileName =3D args.value("configFileName").toString(); + QString configFileName =3D GRUB_CONFIG; QByteArray rawConfigFileContents =3D args.value("rawConfigFileContents= ").toByteArray(); - QString menuFileName =3D args.value("menuFileName").toString(); QByteArray rawDefaultEntry =3D args.value("rawDefaultEntry").toByteArr= ay(); - QString memtestFileName =3D args.value("memtestFileName").toString(); bool memtest =3D args.value("memtest").toBool(); = QFile::copy(configFileName, configFileName + ".original"); @@ -232,21 +208,21 @@ ActionReply Helper::save(QVariantMap args) file.close(); = if (args.contains("memtest")) { - QFile::Permissions permissions =3D QFile::permissions(memtestFileN= ame); + QFile::Permissions permissions =3D QFile::permissions(GRUB_MEMTEST= ); if (memtest) { permissions |=3D (QFile::ExeOwner | QFile::ExeUser | QFile::Ex= eGroup | QFile::ExeOther); } else { permissions &=3D ~(QFile::ExeOwner | QFile::ExeUser | QFile::E= xeGroup | QFile::ExeOther); } - QFile::setPermissions(memtestFileName, permissions); + QFile::setPermissions(GRUB_MEMTEST, permissions); } = - ActionReply grub_mkconfigReply =3D executeCommand(QStringList() << mkc= onfigExePath << "-o" << menuFileName); + ActionReply grub_mkconfigReply =3D executeCommand(QStringList() << GRU= B_MKCONFIG_EXE << "-o" << GRUB_MENU); if (grub_mkconfigReply.failed()) { return grub_mkconfigReply; } = - ActionReply grub_set_defaultReply =3D executeCommand(QStringList() << = set_defaultExePath << rawDefaultEntry); + ActionReply grub_set_defaultReply =3D executeCommand(QStringList() << = GRUB_SET_DEFAULT_EXE << rawDefaultEntry); if (grub_set_defaultReply.failed()) { return grub_set_defaultReply; } diff --git a/src/helper/helper.h b/src/helper/helper.h index e84af67..782d382 100644 --- a/src/helper/helper.h +++ b/src/helper/helper.h @@ -29,7 +29,6 @@ public: Helper(); private: ActionReply executeCommand(const QStringList &command); - QString findShell(); public Q_SLOTS: ActionReply defaults(QVariantMap args); ActionReply install(QVariantMap args); diff --git a/src/installDlg.cpp b/src/installDlg.cpp index 97f8c80..ceff92c 100644 --- a/src/installDlg.cpp +++ b/src/installDlg.cpp @@ -35,7 +35,7 @@ using namespace KAuth; //Ui #include "ui_installDlg.h" = -InstallDialog::InstallDialog(const QString installExePath, QWidget *parent= , Qt::WFlags flags) : KDialog(parent, flags) +InstallDialog::InstallDialog(QWidget *parent, Qt::WFlags flags) : KDialog(= parent, flags) { QWidget *widget =3D new QWidget(this); ui =3D new Ui::InstallDialog; @@ -48,8 +48,6 @@ InstallDialog::InstallDialog(const QString installExePath= , QWidget *parent, Qt:: setInitialSize(parent->size()); } = - m_installExePath =3D installExePath; - ui->treeWidget_recover->headerItem()->setText(0, QString()); ui->treeWidget_recover->header()->setResizeMode(QHeaderView::Stretch); ui->treeWidget_recover->header()->setResizeMode(0, QHeaderView::Resize= ToContents); @@ -90,7 +88,6 @@ void InstallDialog::slotButtonClicked(int button) for (int i =3D 0; i < ui->treeWidget_recover->topLevelItemCount();= i++) { QRadioButton *radio =3D qobject_cast(ui->treeW= idget_recover->itemWidget(ui->treeWidget_recover->topLevelItem(i), 0)); if (radio && radio->isChecked()) { - installAction.addArgument("installExePath", m_installExePa= th); installAction.addArgument("partition", ui->treeWidget_reco= ver->topLevelItem(i)->text(1)); installAction.addArgument("mountPoint", ui->treeWidget_rec= over->topLevelItem(i)->text(2)); installAction.addArgument("mbrInstall", !ui->checkBox_part= ition->isChecked()); diff --git a/src/installDlg.h b/src/installDlg.h index 384f63c..e5ddc93 100644 --- a/src/installDlg.h +++ b/src/installDlg.h @@ -31,12 +31,11 @@ class InstallDialog : public KDialog { Q_OBJECT public: - explicit InstallDialog(const QString installExePath, QWidget *parent = =3D 0, Qt::WFlags flags =3D 0); + explicit InstallDialog(QWidget *parent =3D 0, Qt::WFlags flags =3D 0); virtual ~InstallDialog(); protected Q_SLOTS: virtual void slotButtonClicked(int button); private: - QString m_installExePath; Ui::InstallDialog *ui; }; = diff --git a/src/kcm_grub2.cpp b/src/kcm_grub2.cpp index 56e0466..b6b324d 100644 --- a/src/kcm_grub2.cpp +++ b/src/kcm_grub2.cpp @@ -34,15 +34,12 @@ #include #include #include -#include #include -#include #include using namespace KAuth; = //Project #include "common.h" -#include #if HAVE_IMAGEMAGICK #include "convertDlg.h" #endif @@ -71,9 +68,6 @@ KCMGRUB2::KCMGRUB2(QWidget *parent, const QVariantList &l= ist) : KCModule(GRUB2Fa ui->setupUi(this); setupObjects(); setupConnections(); - if (check()) { - ui->stackedWidget->setCurrentIndex(1); - } } KCMGRUB2::~KCMGRUB2() { @@ -84,7 +78,6 @@ void KCMGRUB2::defaults() { Action defaultsAction("org.kde.kcontrol.kcmgrub2.defaults"); defaultsAction.setHelperID("org.kde.kcontrol.kcmgrub2"); - defaultsAction.addArgument("configFileName", configPath); #if KDE_IS_VERSION(4,6,0) defaultsAction.setParentWidget(this); #endif @@ -101,10 +94,6 @@ void KCMGRUB2::defaults() } void KCMGRUB2::load() { - if (ui->stackedWidget->currentIndex() =3D=3D 0) { - return; - } - readEntries(); readSettings(); readEnv(); @@ -202,9 +191,9 @@ void KCMGRUB2::load() } = ui->checkBox_recovery->setChecked(unquoteWord(m_settings.value("GRUB_D= ISABLE_RECOVERY")).compare("true") !=3D 0); - if (QFile::exists(memtestPath)) { + if (QFile::exists(GRUB_MEMTEST)) { ui->checkBox_memtest->setVisible(true); - ui->checkBox_memtest->setChecked(QFile::permissions(memtestPath) &= (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther)); + ui->checkBox_memtest->setChecked(QFile::permissions(GRUB_MEMTEST) = & (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther)); } else { ui->checkBox_memtest->setVisible(false); } @@ -471,14 +460,9 @@ void KCMGRUB2::save() = Action saveAction("org.kde.kcontrol.kcmgrub2.save"); saveAction.setHelperID("org.kde.kcontrol.kcmgrub2"); - saveAction.addArgument("mkconfigExePath", mkconfigExePath); - saveAction.addArgument("set_defaultExePath", set_defaultExePath); - saveAction.addArgument("configFileName", configPath); saveAction.addArgument("rawConfigFileContents", configFileContents.toL= ocal8Bit()); - saveAction.addArgument("menuFileName", menuPath); saveAction.addArgument("rawDefaultEntry", !m_entries.isEmpty() ? grubD= efault : m_settings.value("GRUB_DEFAULT").toLocal8Bit()); if (m_dirtyBits.testBit(memtestDirty)) { - saveAction.addArgument("memtestFileName", memtestPath); saveAction.addArgument("memtest", ui->checkBox_memtest->isChecked(= )); } #if KDE_IS_VERSION(4,6,0) @@ -571,7 +555,7 @@ void KCMGRUB2::slotGrubDisableOsProberChanged() } void KCMGRUB2::slotInstallBootloader() { - QPointer installDlg =3D new InstallDialog(installExePat= h, this); + QPointer installDlg =3D new InstallDialog(this); installDlg->exec(); delete installDlg; } @@ -947,64 +931,6 @@ void KCMGRUB2::setupConnections() connect(ui->kpushbutton_install, SIGNAL(clicked(bool)), this, SLOT(slo= tInstallBootloader())); } = -QString KCMGRUB2::findExe(const QString &exeName) -{ - QString exePath =3D KStandardDirs::findExe(exeName); - if (!exePath.isEmpty()) { - return exePath; - } - KProcess whereis; - whereis << "whereis" << "-b" << exeName; - whereis.setOutputChannelMode(KProcess::OnlyStdoutChannel); - if (whereis.execute() =3D=3D 0) { - QString output =3D whereis.readAllStandardOutput(); - if (output.startsWith(exeName + ':')) { - return output.mid(exeName.length() + 1).trimmed(); - } - } - return QString(); -} -bool KCMGRUB2::check() -{ - installExePath =3D findExe("grub-install"); - mkconfigExePath =3D findExe("grub-mkconfig"); - probeExePath =3D findExe("grub-probe"); - set_defaultExePath =3D findExe("grub-set-default"); - if (!installExePath.isEmpty() && !mkconfigExePath.isEmpty() && !probeE= xePath.isEmpty() && !set_defaultExePath.isEmpty()) { - kDebug() << "GRUB2 installation detected!"; - menuPath =3D "/boot/grub/grub.cfg"; - configPath =3D "/etc/default/grub"; - envPath =3D "/boot/grub/grubenv"; - memtestPath =3D "/etc/grub.d/20_memtest86+"; - return true; - } - installExePath =3D findExe("grub2-install"); - mkconfigExePath =3D findExe("grub2-mkconfig"); - probeExePath =3D findExe("grub2-probe"); - set_defaultExePath =3D findExe("grub2-set-default"); - if (!installExePath.isEmpty() && !mkconfigExePath.isEmpty() && !probeE= xePath.isEmpty() && !set_defaultExePath.isEmpty()) { - kDebug() << "GRUB2 (RPM) installation detected!"; - menuPath =3D "/boot/grub2/grub.cfg"; - configPath =3D "/etc/default/grub"; - envPath =3D "/boot/grub2/grubenv"; - memtestPath =3D "/etc/grub.d/20_memtest86+"; - return true; - } - installExePath =3D findExe("burg-install"); - mkconfigExePath =3D findExe("burg-mkconfig"); - probeExePath =3D findExe("burg-probe"); - set_defaultExePath =3D findExe("burg-set-default"); - if (!installExePath.isEmpty() && !mkconfigExePath.isEmpty() && !probeE= xePath.isEmpty() && !set_defaultExePath.isEmpty()) { - kDebug() << "BURG installation detected!"; - menuPath =3D "/boot/burg/burg.cfg"; - configPath =3D "/etc/default/burg"; - envPath =3D "/boot/burg/burgenv"; - memtestPath =3D "/etc/burg.d/20_memtest86+"; - return true; - } - return false; -} - QString KCMGRUB2::convertToGRUBFileName(const QString &fileName) { QString grubFileName =3D fileName; @@ -1034,8 +960,23 @@ QString KCMGRUB2::convertToLocalFileName(const QStrin= g &grubFileName) return fileName; } = -QString KCMGRUB2::readFile(const QString &fileName) +QString KCMGRUB2::readFile(GrubFile grubFile) { + QString fileName; + switch (grubFile) { + case GrubMenuFile: + fileName =3D GRUB_MENU; + break; + case GrubConfigurationFile: + fileName =3D GRUB_CONFIG; + break; + case GrubEnvironmentFile: + fileName =3D GRUB_ENV; + break; + case GrubMemtestFile: + return QString(); + } + QFile file(fileName); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); @@ -1044,7 +985,7 @@ QString KCMGRUB2::readFile(const QString &fileName) = Action loadAction("org.kde.kcontrol.kcmgrub2.load"); loadAction.setHelperID("org.kde.kcontrol.kcmgrub2"); - loadAction.addArgument("fileName", fileName); + loadAction.addArgument("grubFile", grubFile); #if KDE_IS_VERSION(4,6,0) loadAction.setParentWidget(this); #endif @@ -1060,21 +1001,21 @@ QString KCMGRUB2::readFile(const QString &fileName) } void KCMGRUB2::readEntries() { - QString fileContents =3D readFile(menuPath); + QString fileContents =3D readFile(GrubMenuFile); = m_entries.clear(); parseEntries(fileContents); } void KCMGRUB2::readSettings() { - QString fileContents =3D readFile(configPath); + QString fileContents =3D readFile(GrubConfigurationFile); = m_settings.clear(); parseSettings(fileContents); } void KCMGRUB2::readEnv() { - QString fileContents =3D readFile(envPath); + QString fileContents =3D readFile(GrubEnvironmentFile); = m_env.clear(); parseEnv(fileContents); @@ -1090,7 +1031,6 @@ void KCMGRUB2::readDevices() = Action probeAction("org.kde.kcontrol.kcmgrub2.probe"); probeAction.setHelperID("org.kde.kcontrol.kcmgrub2"); - probeAction.addArgument("probeExePath", probeExePath); probeAction.addArgument("mountPoints", mountPoints); #if KDE_IS_VERSION(4,6,0) probeAction.setParentWidget(this); diff --git a/src/kcm_grub2.h b/src/kcm_grub2.h index 605029f..6afb0e0 100644 --- a/src/kcm_grub2.h +++ b/src/kcm_grub2.h @@ -29,6 +29,7 @@ namespace KAuth } = //Project +#include "config.h" class Entry; = //Ui @@ -83,14 +84,11 @@ private: void setupObjects(); void setupConnections(); = - QString findExe(const QString &exeName); - bool check(); - //TODO: Maybe remove? QString convertToGRUBFileName(const QString &fileName); QString convertToLocalFileName(const QString &grubFileName); = - QString readFile(const QString &fileName); + QString readFile(GrubFile grubFile); void readEntries(); void readSettings(); void readEnv(); @@ -135,15 +133,6 @@ private: }; QBitArray m_dirtyBits; = - QString installExePath; - QString mkconfigExePath; - QString probeExePath; - QString set_defaultExePath; - QString menuPath; - QString configPath; - QString envPath; - QString memtestPath; - QList m_entries; QHash m_settings; QHash m_env; diff --git a/ui/kcm_grub2.ui b/ui/kcm_grub2.ui index 24acc06..8a4bc41 100644 --- a/ui/kcm_grub2.ui +++ b/ui/kcm_grub2.ui @@ -6,635 +6,610 @@ 0 0 - 492 - 507 + 484 + 499 - + - + 0 - - + + + General + + + + + + Timeout + + + + + + + + Hide the menu for: + + + + + + + false + + + s + + + 1 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + false + + + Show countdown timer + + + + + + + Automatically boot the defa= ult entry after showing the menu + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Immediately + + + + + + + Qt::Horizontal + + + + 40 + 21 + + + + + + + + + + false + + + After: + + + true + + + + + + + false + + + s + + + 1 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 43 + + + + + + + + Generated Entries + + + + + + Generate recovery entries + + + + + + + Generate memtest entries + + + + + + + Probe for operating systems= + + + + + + - - - No valid GRUB2/BURG installation could= be detected! + + + Default Entry - - Qt::AlignCenter + + + + + Default Entry: + + + + + + + + + QComboBox::AdjustToContents + + + + + + + Remove Old Entries + + + + + + + + + The next booted entry will = become default + + + + + + + + + + + Appearance + + + + + + Resolutions + + + + + GRUB: + + + + + + + QComboBox::AdjustToContents + + + + + + + Linux Kernel: + + + + + + + QComboBox::AdjustToContents + + + + + + + + Colors + + + + + + + + Normal Foreground (Text)= : + + + + + + + + + + Highlight Foreground (Te= xt): + + + + + + + + + + + + + + Normal Background: + + + + + + + + + + Highlight Background: + + + + + + + + + + + + + + + Background + + + + + + Wallpaper: + + + + + + + + + + + + Preview + + + + + + + Create + + + + + + + + + Theme: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 69 + + + + - - + + + Advanced + + - - - 0 + + + Linux Kernel Arguments + + + + + + Normal Entries: + + + + + + + + + + + + Suggestions + + + + + + + + + All Entries: + + + + + + + + + + + + Suggestions + + + + + + + + + + + + Terminal + + + + + + Terminal: + + + + + + + + + + + + Suggestions + + + + + + + + + Input Terminal: + + + + + + + + + + + + Suggestions + + + + + + + + + Output Terminal: + + + + + + + + + + + + Suggestions + + + + + + + + + + + + Other + + + + + + Distributor: + + + + + + + + + + Serial Command: + + + + + + + + + + Init Tune: + + + + + + + + + + Enable UUIDs: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 43 + + + + + + + + Tools - - - General - - - - - - Timeout - - - - - - - - Hide the menu for: - - - - - - - false - - - s - - - 1 - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 40 - 20 - - - - - - - - false - - - Show countdown timer - - - - - - - Automatically boot the = default entry after showing the menu - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Immediately - - - - - - - Qt::Horizontal - - - - 40 - 21 - - - - - - - - - - false - - - After: - - - true - - - - - - - false - - - s - - - 1 - - - - - - - - - - - - Qt::Vertical - - - - 20 - 43 - - - - - - - - Generated Entries - - - - - - Generate recovery entri= es - - - - - - - Generate memtest entrie= s - - - - - - - Probe for operating sys= tems - - - - - - - - - - Default Entry - - - - - - Default Entry: - - - - - - - - - QComboBox::AdjustToContents - - - - - - - Remove Old Entries - - - - - - - - - The next booted entry w= ill become default - - - - - - - - - - - Appearance - - - - - - Resolutions - - - - - - GRUB: - - - - - - - QComboBox::AdjustToContents - - - - - - - Linux Kernel: - - - - - - - QComboBox::AdjustToContents - - - - - - - - - - Colors - - - - - - - - Normal Foreground (T= ext): - - - - - - - - - - Highlight Foreground= (Text): - - - - - - - - - - - - - - Normal Background: - - - - - - - - - - Highlight Background= : - - - - - - - - - - - - - - - Background - - - - - - Wallpaper: - - - - - - - - - - - - Preview - - - - - - - Create - - - - - - - - - Theme: - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 69 - - - - - - - - - Advanced - - - - - - Linux Kernel Arguments - - - - - - Normal Entries: - - - - - - - - - - - - Suggestions - - - - - - - - - All Entries: - - - - - - - - - - - - Suggestions - - - - - - - - - - - - Terminal - - - - - - Terminal: - - - - - - - - - - - - Suggestions - - - - - - - - - Input Terminal: - - - - - - - - - - - - Suggestions - - - - - - - - - Output Terminal: - - - - - - - - - - - - Suggestions - - - - - - - - - - - - Other - - - - - - Distributor: - - - - - - - - - - Serial Command: - - - - - - - - - - Init Tune: - - - - - - - - - - Enable UUIDs: - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 43 - - - - - - - - Tools - - - - - - - 0 - 0 - - - - Install/Recover Bootlo= ader - - - - - - - - + + + + + + 0 + 0 + + + + Install/Recover Bootloader= + + + +