diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index fb69298f6..58e2b76ac 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -20,6 +20,11 @@ #include "Config.h" +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/Logger.h" +#include "utils/Variant.h" + Config::Config( QObject* parent ) : QObject( parent ) { @@ -28,6 +33,26 @@ Config::Config( QObject* parent ) Config::~Config() {} void -Config::setConfigurationMap( const QVariantMap& ) +Config::setUserShell( const QString& shell ) +{ + if ( !shell.isEmpty() && !shell.startsWith( '/' ) ) + { + cWarning() << "User shell" << shell << "is not an absolute path."; + return; + } + // The shell is put into GS because the CreateUser job expects it there + Calamares::JobQueue::instance()->globalStorage()->insert( "userShell", shell ); +} + + +void +Config::setConfigurationMap( const QVariantMap& configurationMap ) { + QString shell( QLatin1String( "/bin/bash" ) ); // as if it's not set at all + if ( configurationMap.contains( "userShell" ) ) + { + shell = CalamaresUtils::getString( configurationMap, "userShell" ); + } + // Now it might be explicitly set to empty, which is ok + setUserShell( shell ); } diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index 95c8c33bd..27416e88d 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -26,12 +26,39 @@ class Config : public QObject { + Q_OBJECT + + Q_PROPERTY( QString userShell READ userShell WRITE setUserShell NOTIFY userShellChanged ) + public: Config( QObject* parent = nullptr ); ~Config(); - // Currently, config does nothing void setConfigurationMap( const QVariantMap& ); + + /** @brief Full path to the user's shell executable + * + * Typically this will be /bin/bash, but it can be set from + * the config file with the *userShell* setting. + */ + QString userShell() const { return m_userShell; } + +public Q_SLOTS: + /** @brief Sets the user's shell if possible + * + * If the path is empty, that's ok: no shell will be explicitly set, + * so the user will get whatever shell is set to default in the target. + * + * The given non-empty @p path must be an absolute path (for use inside + * the target system!); if it is not, the shell is not changed. + */ + void setUserShell( const QString& path ); + +signals: + void userShellChanged( const QString& ); + +private: + QString m_userShell; }; #endif diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 3fc86eb91..e037902ab 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -209,15 +209,6 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_widget->setPasswordCheckboxVisible( getBool( configurationMap, "allowWeakPasswords", false ) ); m_widget->setValidatePasswordDefault( !getBool( configurationMap, "allowWeakPasswordsDefault", false ) ); - QString shell( QLatin1String( "/bin/bash" ) ); // as if it's not set at all - if ( configurationMap.contains( "userShell" ) ) - { - shell = CalamaresUtils::getString( configurationMap, "userShell" ); - } - // Now it might be explicitly set to empty, which is ok - - Calamares::JobQueue::instance()->globalStorage()->insert( "userShell", shell ); - using Action = SetHostNameJob::Action; QString hostnameActionString = CalamaresUtils::getString( configurationMap, "setHostname" );