mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 10:55:46 -05:00
[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:
parent
145855a56f
commit
c67ac999de
3 changed files with 40 additions and 18 deletions
|
@ -104,13 +104,21 @@ MachineIdJob::exec()
|
||||||
}
|
}
|
||||||
if ( m_dbus )
|
if ( m_dbus )
|
||||||
{
|
{
|
||||||
auto r = MachineId::createDBusMachineId( m_dbus_symlink ? MachineId::DBusGeneration::SymlinkFromSystemD
|
if ( m_dbus_symlink && QFile::exists( root + target_systemd_machineid_file ) )
|
||||||
: MachineId::DBusGeneration::New,
|
|
||||||
root,
|
|
||||||
target_dbus_machineid_file );
|
|
||||||
if ( !r )
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,10 +139,9 @@ createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, cons
|
||||||
return createNewEntropy( poolSize, rootMountPoint, fileName );
|
return createNewEntropy( poolSize, rootMountPoint, fileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobResult
|
static Calamares::JobResult
|
||||||
createSystemdMachineId( const QString& rootMountPoint, const QString& fileName )
|
runCmd( const QStringList& cmd )
|
||||||
{
|
{
|
||||||
auto cmd = QStringList { QStringLiteral( "systemd-machine-id-setup" ) };
|
|
||||||
auto r = CalamaresUtils::System::instance()->targetEnvCommand( cmd );
|
auto r = CalamaresUtils::System::instance()->targetEnvCommand( cmd );
|
||||||
if ( r.getExitCode() )
|
if ( r.getExitCode() )
|
||||||
{
|
{
|
||||||
|
@ -153,9 +152,26 @@ createSystemdMachineId( const QString& rootMountPoint, const QString& fileName )
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobResult
|
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
|
} // namespace MachineId
|
||||||
|
|
|
@ -67,14 +67,12 @@ createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, cons
|
||||||
* Creating UUIDs for DBUS and SystemD.
|
* Creating UUIDs for DBUS and SystemD.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// @brief How to create the DBus machine-id (bool-like)
|
/// @brief Create a new DBus UUID file
|
||||||
enum class DBusGeneration
|
Calamares::JobResult createDBusMachineId( const QString& rootMountPoint, const QString& fileName );
|
||||||
{
|
|
||||||
New,
|
|
||||||
SymlinkFromSystemD
|
|
||||||
};
|
|
||||||
|
|
||||||
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 );
|
Calamares::JobResult createSystemdMachineId( const QString& rootMountPoint, const QString& fileName );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue