From e74831fcb460e023f7bcf48f16c1ac6c88a1e63e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 17 Feb 2020 16:40:09 +0100 Subject: [PATCH] [users] Add .conf entries for hostname settings - Set hostname not-at-all, or via one of two mechanisms - Write /etc/hosts or not --- src/modules/users/UsersViewStep.cpp | 20 +++++++++++++++-- src/modules/users/users.conf | 34 ++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 695ba109f..759fdb3e1 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -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; } diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index 00747195c..1c928fd3a 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -28,13 +28,13 @@ defaultGroups: # Disable when your Distribution does not require such a group. autologinGroup: autologin # You can control the initial state for the 'autologin checkbox' here. -# Possible values are: -# - true to check or +# Possible values are: +# - true to check or # - false to uncheck # These set the **initial** state of the checkbox. doAutologin: true -# When *sudoersGroup* is set to a non-empty string, Calamares creates a +# When *sudoersGroup* is set to a non-empty string, Calamares creates a # sudoers file for the user. This file is located at: # `/etc/sudoers.d/10-installer` # Remember to add the (value of) *sudoersGroup* to *defaultGroups*. @@ -48,8 +48,8 @@ sudoersGroup: wheel # Setting this to false , causes the root account to be disabled. setRootPassword: true # You can control the initial state for the 'reuse password for root' -# checkbox here. Possible values are: -# - true to check or +# checkbox here. Possible values are: +# - true to check or # - false to uncheck # # When checked, the user password is used for the root account too. @@ -96,18 +96,18 @@ passwordRequirements: libpwquality: - minlen=0 - minclass=0 - + # You can control the visibility of the 'strong passwords' checkbox here. -# Possible values are: -# - true to show or +# Possible values are: +# - true to show or # - false to hide (default) # the checkbox. This checkbox allows the user to choose to disable # password-strength-checks. By default the box is **hidden**, so # that you have to pick a password that satisfies the checks. allowWeakPasswords: false # You can control the initial state for the 'strong passwords' checkbox here. -# Possible values are: -# - true to uncheck or +# Possible values are: +# - true to uncheck or # - false to check (default) # the checkbox by default. Since the box is labeled to enforce strong # passwords, in order to **allow** weak ones by default, the box needs @@ -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