Make default groups, users group and autologin group configurable.

This commit is contained in:
Teo Mrnjavac 2014-10-08 15:05:23 +02:00
parent 0d1fb79ec8
commit ad68ce0187
6 changed files with 88 additions and 10 deletions

View File

@ -30,11 +30,17 @@
#include <QTextStream>
CreateUserJob::CreateUserJob( const QString& userName, const QString& fullName, bool autologin )
CreateUserJob::CreateUserJob( const QString& userName,
const QString& fullName,
bool autologin,
const QString& userGroup,
const QStringList& defaultGroups )
: Calamares::Job()
, m_userName( userName )
, m_fullName( fullName )
, m_autologin( autologin )
, m_userGroup( userGroup )
, m_defaultGroups( defaultGroups )
{
}
@ -66,12 +72,35 @@ CreateUserJob::exec()
if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) )
return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) );
QFileInfo groupsFi( destDir.absoluteFilePath( "etc/group" ) );
QFile groupsFile( groupsFi.absoluteFilePath() );
if ( !groupsFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
return Calamares::JobResult::error( tr( "Cannot open groups file for reading." ) );
QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() );
QStringList groupsLines = groupsData.split( '\n' );
for ( QStringList::iterator it = groupsLines.begin();
it != groupsLines.end(); ++it )
{
int indexOfFirstToDrop = it->indexOf( ':' );
it->truncate( indexOfFirstToDrop );
}
QString defaultGroups( "lp,video,network,storage,wheel,audio" );
foreach ( const QString& group, m_defaultGroups )
if ( !groupsLines.contains( group ) )
CalamaresUtils::chrootCall( { "groupadd", group } );
QString defaultGroups = m_defaultGroups.join( ',' );
if ( m_autologin )
{
CalamaresUtils::chrootCall( { "groupadd", "autologin" } );
defaultGroups.append( ",autologin" );
QString autologinGroup;
if ( gs->contains( "autologinGroup" ) &&
!gs->value( "autologinGroup" ).toString().isEmpty() )
autologinGroup = gs->value( "autologinGroup" ).toString();
else
autologinGroup = QStringLiteral( "autologin" );
CalamaresUtils::chrootCall( { "groupadd", autologinGroup } );
defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) );
}
int ec = CalamaresUtils::chrootCall( { "useradd",
@ -98,7 +127,8 @@ CreateUserJob::exec()
ec = CalamaresUtils::chrootCall( { "chown",
"-R",
QString( "%1:users" ).arg( m_userName ),
QString( "%1:%2" ).arg( m_userName )
.arg( m_userGroup ),
QString( "/home/%1" ).arg( m_userName ) } );
if ( ec )
return Calamares::JobResult::error( tr( "Cannot set home directory ownership for user %1." )

View File

@ -21,6 +21,7 @@
#include <Job.h>
#include <QStringList>
class CreateUserJob : public Calamares::Job
{
@ -28,7 +29,9 @@ class CreateUserJob : public Calamares::Job
public:
CreateUserJob( const QString& userName,
const QString& fullName,
bool autologin );
bool autologin,
const QString& userGroup,
const QStringList& defaultGroups );
QString prettyName() const override;
Calamares::JobResult exec() override;
@ -36,6 +39,8 @@ private:
QString m_userName;
QString m_fullName;
bool m_autologin;
QString m_userGroup;
QStringList m_defaultGroups;
};
#endif /* CREATEUSERJOB_H */

View File

@ -87,7 +87,7 @@ UsersPage::isReady()
QList< Calamares::job_ptr >
UsersPage::createJobs()
UsersPage::createJobs( const QString& defaultUserGroup, const QStringList& defaultGroupsList )
{
QList< Calamares::job_ptr > list;
if ( !isReady() )
@ -96,7 +96,9 @@ UsersPage::createJobs()
Calamares::Job* j;
j = new CreateUserJob( ui->textBoxUsername->text(),
QString(),
ui->checkBoxLoginAuto->isChecked() );
ui->checkBoxLoginAuto->isChecked(),
defaultUserGroup,
defaultGroupsList );
list.append( Calamares::job_ptr( j ) );
j = new SetPasswordJob( ui->textBoxUsername->text(),

View File

@ -40,7 +40,8 @@ public:
bool isReady();
QList< Calamares::job_ptr > createJobs();
QList< Calamares::job_ptr > createJobs( const QString& defaultUserGroup,
const QStringList& defaultGroupsList );
protected slots:
void onFullNameTextEdited( const QString& );

View File

@ -20,6 +20,9 @@
#include "UsersPage.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
UsersViewStep::UsersViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new UsersPage() )
@ -96,6 +99,36 @@ UsersViewStep::onLeave()
{
m_jobs.clear();
m_jobs.append( m_widget->createJobs() );
m_jobs.append( m_widget->createJobs( m_userGroup, m_defaultGroups ) );
}
void
UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
if ( configurationMap.contains( "userGroup" ) &&
configurationMap.value( "userGroup" ).type() == QVariant::String )
{
m_userGroup = configurationMap.value( "userGroup" ).toString();
}
if ( m_userGroup.isEmpty() )
m_userGroup = QStringLiteral( "users" );
if ( configurationMap.contains( "defaultGroups" ) &&
configurationMap.value( "defaultGroups" ).type() == QVariant::List )
{
m_defaultGroups = configurationMap.value( "defaultGroups" ).toStringList();
}
else
{
m_defaultGroups = { "lp", "video", "network", "storage", "wheel", "audio" };
}
if ( configurationMap.contains( "autologinGroup" ) &&
configurationMap.value( "autologinGroup" ).type() == QVariant::String )
{
Calamares::JobQueue::instance()->globalStorage()->insert( "autologinGroup",
configurationMap.value( "autologinGroup" ).toString() );
}
}

View File

@ -24,6 +24,8 @@
#include "viewpages/ViewStep.h"
#include "PluginDllMacro.h"
#include <QVariant>
class UsersPage;
class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep
@ -53,9 +55,14 @@ public:
void onLeave() override;
void setConfigurationMap( const QVariantMap &configurationMap ) override;
private:
UsersPage* m_widget;
QList< Calamares::job_ptr > m_jobs;
QString m_userGroup;
QStringList m_defaultGroups;
};
#endif // USERSPAGEPLUGIN_H