[luksopenswaphookcfg] Read GS for finding LUKS config
This commit is contained in:
parent
45d6eb36fb
commit
2c20a00cc3
@ -59,9 +59,8 @@ struct LOSHInfo
|
|||||||
|
|
||||||
/** @brief Creates a struct from information already set in GS
|
/** @brief Creates a struct from information already set in GS
|
||||||
*
|
*
|
||||||
* TODO: implement this in LOSHJob.cpp
|
|
||||||
*/
|
*/
|
||||||
static LOSHInfo fromGlobalStorage() { return LOSHInfo {}; }
|
static LOSHInfo fromGlobalStorage();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Permissions.h"
|
#include "utils/Permissions.h"
|
||||||
#include "utils/PluginFactory.h"
|
#include "utils/PluginFactory.h"
|
||||||
|
#include "utils/String.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@ -118,4 +119,62 @@ LOSHJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
configurationMap, QStringLiteral( "configFilePath" ), QStringLiteral( "/etc/openswap.conf" ) );
|
configurationMap, QStringLiteral( "configFilePath" ), QStringLiteral( "/etc/openswap.conf" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATICTEST void
|
||||||
|
globalStoragePartitionInfo( Calamares::GlobalStorage* gs, LOSHInfo& info )
|
||||||
|
{
|
||||||
|
if ( !gs )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QVariantList l = gs->value( "partitions" ).toList();
|
||||||
|
if ( l.isEmpty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( const auto& pv : l )
|
||||||
|
{
|
||||||
|
const QVariantMap partition = pv.toMap();
|
||||||
|
if ( !partition.isEmpty() )
|
||||||
|
{
|
||||||
|
QString mountPoint = partition.value( "mountPoint" ).toString();
|
||||||
|
QString fileSystem = partition.value( "fs" ).toString();
|
||||||
|
QString luksMapperName = partition.value( "luksMapperName" ).toString();
|
||||||
|
// if partition["fs"] == "linuxswap" and "luksMapperName" in partition:
|
||||||
|
if ( fileSystem == QStringLiteral( "linuxswap" ) && !luksMapperName.isEmpty() )
|
||||||
|
{
|
||||||
|
info.swap_outer_uuid = partition.value( "luksUuid" ).toString();
|
||||||
|
info.swap_mapper_name = luksMapperName;
|
||||||
|
}
|
||||||
|
else if ( mountPoint == QStringLiteral( "/" ) && !luksMapperName.isEmpty() )
|
||||||
|
{
|
||||||
|
|
||||||
|
info.mountable_keyfile_device = QStringLiteral( "/dev/mapper/" ) + luksMapperName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !info.mountable_keyfile_device.isEmpty() && !info.swap_outer_uuid.isEmpty() )
|
||||||
|
{
|
||||||
|
info.swap_device_path = QStringLiteral( "/dev/disk/by-uuid/" ) + info.swap_outer_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString btrfsRootSubvolume = gs->value( "btrfsRootSubvolume" ).toString();
|
||||||
|
if ( !btrfsRootSubvolume.isEmpty() )
|
||||||
|
{
|
||||||
|
CalamaresUtils::removeLeading( btrfsRootSubvolume, '/' );
|
||||||
|
info.keyfile_device_mount_options
|
||||||
|
= QStringLiteral( "keyfile_device_mount_options=--options=subvol=" ) + btrfsRootSubvolume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOSHInfo
|
||||||
|
LOSHInfo::fromGlobalStorage()
|
||||||
|
{
|
||||||
|
LOSHInfo i {};
|
||||||
|
globalStoragePartitionInfo(
|
||||||
|
Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr, i );
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( LOSHJobFactory, registerPlugin< LOSHJob >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( LOSHJobFactory, registerPlugin< LOSHJob >(); )
|
||||||
|
@ -194,18 +194,49 @@ LOSHTests::testConfigWriting()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LOSHTests::testJob()
|
void
|
||||||
|
LOSHTests::testJob()
|
||||||
{
|
{
|
||||||
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) );
|
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) );
|
||||||
QVERIFY( tempRoot.isValid() );
|
QVERIFY( tempRoot.isValid() );
|
||||||
auto* ss = file_setup( tempRoot );
|
auto* ss = file_setup( tempRoot );
|
||||||
QVERIFY( ss );
|
QVERIFY( ss );
|
||||||
|
Calamares::GlobalStorage* gs
|
||||||
|
= Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr;
|
||||||
|
QVERIFY( gs );
|
||||||
|
|
||||||
|
{
|
||||||
|
QDir d( tempRoot.path() );
|
||||||
|
d.mkdir( "etc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
QVERIFY( !LOSHInfo::fromGlobalStorage().isValid() );
|
||||||
|
QVariantList outerPartition;
|
||||||
|
QVariantMap innerPartition;
|
||||||
|
innerPartition.insert( "mountPoint", "/" );
|
||||||
|
innerPartition.insert( "fs", "ext4" );
|
||||||
|
innerPartition.insert( "luksMapperName", "root" );
|
||||||
|
innerPartition.insert( "luksUUID", "0000" );
|
||||||
|
outerPartition.append( innerPartition );
|
||||||
|
innerPartition.remove( "mountPoint" );
|
||||||
|
innerPartition.insert( "fs", "linuxswap" );
|
||||||
|
innerPartition.insert( "luksMapperName", "swap" );
|
||||||
|
innerPartition.insert( "luksUuid", "0001" );
|
||||||
|
outerPartition.append( innerPartition );
|
||||||
|
gs->insert( "partitions", outerPartition );
|
||||||
|
QVERIFY( LOSHInfo::fromGlobalStorage().isValid() );
|
||||||
|
|
||||||
LOSHJob j;
|
LOSHJob j;
|
||||||
j.setConfigurationMap( QVariantMap() );
|
j.setConfigurationMap( QVariantMap() );
|
||||||
auto jobresult = j.exec();
|
auto jobresult = j.exec();
|
||||||
QVERIFY( jobresult );
|
QVERIFY( jobresult );
|
||||||
QVERIFY( QFile::exists( tempRoot.filePath( "etc/openswap.conf" ) ) );
|
|
||||||
|
{
|
||||||
|
QFile f( tempRoot.filePath( "etc/openswap.conf" ) );
|
||||||
|
QVERIFY( f.exists() );
|
||||||
|
QVERIFY( f.open( QIODevice::ReadOnly ) );
|
||||||
|
cDebug() << f.readAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user