[users] Show progress during the module

- add a status member so the different steps can show progress
  as the user is created and configured. The progress values
  are hard-coded guesses as to how much work is done for each step.
- while here, reduce the scope of the global storage variable
This commit is contained in:
Adriaan de Groot 2020-10-14 00:55:00 +02:00
parent ef70b2c32e
commit 58f10739e1
2 changed files with 25 additions and 6 deletions

View File

@ -47,7 +47,7 @@ CreateUserJob::prettyDescription() const
QString QString
CreateUserJob::prettyStatusMessage() const CreateUserJob::prettyStatusMessage() const
{ {
return tr( "Creating user %1." ).arg( m_config->loginName() ); return m_status.isEmpty() ? tr( "Creating user %1." ).arg( m_config->loginName() ) : m_status;
} }
STATICTEST QStringList STATICTEST QStringList
@ -157,14 +157,22 @@ setUserGroups( const QString& loginName, const QStringList& groups )
Calamares::JobResult Calamares::JobResult
CreateUserJob::exec() CreateUserJob::exec()
{ {
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); QDir destDir;
QDir destDir( gs->value( "rootMountPoint" ).toString() ); bool reuseHome = false;
if ( gs->contains( "sudoersGroup" ) && !gs->value( "sudoersGroup" ).toString().isEmpty() )
{ {
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
destDir = QDir( gs->value( "rootMountPoint" ).toString() );
reuseHome = gs->value( "reuseHome" ).toBool();
}
if ( !m_config->sudoersGroup().isEmpty() )
{
m_status = tr( "Preparing sudo for user %1" ).arg( m_config->loginName() );
emit progress( 0.05 );
cDebug() << "[CREATEUSER]: preparing sudoers"; cDebug() << "[CREATEUSER]: preparing sudoers";
QString sudoersLine = QString( "%%1 ALL=(ALL) ALL\n" ).arg( gs->value( "sudoersGroup" ).toString() ); QString sudoersLine = QString( "%%1 ALL=(ALL) ALL\n" ).arg( m_config->sudoersGroup() );
auto fileResult auto fileResult
= CalamaresUtils::System::instance()->createTargetFile( QStringLiteral( "/etc/sudoers.d/10-installer" ), = CalamaresUtils::System::instance()->createTargetFile( QStringLiteral( "/etc/sudoers.d/10-installer" ),
sudoersLine.toUtf8().constData(), sudoersLine.toUtf8().constData(),
@ -185,6 +193,8 @@ CreateUserJob::exec()
cDebug() << "[CREATEUSER]: preparing groups"; 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 ); // loginName(), fullName().isEmpty() ? loginName() : fullName(), doAutoLogin(), groupNames );
const auto& defaultGroups = m_config->defaultGroups(); const auto& defaultGroups = m_config->defaultGroups();
QStringList groupsForThisUser = std::accumulate( QStringList groupsForThisUser = std::accumulate(
@ -205,8 +215,10 @@ CreateUserJob::exec()
// If we're looking to reuse the contents of an existing /home. // If we're looking to reuse the contents of an existing /home.
// This GS setting comes from the **partitioning** module. // This GS setting comes from the **partitioning** module.
if ( gs->value( "reuseHome" ).toBool() ) if ( reuseHome )
{ {
m_status = tr( "Preserving home directory" );
emit progress( 0.2 );
QString shellFriendlyHome = "/home/" + m_config->loginName(); QString shellFriendlyHome = "/home/" + m_config->loginName();
QDir existingHome( destDir.absolutePath() + shellFriendlyHome ); QDir existingHome( destDir.absolutePath() + shellFriendlyHome );
if ( existingHome.exists() ) if ( existingHome.exists() )
@ -222,18 +234,24 @@ CreateUserJob::exec()
cDebug() << "[CREATEUSER]: creating user"; cDebug() << "[CREATEUSER]: creating user";
m_status = tr( "Creating user %1" ).arg( m_config->loginName() );
emit progress( 0.5 );
auto useraddResult = createUser( m_config->loginName(), m_config->fullName(), m_config->userShell() ); auto useraddResult = createUser( m_config->loginName(), m_config->fullName(), m_config->userShell() );
if ( !useraddResult ) if ( !useraddResult )
{ {
return useraddResult; return useraddResult;
} }
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(), groupsForThisUser );
if ( !usergroupsResult ) if ( !usergroupsResult )
{ {
return usergroupsResult; return usergroupsResult;
} }
m_status = tr( "Setting file permissions" );
emit progress( 0.9 );
QString userGroup = QString( "%1:%2" ).arg( m_config->loginName() ).arg( m_config->loginName() ); QString userGroup = QString( "%1:%2" ).arg( m_config->loginName() ).arg( m_config->loginName() );
QString homeDir = QString( "/home/%1" ).arg( m_config->loginName() ); QString homeDir = QString( "/home/%1" ).arg( m_config->loginName() );
auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } ); auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } );

View File

@ -26,6 +26,7 @@ public:
private: private:
const Config* m_config; const Config* m_config;
QString m_status;
}; };
#endif /* CREATEUSERJOB_H */ #endif /* CREATEUSERJOB_H */