[users] Make SetHostName job actions configurable
This commit is contained in:
parent
44bf0a5d6d
commit
ef4bb5e13b
@ -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,17 +128,29 @@ SetHostNameJob::exec()
|
||||
return Calamares::JobResult::error( tr( "Internal Error" ) );
|
||||
}
|
||||
|
||||
if ( m_actions & Action::EtcHostname )
|
||||
{
|
||||
if ( !setFileHostname( m_hostname ) )
|
||||
{
|
||||
cError() << "Can't write to hostname file";
|
||||
return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_actions & Action::EtcHosts )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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() );
|
||||
|
Loading…
Reference in New Issue
Block a user