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> #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() : Calamares::Job()
, m_userName( userName ) , m_userName( userName )
, m_fullName( fullName ) , m_fullName( fullName )
, m_autologin( autologin ) , m_autologin( autologin )
, m_userGroup( userGroup )
, m_defaultGroups( defaultGroups )
{ {
} }
@ -66,12 +72,35 @@ CreateUserJob::exec()
if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) ) if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) )
return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) ); 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 ) if ( m_autologin )
{ {
CalamaresUtils::chrootCall( { "groupadd", "autologin" } ); QString autologinGroup;
defaultGroups.append( ",autologin" ); 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", int ec = CalamaresUtils::chrootCall( { "useradd",
@ -98,7 +127,8 @@ CreateUserJob::exec()
ec = CalamaresUtils::chrootCall( { "chown", ec = CalamaresUtils::chrootCall( { "chown",
"-R", "-R",
QString( "%1:users" ).arg( m_userName ), QString( "%1:%2" ).arg( m_userName )
.arg( m_userGroup ),
QString( "/home/%1" ).arg( m_userName ) } ); QString( "/home/%1" ).arg( m_userName ) } );
if ( ec ) if ( ec )
return Calamares::JobResult::error( tr( "Cannot set home directory ownership for user %1." ) return Calamares::JobResult::error( tr( "Cannot set home directory ownership for user %1." )

View File

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

View File

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

View File

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

View File

@ -20,6 +20,9 @@
#include "UsersPage.h" #include "UsersPage.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
UsersViewStep::UsersViewStep( QObject* parent ) UsersViewStep::UsersViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_widget( new UsersPage() ) , m_widget( new UsersPage() )
@ -96,6 +99,36 @@ UsersViewStep::onLeave()
{ {
m_jobs.clear(); 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 "viewpages/ViewStep.h"
#include "PluginDllMacro.h" #include "PluginDllMacro.h"
#include <QVariant>
class UsersPage; class UsersPage;
class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep
@ -53,9 +55,14 @@ public:
void onLeave() override; void onLeave() override;
void setConfigurationMap( const QVariantMap &configurationMap ) override;
private: private:
UsersPage* m_widget; UsersPage* m_widget;
QList< Calamares::job_ptr > m_jobs; QList< Calamares::job_ptr > m_jobs;
QString m_userGroup;
QStringList m_defaultGroups;
}; };
#endif // USERSPAGEPLUGIN_H #endif // USERSPAGEPLUGIN_H