diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index de98854ec..7c81329a7 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -31,9 +31,10 @@ #include #include -SetHostNameJob::SetHostNameJob( const QString& hostname ) +SetHostNameJob::SetHostNameJob( const QString& hostname, Actions a ) : Calamares::Job() , m_hostname( hostname ) + , m_actions( a ) { } @@ -127,16 +128,28 @@ SetHostNameJob::exec() return Calamares::JobResult::error( tr( "Internal Error" ) ); } - if ( !setFileHostname( m_hostname ) ) + if ( m_actions & Action::EtcHostname ) { - cError() << "Can't write to hostname file"; - return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + if ( !setFileHostname( m_hostname ) ) + { + cError() << "Can't write to hostname file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } } - if ( !writeFileEtcHosts( m_hostname ) ) + if ( m_actions & Action::EtcHosts ) { - cError() << "Can't write to hosts file"; - return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + if ( !writeFileEtcHosts( m_hostname ) ) + { + cError() << "Can't write to hosts file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } + } + + if ( m_actions & Action::SystemdHostname ) + { + // Does its own logging + setSystemdHostname( m_hostname ); } return Calamares::JobResult::ok(); diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h index ca2481dd4..bc1d1d8ac 100644 --- a/src/modules/users/SetHostNameJob.h +++ b/src/modules/users/SetHostNameJob.h @@ -26,7 +26,17 @@ class SetHostNameJob : public Calamares::Job { Q_OBJECT public: - SetHostNameJob( const QString& hostname ); + enum Action + { + None = 0x0, + EtcHostname = 0x1, // Write to /etc/hostname directly + SystemdHostname = 0x2, // Set via hostnamed(1) + EtcHosts = 0x4 // Write /etc/hosts (127.0.1.1 is this host) + }; + Q_DECLARE_FLAGS( Actions, Action ) + + + SetHostNameJob( const QString& hostname, Actions a ); QString prettyName() const override; QString prettyDescription() const override; QString prettyStatusMessage() const override; @@ -34,7 +44,9 @@ public: private: const QString m_hostname; + const Actions m_actions; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( SetHostNameJob::Actions ) #endif // SETHOSTNAMEJOB_CPP_H diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index c5c6ef8d4..f4e88b629 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -209,7 +209,8 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) list.append( Calamares::job_ptr( j ) ); } - j = new SetHostNameJob( ui->textBoxHostname->text() ); + j = new SetHostNameJob( ui->textBoxHostname->text(), + SetHostNameJob::Action::EtcHostname | SetHostNameJob::Action::EtcHosts ); list.append( Calamares::job_ptr( j ) ); gs->insert( "hostname", ui->textBoxHostname->text() );