[users] Make SetHostName job actions configurable

This commit is contained in:
Adriaan de Groot 2020-02-17 15:24:44 +01:00
parent 44bf0a5d6d
commit ef4bb5e13b
3 changed files with 35 additions and 9 deletions

View File

@ -31,9 +31,10 @@
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
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();

View File

@ -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

View File

@ -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() );