[users] Add method for using hostnamed

SEE #1140
This commit is contained in:
Adriaan de Groot 2020-02-17 10:57:41 +01:00
parent 9a7465bfd5
commit 44bf0a5d6d
2 changed files with 31 additions and 1 deletions

View File

@ -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
)

View File

@ -27,6 +27,9 @@
#include <QDir>
#include <QFile>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
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()