[machineid] Implement DBUS and systemd machine-ids

- refactor running the command into a helper function,
   to deal with the regular if-command-failed-then-complain pattern.
 - mark parameters as unused.
 - move distinction about kind of DBus file up into the MachineIdJob
   and remove the enum that marked it.
This commit is contained in:
Adriaan de Groot 2019-10-04 14:57:05 +02:00
parent 145855a56f
commit c67ac999de
3 changed files with 40 additions and 18 deletions

View File

@ -104,13 +104,21 @@ MachineIdJob::exec()
}
if ( m_dbus )
{
auto r = MachineId::createDBusMachineId( m_dbus_symlink ? MachineId::DBusGeneration::SymlinkFromSystemD
: MachineId::DBusGeneration::New,
root,
target_dbus_machineid_file );
if ( !r )
if ( m_dbus_symlink && QFile::exists( root + target_systemd_machineid_file ) )
{
return r;
auto r = MachineId::createDBusLink( root, target_dbus_machineid_file, target_systemd_machineid_file );
if ( !r )
{
return r;
}
}
else
{
auto r = MachineId::createDBusMachineId( root, target_dbus_machineid_file );
if ( !r )
{
return r;
}
}
}

View File

@ -139,10 +139,9 @@ createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, cons
return createNewEntropy( poolSize, rootMountPoint, fileName );
}
Calamares::JobResult
createSystemdMachineId( const QString& rootMountPoint, const QString& fileName )
static Calamares::JobResult
runCmd( const QStringList& cmd )
{
auto cmd = QStringList { QStringLiteral( "systemd-machine-id-setup" ) };
auto r = CalamaresUtils::System::instance()->targetEnvCommand( cmd );
if ( r.getExitCode() )
{
@ -153,9 +152,26 @@ createSystemdMachineId( const QString& rootMountPoint, const QString& fileName )
}
Calamares::JobResult
createDBusMachineId( DBusGeneration kind, const QString& rootMountPoint, const QString& fileName )
createSystemdMachineId( const QString& rootMountPoint, const QString& fileName )
{
return Calamares::JobResult::internalError( QObject::tr( "Internal Error" ), QObject::tr( "Not implemented" ), 0 );
Q_UNUSED( rootMountPoint )
Q_UNUSED( fileName )
return runCmd( QStringList { QStringLiteral( "systemd-machine-id-setup" ) } );
}
Calamares::JobResult
createDBusMachineId( const QString& rootMountPoint, const QString& fileName )
{
Q_UNUSED( rootMountPoint )
Q_UNUSED( fileName )
return runCmd( QStringList { QStringLiteral( "dbus-uuidgen" ), QStringLiteral( "--ensure" ) } );
}
Calamares::JobResult
createDBusLink( const QString& rootMountPoint, const QString& fileName, const QString& systemdFileName )
{
Q_UNUSED( rootMountPoint );
return runCmd( QStringList { QStringLiteral( "ln" ), QStringLiteral( "-s" ), systemdFileName, fileName } );
}
} // namespace MachineId

View File

@ -67,14 +67,12 @@ createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, cons
* Creating UUIDs for DBUS and SystemD.
*/
/// @brief How to create the DBus machine-id (bool-like)
enum class DBusGeneration
{
New,
SymlinkFromSystemD
};
/// @brief Create a new DBus UUID file
Calamares::JobResult createDBusMachineId( const QString& rootMountPoint, const QString& fileName );
Calamares::JobResult createDBusMachineId( DBusGeneration kind, const QString& rootMountPoint, const QString& fileName );
/// @brief Symlink DBus UUID file to the one from systemd (which must exist already)
Calamares::JobResult
createDBusLink( const QString& rootMountPoint, const QString& fileName, const QString& systemdFileName );
Calamares::JobResult createSystemdMachineId( const QString& rootMountPoint, const QString& fileName );