[users] Create groups in a separate job
This commit is contained in:
parent
03541470d5
commit
f1772a7eae
@ -821,6 +821,9 @@ Config::createJobs() const
|
||||
jobs.append( Calamares::job_ptr( j ) );
|
||||
}
|
||||
|
||||
j = new SetupGroupsJob( this );
|
||||
jobs.append( Calamares::job_ptr( j ) );
|
||||
|
||||
j = new CreateUserJob( this );
|
||||
jobs.append( Calamares::job_ptr( j ) );
|
||||
|
||||
|
@ -50,53 +50,6 @@ CreateUserJob::prettyStatusMessage() const
|
||||
return m_status.isEmpty() ? tr( "Creating user %1." ).arg( m_config->loginName() ) : m_status;
|
||||
}
|
||||
|
||||
STATICTEST QStringList
|
||||
groupsInTargetSystem( const QDir& targetRoot )
|
||||
{
|
||||
QFileInfo groupsFi( targetRoot.absoluteFilePath( "etc/group" ) );
|
||||
QFile groupsFile( groupsFi.absoluteFilePath() );
|
||||
if ( !groupsFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
return QStringList();
|
||||
}
|
||||
QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() );
|
||||
QStringList groupsLines = groupsData.split( '\n' );
|
||||
QStringList::iterator it = groupsLines.begin();
|
||||
while ( it != groupsLines.end() )
|
||||
{
|
||||
if ( it->startsWith( '#' ) )
|
||||
{
|
||||
it = groupsLines.erase( it );
|
||||
continue;
|
||||
}
|
||||
int indexOfFirstToDrop = it->indexOf( ':' );
|
||||
if ( indexOfFirstToDrop < 1 )
|
||||
{
|
||||
it = groupsLines.erase( it );
|
||||
continue;
|
||||
}
|
||||
it->truncate( indexOfFirstToDrop );
|
||||
++it;
|
||||
}
|
||||
return groupsLines;
|
||||
}
|
||||
|
||||
static void
|
||||
ensureGroupsExistInTarget( const QList< GroupDescription >& wantedGroups, const QStringList& availableGroups )
|
||||
{
|
||||
for ( const auto& group : wantedGroups )
|
||||
{
|
||||
if ( group.isValid() && !availableGroups.contains( group.name() ) )
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group.name() } );
|
||||
#else
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group.name() } );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Calamares::JobResult
|
||||
createUser( const QString& loginName, const QString& fullName, const QString& shell )
|
||||
{
|
||||
@ -166,28 +119,6 @@ CreateUserJob::exec()
|
||||
reuseHome = gs->value( "reuseHome" ).toBool();
|
||||
}
|
||||
|
||||
cDebug() << "[CREATEUSER]: preparing groups";
|
||||
|
||||
m_status = tr( "Preparing groups for user %1" ).arg( m_config->loginName() );
|
||||
emit progress( 0.1 );
|
||||
// loginName(), fullName().isEmpty() ? loginName() : fullName(), doAutoLogin(), groupNames );
|
||||
const auto& defaultGroups = m_config->defaultGroups();
|
||||
QStringList groupsForThisUser = std::accumulate(
|
||||
defaultGroups.begin(),
|
||||
defaultGroups.end(),
|
||||
QStringList(),
|
||||
[]( const QStringList& l, const GroupDescription& g ) { return QStringList( l ) << g.name(); } );
|
||||
|
||||
QStringList availableGroups = groupsInTargetSystem( destDir );
|
||||
ensureGroupsExistInTarget( defaultGroups, availableGroups );
|
||||
|
||||
if ( m_config->doAutoLogin() && !m_config->autologinGroup().isEmpty() )
|
||||
{
|
||||
const QString autologinGroup = m_config->autologinGroup();
|
||||
groupsForThisUser << autologinGroup;
|
||||
ensureGroupsExistInTarget( QList< GroupDescription >() << GroupDescription( autologinGroup ), availableGroups );
|
||||
}
|
||||
|
||||
// If we're looking to reuse the contents of an existing /home.
|
||||
// This GS setting comes from the **partitioning** module.
|
||||
if ( reuseHome )
|
||||
@ -219,7 +150,7 @@ CreateUserJob::exec()
|
||||
|
||||
m_status = tr( "Configuring user %1" ).arg( m_config->loginName() );
|
||||
emit progress( 0.8 );
|
||||
auto usergroupsResult = setUserGroups( m_config->loginName(), groupsForThisUser );
|
||||
auto usergroupsResult = setUserGroups( m_config->loginName(), m_config->groupsForThisUser() );
|
||||
if ( !usergroupsResult )
|
||||
{
|
||||
return usergroupsResult;
|
||||
|
@ -150,9 +150,8 @@ ensureGroupsExistInTarget( const QList< GroupDescription >& wantedGroups,
|
||||
return failureCount == 0;
|
||||
}
|
||||
|
||||
SetupGroupsJob::SetupGroupsJob( const Config* config, const QString& autologinGroup )
|
||||
: m_autologinGroup( autologinGroup )
|
||||
, m_config( config )
|
||||
SetupGroupsJob::SetupGroupsJob( const Config* config )
|
||||
: m_config( config )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,11 @@ class SetupGroupsJob : public Calamares::Job
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SetupGroupsJob( const Config* config, const QString& autologinGroup );
|
||||
SetupGroupsJob( const Config* config );
|
||||
QString prettyName() const override;
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
public:
|
||||
QString m_autologinGroup;
|
||||
const Config* m_config;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user