[users] Add .conf entries for hostname settings

- Set hostname not-at-all, or via one of two mechanisms
 - Write /etc/hosts or not
This commit is contained in:
Adriaan de Groot 2020-02-17 16:40:09 +01:00
parent 61d096c9ec
commit e74831fcb4
2 changed files with 42 additions and 12 deletions

View File

@ -141,8 +141,7 @@ UsersViewStep::onLeave()
j = new SetPasswordJob( "root", m_widget->getRootPassword() );
m_jobs.append( Calamares::job_ptr( j ) );
j = new SetHostNameJob( m_widget->getHostname(),
SetHostNameJob::Action::EtcHostname | SetHostNameJob::Action::EtcHosts );
j = new SetHostNameJob( m_widget->getHostname(), m_actions );
m_jobs.append( Calamares::job_ptr( j ) );
}
@ -206,4 +205,21 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap )
// 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" );
if ( hostnameActionString.isEmpty() )
{
hostnameActionString = QStringLiteral( "EtcFile" );
}
bool ok = false;
auto hostnameAction = hostnameActions().find( hostnameActionString, ok );
if ( !ok )
{
hostnameAction = Action::EtcHostname;
}
Action hostsfileAction = getBool( configurationMap, "writeHostsFile", true ) ? Action::EtcHosts : Action::None;
m_actions = hostsfileAction | hostnameAction;
}

View File

@ -122,3 +122,17 @@ allowWeakPasswordsDefault: false
# - set, non-empty, use that path as shell. No validation is done
# that the shell actually exists or is executable.
# userShell: /bin/bash
# Hostname setting
#
# The user can enter a hostname; this is configured into the system
# in some way; pick one of:
# - *None*, to not set the hostname at all
# - *EtcFile*, to write to `/etc/hostname` directly
# - *Hostnamed*, to use systemd hostnamed(1) over DBus
# The default is *EtcFile*.
setHostname: EtcFile
# Should /etc/hosts be written with a hostname for this machine
# (also adds localhost and some ipv6 standard entries).
writeHostsFile: true