Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add repo management from CLI, build documentation
  • Loading branch information
Bernd Wachter committed Mar 30, 2013
1 parent 678531b commit 388cd8d
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 31 deletions.
9 changes: 4 additions & 5 deletions libssu/ssu.h
Expand Up @@ -17,7 +17,6 @@
#include <QtXml/QDomDocument>

#include <ssudeviceinfo.h>
#include <ssusettings.h>

class Ssu: public QObject {
Q_OBJECT
Expand Down Expand Up @@ -106,10 +105,10 @@ class Ssu: public QObject {
* now any mode where RndMode is not set is treated as ReleaseMode.
*/
enum DeviceMode {
DisableRepoManager = 0x1, ///< Disable automagic repository management
RndMode = 0x2, ///< Enable RnD mode for device
ReleaseMode = 0x4, ///< Enable Release mode
StrictMode = 0x8 ///< Enable strict mode (i.e., delete unmanaged repositories)
DisableRepoManager = 0x1, ///< Disable automagic repository management
RndMode = 0x2, ///< Enable RnD mode for device
ReleaseMode = 0x4, ///< Enable Release mode
LenientMode = 0x8 ///< Disable strict mode (i.e., keep unmanaged repositories)
};

/**
Expand Down
6 changes: 2 additions & 4 deletions libssu/ssucoreconfig.cpp
Expand Up @@ -51,11 +51,9 @@ QString SsuCoreConfig::flavour(){
}

int SsuCoreConfig::deviceMode(){
if (!contains("deviceMode")){
setValue("deviceMode", Ssu::ReleaseMode);
sync();
if (!contains("deviceMode"))
return Ssu::ReleaseMode;
} else
else
return value("deviceMode").toInt();
}

Expand Down
4 changes: 4 additions & 0 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -191,6 +191,10 @@ QStringList SsuDeviceInfo::repos(bool rnd){
result.append(ssuSettings->allKeys());
ssuSettings->endGroup();

// read user-enabled repositories from ssu.ini
if (ssuSettings->contains("enabled-repos"))
result.append(ssuSettings->value("enabled-repos").toStringList());

result.removeDuplicates();

// read the disabled repositories for this device
Expand Down
65 changes: 64 additions & 1 deletion libssu/ssurepomanager.cpp
Expand Up @@ -22,6 +22,69 @@ SsuRepoManager::SsuRepoManager(): QObject() {

}

void SsuRepoManager::add(QString repo, QString repoUrl){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();

if (repoUrl == ""){
// just enable a repository which has URL in repos.ini
QStringList enabledRepos;
if (ssuSettings->contains("enabled-repos"))
enabledRepos = ssuSettings->value("enabled-repos").toStringList();

enabledRepos.append(repo);
enabledRepos.removeDuplicates();
ssuSettings->setValue("enabled-repos", enabledRepos);
} else
ssuSettings->setValue("repository-urls/" + repo, repoUrl);

ssuSettings->sync();
}

void SsuRepoManager::disable(QString repo){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
QStringList disabledRepos;

if (ssuSettings->contains("disabled-repos"))
disabledRepos = ssuSettings->value("disabled-repos").toStringList();

disabledRepos.append(repo);
disabledRepos.removeDuplicates();

ssuSettings->setValue("disabled-repos", disabledRepos);
ssuSettings->sync();
}

void SsuRepoManager::enable(QString repo){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
QStringList disabledRepos;

if (ssuSettings->contains("disabled-repos"))
disabledRepos = ssuSettings->value("disabled-repos").toStringList();

disabledRepos.removeAll(repo);
disabledRepos.removeDuplicates();

ssuSettings->setValue("disabled-repos", disabledRepos);
ssuSettings->sync();
}

void SsuRepoManager::remove(QString repo){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
if (ssuSettings->contains("repository-urls/" + repo))
ssuSettings->remove("repository-urls/" + repo);

if (ssuSettings->contains("enabled-repos")){
QStringList enabledRepos = ssuSettings->value("enabled-repos").toStringList();
if (enabledRepos.contains(repo)){
enabledRepos.removeAll(repo);
enabledRepos.removeDuplicates();
ssuSettings->setValue("enabled-repos", enabledRepos);
}
}

ssuSettings->sync();
}

void SsuRepoManager::update(){
// - delete all non-ssu managed repositories (missing ssu_ prefix)
// - create list of ssu-repositories for current adaptation
Expand Down Expand Up @@ -52,7 +115,7 @@ void SsuRepoManager::update(){
// strict mode enabled -> delete all repositories not prefixed by ssu
// assume configuration error if there are no device repos, and don't delete
// anything, even in strict mode
if ((deviceMode & Ssu::StrictMode) == Ssu::StrictMode && !repos.isEmpty()){
if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repos.isEmpty()){
QDirIterator it(ZYPP_REPO_PATH, QDir::AllEntries|QDir::NoDot|QDir::NoDotDot);
while (it.hasNext()){
it.next();
Expand Down
21 changes: 18 additions & 3 deletions libssu/ssurepomanager.h
Expand Up @@ -18,9 +18,23 @@ class SsuRepoManager: public QObject {
public:
SsuRepoManager();
/**
* Look up all variables in the specified configuration file section,
* run them through the variable expander, and add them to the supplied
* QHash
* Add a repository
*/
void add(QString repo, QString repoUrl="");
/**
* Disable a repository
*/
void disable(QString repo);
/**
* Enable a repository, given it's not disabled by board configuration
*/
void enable(QString repo);
/**
* Remove a repository
*/
void remove(QString repo);
/**
* Update the repository files on disk
*/
void update();
/**
Expand All @@ -30,6 +44,7 @@ class SsuRepoManager: public QObject {
QString url(QString repoName, bool rndRepo=false,
QHash<QString, QString> repoParameters=QHash<QString, QString>(),
QHash<QString, QString> parametersOverride=QHash<QString, QString>());

};

#endif
48 changes: 33 additions & 15 deletions rndssucli/rndssucli.cpp
Expand Up @@ -53,29 +53,47 @@ void RndSsuCli::optFlavour(QStringList opt){

void RndSsuCli::optMode(QStringList opt){
QTextStream qout(stdout);
qout << "Mode handling is currently not implemented" << endl;
state = Idle;

// TODO: allow setting meaningful names instead of numbers

if (opt.count() == 2){
qout << "Device mode is: " << ssu.deviceMode() << endl;
state = Idle;
} else if (opt.count() == 3){
qout << "Setting device mode from " << ssu.deviceMode()
<< " to " << opt.at(2) << endl;
ssu.setDeviceMode(opt.at(2).toInt());
state = Idle;
}
}

void RndSsuCli::optModifyRepo(int action, QStringList opt){
SsuRepoManager repoManager;

QTextStream qout(stdout);
qout << "Repository management is currently not implemented" << endl;

if (opt.count() == 3){

} else if (opt.count() == 4){

}
/*
switch(action){
case Add:
case Remove:
case Disable:
case Enable:
switch(action){
case Add:
repoManager.add(opt.at(2));
repoManager.update();
break;
case Remove:
repoManager.remove(opt.at(2));
repoManager.update();
break;
case Disable:
repoManager.disable(opt.at(2));
repoManager.update();
break;
case Enable:
repoManager.enable(opt.at(2));
repoManager.update();
break;
}
} else if (opt.count() == 4 && action == Add){
repoManager.add(opt.at(2), opt.at(3));
repoManager.update();
}
*/
}

void RndSsuCli::optRegister(){
Expand Down
5 changes: 5 additions & 0 deletions rpm/ssu.changes
@@ -1,3 +1,8 @@
* Sat Mar 30 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.28
- Add repository management
- Add basic device mode handling
- Disable credentials handling for insecure repositories

* Wed Mar 27 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.27
- Add support for := in variable substitution

Expand Down
26 changes: 24 additions & 2 deletions rpm/ssu.spec
@@ -1,5 +1,5 @@
Name: ssu
Version: 0.27
Version: 0.28
Release: 1
Summary: SSU enabler for RND
Group: System/Base
Expand All @@ -11,6 +11,8 @@ BuildRequires: pkgconfig(libzypp)
BuildRequires: pkgconfig(QtSystemInfo)
BuildRequires: pkgconfig(qt-boostable)
BuildRequires: pkgconfig(libsystemd-journal)
BuildRequires: oneshot
BuildRequires: doxygen
Requires(pre): shadow-utils
Requires(postun): shadow-utils
Requires: ssu-vendor-data
Expand All @@ -25,6 +27,9 @@ Requires: ssu-vendor-data
%{_bindir}/ssu
%{_libdir}/*.so.*
%dir %{_sysconfdir}/zypp/credentials.d
# ssu itself does not use the package-update triggers, but provides
# them for the vendor data packages to use
%attr(0755, -, -) %{_oneshotdir}/*


%package vendor-data-example
Expand Down Expand Up @@ -93,19 +98,35 @@ Requires: rpm
%attr(0755, -, -) /usr/sbin/ssu-repos.sh


%package doc
Summary: Documentation for %{name}
Group: Documentation

%description doc
%{summary}.

%files doc
%defattr(-,root,root,-)
%{_docdir}/%{name}


%prep
%setup -q -n %{name}-%{version}


%build
qmake DEFINES+='TARGET_ARCH=\\\"\"%{_target_cpu}\"\\\"' -recursive
make %{?_smp_mflags}
doxygen doc/Doxyfile


%install
make INSTALL_ROOT=%{buildroot} install
mkdir -p %{buildroot}/%{_sysconfdir}/zypp/credentials.d
ln -s %{_bindir}/ssu %{buildroot}/%{_bindir}/rndssu
mkdir -p %{buildroot}/%{_docdir}/%{name}
cp -R doc/html/* %{buildroot}/%{_docdir}/%{name}/


%pre
groupadd -rf ssu
Expand All @@ -124,4 +145,5 @@ if [ "$1" == 0 ]; then
getent group ssu >/dev/null && groupdel ssu
fi

%post -p /sbin/ldconfig
%post
/sbin/ldconfig
7 changes: 7 additions & 0 deletions ssu-update-repos
@@ -0,0 +1,7 @@
#!/bin/sh

if [ -z "$MIC_RUN" ]; then
/usr/bin/ssu updaterepos
else
exit 1
fi
5 changes: 4 additions & 1 deletion ssu.pro
Expand Up @@ -20,7 +20,10 @@ tests.depends = libssu
config.files = ssu.ini
config.path = /etc/ssu

oneshot.files = ssu-update-repos
oneshot.path = /usr/lib/oneshot.d

static_config.files = repos.ini ssu-defaults.ini board-mappings.ini
static_config.path = /usr/share/ssu

INSTALLS += config static_config
INSTALLS += config static_config oneshot

0 comments on commit 388cd8d

Please sign in to comment.