diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 371d98932..55377abba 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -738,7 +738,7 @@ STATICTEST HostNameActions getHostNameActions( const QVariantMap& configurationMap ) { HostNameAction setHostName = HostNameAction::EtcHostname; - QString hostnameActionString = CalamaresUtils::getString( configurationMap, "setHostname" ); + QString hostnameActionString = CalamaresUtils::getString( configurationMap, "location" ); if ( !hostnameActionString.isEmpty() ) { bool ok = false; @@ -826,6 +826,17 @@ either( T ( *f )( const QVariantMap&, const QString&, U ), } } +static void +copyLegacy( const QVariantMap& source, const QString& sourceKey, QVariantMap& target, const QString& targetKey ) +{ + if ( source.contains( sourceKey ) ) + { + const QVariant legacyValue = source.value( sourceKey ); + cWarning() << "Legacy *users* key" << sourceKey << "overrides hostname-settings."; + target.insert( targetKey, legacyValue ); + } +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -844,7 +855,15 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) ? SudoStyle::UserAndGroup : SudoStyle::UserOnly; - m_hostNameActions = getHostNameActions( configurationMap ); + // Handle *hostname* key and subkeys and legacy settings + { + bool ok = false; // Ignored + QVariantMap hostnameSettings = CalamaresUtils::getSubMap( configurationMap, "hostname", ok ); + + copyLegacy( configurationMap, "setHostname", hostnameSettings, "location" ); + copyLegacy( configurationMap, "writeHostsFile", hostnameSettings, "writeHostsFile" ); + m_hostNameActions = getHostNameActions( hostnameSettings ); + } setConfigurationDefaultGroups( configurationMap, m_defaultGroups ); diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index acb0c9d6d..6bb701228 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -240,7 +240,7 @@ UserTests::testHostActions() QVariantMap m; if ( set ) { - m.insert( "setHostname", string ); + m.insert( "location", string ); } QCOMPARE( getHostNameActions( m ), HostNameActions( result ) | HostNameAction::WriteEtcHosts ); // write bits default to true diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index 9f932c0a1..397b888cc 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -149,19 +149,33 @@ allowWeakPasswordsDefault: false # that the shell actually exists or is executable. userShell: /bin/bash -# Hostname setting +# Hostname settings # # The user can enter a hostname; this is configured into the system -# in some way; pick one of: +# in some way. There are settings for how a hostname is guessed (as +# a default / suggestion) and where (or how) the hostname is set in +# the target system. +# +# Key *hostname* has the following sub-keys (just one): +# +# - *location* How the hostname is set in the target system: # - *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*. +# The default is *EtcFile*. Setting this to *None* will +# hide the hostname field. +# - *writeHostsFile* Should /etc/hosts be written with a hostname for +# this machine (also adds localhost and some ipv6 standard entries). +# Defaults to *true*. +hostname: + location: EtcFile + writeHostsFile: true + +# This is a legacy setting for hostname.location; if it is set +# at all, and there is no setting for hostname.location, it is used. setHostname: EtcFile -# Should /etc/hosts be written with a hostname for this machine -# (also adds localhost and some ipv6 standard entries). -# Defaults to *true*. +# This is a legacy setting for hostname.writeHostsFile writeHostsFile: true presets: