From 44bf0a5d6df55f8c6aaa908e5c5addc76d43e7db Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 17 Feb 2020 10:57:41 +0100 Subject: [PATCH] [users] Add method for using hostnamed SEE #1140 --- src/modules/users/CMakeLists.txt | 3 ++- src/modules/users/SetHostNameJob.cpp | 29 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index d0e7b6d9d..944433f79 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package( Qt5 COMPONENTS Core REQUIRED ) +find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core DBus Network ) find_package( Crypt REQUIRED ) # Add optional libraries here @@ -36,6 +36,7 @@ calamares_add_plugin( users calamaresui ${CRYPT_LIBRARIES} ${USER_EXTRA_LIB} + Qt5::DBus SHARED_LIB ) diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index 868c8f852..de98854ec 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include +#include SetHostNameJob::SetHostNameJob( const QString& hostname ) : Calamares::Job() @@ -79,6 +82,32 @@ ff02::2 ip6-allrouters .failed() ); } +static void +setSystemdHostname( const QString& hostname ) +{ + QDBusInterface hostnamed( "org.freedesktop.hostname1", + "/org/freedesktop/hostname1", + "org.freedesktop.hostname1", + QDBusConnection::systemBus() ); + + // Static, writes /etc/hostname + { + QDBusReply< uint > r = hostnamed.call( "SetStaticHostname", hostname, false ); + if ( !r.isValid() ) + { + cWarning() << "Could not set hostname through org.freedesktop.hostname1.SetStaticHostname." << r.error(); + } + } + // Dynamic, updates kernel + { + QDBusReply< uint > r = hostnamed.call( "SetHostname", hostname, false ); + if ( !r.isValid() ) + { + cWarning() << "Could not set hostname through org.freedesktop.hostname1.SetHostname." << r.error(); + } + } +} + Calamares::JobResult SetHostNameJob::exec()