[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kcmgrub2] /: Rework the code that deals with grub configuration files and scripts
From: Alberto Mattea <alberto () mattea ! info>
Date: 2012-03-20 20:38:47
Message-ID: 20120320203847.3A2D2A60A9 () git ! kde ! org
[Download RAW message or body]
Git commit 91f7077a5fa4ffb4ed5582e574c971f02047f710 by Alberto Mattea.
Committed on 20/03/2012 at 20:48.
Pushed by mattea into branch 'master'.
Rework the code that deals with grub configuration files and scripts
- No more need to fix permissions
- No password needed for vbetest
- Supports Fedora 17 prefixes
- Works on systems that do not provide update-grub
M +59 -23 helper/helper.cpp
M +2 -2 helper/helper.h
M +9 -41 helper/kcmgrub2_actions.actions
M +11 -11 kcmgrub2.py
http://commits.kde.org/kcmgrub2/91f7077a5fa4ffb4ed5582e574c971f02047f710
diff --git a/helper/helper.cpp b/helper/helper.cpp
index adf31d1..bf54472 100644
--- a/helper/helper.cpp
+++ b/helper/helper.cpp
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <sys/stat.h>
#include <KProcess>
+#include <QFile>
#include <QDebug>
#include <unistd.h>
@@ -54,28 +55,63 @@ int Grub2Helper::chMemtest(QString path, QString on)
int Grub2Helper::doUpdate()
{
KProcess updProcess;
- updProcess.setShellCommand("update-grub");
+ QFile mkconfig;
+ QString config=findGrubCfg();
+ if (config==QString(""))
+ return 5;
+ QString toexec;
+ mkconfig.setFileName("/usr/sbin/grub2-mkconfig");
+ if (mkconfig.exists()) {
+ toexec.append("/usr/sbin/grub2-mkconfig");
+ } else {
+ mkconfig.setFileName("/usr/sbin/grub-mkconfig");
+ if (mkconfig.exists()) {
+ toexec.append("/usr/sbin/grub-mkconfig");
+ } else {
+ return 5;
+ }
+ }
+ updProcess.setShellCommand(toexec.append(" -o ").append(config));
if (updProcess.execute()!=0)
return 5;
return 0;
}
-int Grub2Helper::chGrubcfg()
+QString Grub2Helper::findGrubCfg()
{
- if (chmod("/boot/grub/grub.cfg", S_IRUSR | S_IRGRP | S_IROTH) != 0) { // We need \
read access to grub.cfg
- if (chmod("/grub/grub.cfg", S_IRUSR | S_IRGRP | S_IROTH) != 0) // BSD
- return 6;
- }
- return 0;
+ QFile file;
+ file.setFileName("/grub/grub.cfg");
+ if (file.exists())
+ return QString("/grub/grub.cfg");
+ file.setFileName("/boot/grub2/grub.cfg");
+ if (file.exists())
+ return QString("/boot/grub2/grub.cfg");
+ file.setFileName("/boot/grub/grub.cfg");
+ if (file.exists())
+ return QString("/boot/grub/grub.cfg");
+ return QString("");
}
int Grub2Helper::doInstall(QList<QVariant> devices)
{
KProcess instProcess;
int i;
+ QFile file;
+ QString toexec;
+ file.setFileName("/usr/sbin/grub2-install");
+ if (file.exists()) {
+ toexec.append("/usr/sbin/grub2-install");
+ } else {
+ file.setFileName("/usr/sbin/grub-install");
+ if (file.exists()) {
+ toexec.append("/usr/sbin/grub-install");
+ } else {
+ return 7;
+ }
+ }
for (i=0;i<devices.count();i++) {
QStringList cmd;
- cmd << QString("/usr/sbin/grub-install") << devices[i].toString();
+ cmd << toexec << devices[i].toString();
instProcess.setProgram(cmd);
if(instProcess.execute()!=0)
return 7;
@@ -99,9 +135,6 @@ ActionReply Grub2Helper::save(const QVariantMap &args)
ret=doUpdate();
if (ret!=0)
goto finish;
- ret=chGrubcfg();
- if (ret!=0)
- goto finish;
HelperSupport::progressStep(2);
ret=doInstall(args["grubinst"].toList());
@@ -117,21 +150,24 @@ ActionReply Grub2Helper::save(const QVariantMap &args)
}
}
-ActionReply Grub2Helper::fixperm(const QVariantMap &args)
+ActionReply Grub2Helper::readcfg(const QVariantMap &args)
{
(void)args; // Fix warning
- int ret=0;
- if (chmod("/boot/grub/grub.cfg", S_IRUSR | S_IRGRP | S_IROTH) != 0) { // We need \
read access to grub.cfg
- if (chmod("/grub/grub.cfg", S_IRUSR | S_IRGRP | S_IROTH) != 0) // BSD
- ret=6;
- }
- if (ret == 0) {
- return ActionReply::SuccessReply;
- } else {
- ActionReply reply(ActionReply::HelperError);
- reply.setErrorCode(ret);
- return reply;
+ ActionReply errorreply(ActionReply::HelperError);
+ errorreply.setErrorCode(6);
+ QFile file;
+ QString config=findGrubCfg();
+ file.setFileName(config);
+ if (!file.open(QIODevice::ReadOnly)) {
+ return errorreply;
}
+ const QByteArray data=file.readAll();
+ file.close();
+ ActionReply reply(ActionReply::SuccessReply);
+ QVariantMap retdata;
+ retdata["contents"] = data;
+ reply.setData(retdata);
+ return reply;
}
ActionReply Grub2Helper::probevbe(const QVariantMap &args)
diff --git a/helper/helper.h b/helper/helper.h
index 4b7748f..551b38e 100644
--- a/helper/helper.h
+++ b/helper/helper.h
@@ -12,14 +12,14 @@ class Grub2Helper : public QObject
public slots:
ActionReply save(const QVariantMap &map);
- ActionReply fixperm(const QVariantMap &map);
+ ActionReply readcfg(const QVariantMap &map);
ActionReply probevbe(const QVariantMap &map);
private:
int writeGrubcfg(const char data[]);
int writeScripts(QMap<QString, QVariant> map);
int chMemtest(QString path, QString on);
int doUpdate();
- int chGrubcfg();
+ QString findGrubCfg();
int doInstall(QList<QVariant> devices);
};
#endif
diff --git a/helper/kcmgrub2_actions.actions b/helper/kcmgrub2_actions.actions
index f41b6af..96138b8 100644
--- a/helper/kcmgrub2_actions.actions
+++ b/helper/kcmgrub2_actions.actions
@@ -62,46 +62,14 @@ Description[uk]=Щоб змінювати \
налаштування завант Description[x-test]=xxYou need to be root to \
change bootloader configurationxx Policy=auth_admin
-[org.kde.kcontrol.kcmgrub2.fixperm]
-Name=Fix permissions of the bootloader configuration file
-Name[ca]=Fixa els permisos del fitxer de configuració del gestor d'arrencada
-Name[da]=Tilpas rettigheder på bootloaderens konfigurationsfil
-Name[de]=Berechtigungen für die Bootloader-Konfigurationsdateien korrigieren.
-Name[es]=Corregir los permisos del archivo de configuración del cargador de \
arranque
-Name[et]=Alglaaduri seadistusfaili õiguste muutmine
-Name[fr]=Correction des droits d'accès du fichier de configuration du chargeur \
d'amorçage
-Name[gl]=Corrixir os permisos do ficheiro do cargador de arrinque
-Name[hr]=Popravi dozvole konfiguracijske datoteke programa punilaca
-Name[hu]=A rendszerbetöltő beállítófájlja jogosultságainak javítása
-Name[it]=Sistema i permessi del file di configurazione del bootloader
-Name[lt]=Taisyti įkrovos tvarkyklės konfigūracijos failo leidimus
-Name[nl]=Rechten op het configuratiebestand van de bootloader repareren
-Name[pl]=Napraw uprawnienia pliku konfiguracyjnego program rozruchowego
-Name[pt]=Corrigir as permissões do ficheiro de configuração do gestor de arranque
-Name[pt_BR]=Corrigir as permissões do arquivo de configuração do gerenciador de \
inicialização
-Name[sv]=Korrigera rättigheter för startprogrammets inställningsfil
-Name[uk]=Виправити права доступу до файла \
налаштувань завантажувача
-Name[x-test]=xxFix permissions of the bootloader configuration filexx
-Description=You need to be root to change bootloader configuration
-Description[ca]=Heu de ser el superusuari (root) per canviar la configuració del \
gestor d'arrencada
-Description[da]=Du skal være root for at ændre bootloader-konfigurationen
-Description[de]=Nur der Systemverwalter kann Änderungen an den \
Systemstarteinstellungen vornehmen.
-Description[es]=Debe ser root para cambiar la configuración del cargador de \
arranque
-Description[et]=Alglaaduri seadistuste muutmiseks peab olema administraator
-Description[fr]=Vous devez être superutilisateur pour changer la configuration du \
chargeur d'amorçage
-Description[gl]=Precisa ser root para modificar a configuración do cargador de \
arrinque
-Description[hr]=Trebate biti root kako biste mogli promijeniti konfiguraciju \
programa punilaca
-Description[hu]=A rendszerbetöltő beállításainak módosításához \
újraindítás szükséges
-Description[it]=Devi avere i permessi di root per cambiare la configurazione del \
bootloader
-Description[lt]=Privalote turėti administratoriaus teises, kad galėtumėte keisti \
įkrovos tvarkyklės konfigūraciją
-Description[nl]=U dient als root te zijn aangemeld om de instellingen van de \
bootloader te kunnen wijzigen
-Description[pl]=Musisz być administratorem, aby zmienić konfigurację programu \
rozruchowego
-Description[pt]=Tem de ser o 'root' para mudar a configuração do gestor de \
arranque
-Description[pt_BR]=Você precisa autenticar-se como administrador para alterar a \
configuração do gerenciador de inicialização
-Description[sv]=Du måste vara systemadministratör för att ändra inställning av \
startprogram
-Description[uk]=Щоб змінювати налаштування \
завантажувача, потрібні права доступу \
адміністратора (root)
-Description[x-test]=xxYou need to be root to change bootloader configurationxx
-Policy=auth_admin
+[org.kde.kcontrol.kcmgrub2.readcfg]
+Name=Read bootloader configuration file
+Name[it]=Leggi il file di configurazione del bootloader
+Name[x-test]=xxRead bootloader configuration filexx
+Description=You need to be root to read bootloader configuration
+Description[it]=Devi avere i permessi di root per leggere la configurazione del \
bootloader +Description[x-test]=xxYou need to be root to read bootloader \
configurationxx +Policy=yes
[org.kde.kcontrol.kcmgrub2.probevbe]
Name=Probe the video card for vbe resolutions
@@ -141,4 +109,4 @@ Description[pt_BR]=Você precisa autenticar-se como administrador \
para testar a Description[sv]=Du måste vara systemadministratör för att läsa av \
videokortet Description[uk]=Для визначення можливостей \
відеокартки потрібні права доступу \
адміністратора (root) Description[x-test]=xxYou need to be root to \
probe the video cardxx
-Policy=auth_admin
+Policy=yes
diff --git a/kcmgrub2.py b/kcmgrub2.py
index 465a5de..8e83355 100755
--- a/kcmgrub2.py
+++ b/kcmgrub2.py
@@ -171,17 +171,14 @@ class PyKcm(KCModule):
return None
def getGrubCfg(self):
- if not (os.access("/boot/grub/grub.cfg", os.R_OK) or os.access("/grub/grub.cfg", \
os.R_OK)):
- KMessageBox.information(self, i18n("The configuration file has wrong \
permissions, you will now be asked for your password to fix them."))
- self.fixAction=KAuth.Action("org.kde.kcontrol.kcmgrub2.fixperm")
- self.fixAction.setHelperID("org.kde.kcontrol.kcmgrub2")
- reply=self.fixAction.execute()
- if reply.failed(): KMessageBox.error(self, i18n("Cannot fix the permissions"))
- else: self.load()
- try: self.grubCfg=open("/boot/grub/grub.cfg").read()
- except: self.grubCfg=open("/grub/grub.cfg").read() # NetBSD, OpenBSD
- self.currentItems=self.getCurrentItems()
- self.currentColors=self.getCurrentColors()
+ self.readAction=KAuth.Action("org.kde.kcontrol.kcmgrub2.readcfg")
+ self.readAction.setHelperID("org.kde.kcontrol.kcmgrub2")
+ reply=self.readAction.execute()
+ if reply.failed(): raise OSError
+ else:
+ self.grubCfg=unicode(reply.data()[QString(u'contents')].toString(), "utf-8")
+ self.currentItems=self.getCurrentItems()
+ self.currentColors=self.getCurrentColors()
def getCurrentItems(self):
lines=self.grubCfg.splitlines()
@@ -291,6 +288,9 @@ class PyKcm(KCModule):
for f in os.environ["PATH"].split(":"):
cur=f + "/" + "grub-mkconfig"
if os.path.exists(cur): break
+ else:
+ cur=f + "/" + "grub2-mkconfig"
+ if os.path.exists(cur): break
else: return
source=open(cur).read()
pkgName=re.compile(r"PACKAGE_NAME=(.*)", re.IGNORECASE)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic