Skip to content

Commit

Permalink
Add warning when updating repos as non-root to ssu cli, rewrite repos…
Browse files Browse the repository at this point in the history
… on all relevant changes
  • Loading branch information
Bernd Wachter committed Apr 6, 2013
1 parent 4fd6bed commit 44e6a2b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
39 changes: 38 additions & 1 deletion rndssucli/rndssucli.cpp
Expand Up @@ -8,6 +8,7 @@
#include <QCoreApplication>

#include <termios.h>
#include <unistd.h>

#include "libssu/ssudeviceinfo.h"
#include "libssu/ssurepomanager.h"
Expand Down Expand Up @@ -45,6 +46,11 @@ void RndSsuCli::optFlavour(QStringList opt){
qout << "Changing flavour from " << ssu.flavour()
<< " to " << opt.at(2) << endl;
ssu.setFlavour(opt.at(2));

SsuRepoManager repoManager;
repoManager.update();
uidWarning();

state = Idle;
} else if (opt.count() == 2) {
qout << "Device flavour is currently: " << ssu.flavour() << endl;
Expand Down Expand Up @@ -82,6 +88,11 @@ void RndSsuCli::optMode(QStringList opt){
qout << "Setting device mode from " << ssu.deviceMode()
<< " to " << opt.at(2) << endl;
ssu.setDeviceMode(opt.at(2).toInt());

SsuRepoManager repoManager;
repoManager.update();
uidWarning();

state = Idle;
}
}
Expand All @@ -95,23 +106,28 @@ void RndSsuCli::optModifyRepo(int action, QStringList opt){
case Add:
repoManager.add(opt.at(2));
repoManager.update();
uidWarning();
break;
case Remove:
repoManager.remove(opt.at(2));
repoManager.update();
uidWarning();
break;
case Disable:
repoManager.disable(opt.at(2));
repoManager.update();
uidWarning();
break;
case Enable:
repoManager.enable(opt.at(2));
repoManager.update();
uidWarning();
break;
}
} else if (opt.count() == 4 && action == Add){
repoManager.add(opt.at(2), opt.at(3));
repoManager.update();
uidWarning();
}
}

Expand Down Expand Up @@ -156,6 +172,11 @@ void RndSsuCli::optRelease(QStringList opt){
<< " to " << opt.at(2) << endl;
qout << "Your device is now in release mode!" << endl;
ssu.setRelease(opt.at(2));

SsuRepoManager repoManager;
repoManager.update();
uidWarning();

state = Idle;
}
} else if (opt.count() == 2) {
Expand All @@ -166,6 +187,11 @@ void RndSsuCli::optRelease(QStringList opt){
<< " to " << opt.at(3) << endl;
qout << "Your device is now in RnD mode!" << endl;
ssu.setRelease(opt.at(3), true);

SsuRepoManager repoManager;
repoManager.update();
uidWarning();

state = Idle;
}
}
Expand Down Expand Up @@ -364,6 +390,7 @@ void RndSsuCli::optUpdateCredentials(QStringList opt){
void RndSsuCli::optUpdateRepos(){
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
}

void RndSsuCli::run(){
Expand Down Expand Up @@ -428,8 +455,18 @@ void RndSsuCli::run(){
usage();
}

void RndSsuCli::uidWarning(QString message){
if (message.isEmpty())
message = "Run 'ssu ur' as root to recreate repository files";

if (geteuid() != 0){
QTextStream qout(stderr);
qout << "You're not root. " << message << endl;
}
}

void RndSsuCli::usage(){
QTextStream qout(stdout);
QTextStream qout(stderr);
qout << "\nUsage: ssu <command> [-command-options] [arguments]" << endl
<< endl
<< "Repository management:" << endl
Expand Down
1 change: 1 addition & 0 deletions rndssucli/rndssucli.h
Expand Up @@ -29,6 +29,7 @@ class RndSsuCli: public QObject {
QSettings settings;
int state;
void usage();
void uidWarning(QString message="");
void optFlavour(QStringList opt);
void optMode(QStringList opt);
void optModifyRepo(int action, QStringList opt);
Expand Down

0 comments on commit 44e6a2b

Please sign in to comment.