[dracutlukscfg] set NO_CONFIG and coding style

This commit is contained in:
Adriaan de Groot 2020-01-24 13:08:25 +01:00
parent 6530c889f0
commit fd058302b8
3 changed files with 43 additions and 32 deletions

View File

@ -6,4 +6,5 @@ calamares_add_plugin( dracutlukscfg
LINK_PRIVATE_LIBRARIES LINK_PRIVATE_LIBRARIES
calamares calamares
SHARED_LIB SHARED_LIB
NO_CONFIG
) )

View File

@ -24,8 +24,8 @@
#include <QTextStream> #include <QTextStream>
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "JobQueue.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -33,30 +33,30 @@
const QLatin1String DracutLuksCfgJob::CONFIG_FILE( "/etc/dracut.conf.d/calamares-luks.conf" ); const QLatin1String DracutLuksCfgJob::CONFIG_FILE( "/etc/dracut.conf.d/calamares-luks.conf" );
// static // static
const char *DracutLuksCfgJob::CONFIG_FILE_HEADER = const char* DracutLuksCfgJob::CONFIG_FILE_HEADER
"# Configuration file automatically written by the Calamares system installer\n" = "# Configuration file automatically written by the Calamares system installer\n"
"# (This file is written once at install time and should be safe to edit.)\n" "# (This file is written once at install time and should be safe to edit.)\n"
"# Enables support for LUKS full disk encryption with single sign on from GRUB.\n" "# Enables support for LUKS full disk encryption with single sign on from GRUB.\n"
"\n"; "\n";
// static // static
const char *DracutLuksCfgJob::CONFIG_FILE_CRYPTTAB_KEYFILE_LINE = const char* DracutLuksCfgJob::CONFIG_FILE_CRYPTTAB_KEYFILE_LINE
"# force installing /etc/crypttab even if hostonly=\"no\", install the keyfile\n" = "# force installing /etc/crypttab even if hostonly=\"no\", install the keyfile\n"
"install_items+=\" /etc/crypttab /crypto_keyfile.bin \"\n"; "install_items+=\" /etc/crypttab /crypto_keyfile.bin \"\n";
// static // static
const char *DracutLuksCfgJob::CONFIG_FILE_CRYPTTAB_LINE = const char* DracutLuksCfgJob::CONFIG_FILE_CRYPTTAB_LINE = "# force installing /etc/crypttab even if hostonly=\"no\"\n"
"# force installing /etc/crypttab even if hostonly=\"no\"\n" "install_items+=\" /etc/crypttab \"\n";
"install_items+=\" /etc/crypttab \"\n";
// static // static
const QLatin1String DracutLuksCfgJob::CONFIG_FILE_SWAPLINE( "# enable automatic resume from swap\nadd_device+=\" /dev/disk/by-uuid/%1 \"\n" ); const QLatin1String DracutLuksCfgJob::CONFIG_FILE_SWAPLINE(
"# enable automatic resume from swap\nadd_device+=\" /dev/disk/by-uuid/%1 \"\n" );
// static // static
QString QString
DracutLuksCfgJob::rootMountPoint() DracutLuksCfgJob::rootMountPoint()
{ {
Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* globalStorage = Calamares::JobQueue::instance()->globalStorage();
return globalStorage->value( QStringLiteral( "rootMountPoint" ) ).toString(); return globalStorage->value( QStringLiteral( "rootMountPoint" ) ).toString();
} }
@ -64,7 +64,7 @@ DracutLuksCfgJob::rootMountPoint()
QVariantList QVariantList
DracutLuksCfgJob::partitions() DracutLuksCfgJob::partitions()
{ {
Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* globalStorage = Calamares::JobQueue::instance()->globalStorage();
return globalStorage->value( QStringLiteral( "partitions" ) ).toList(); return globalStorage->value( QStringLiteral( "partitions" ) ).toList();
} }
@ -73,12 +73,14 @@ bool
DracutLuksCfgJob::isRootEncrypted() DracutLuksCfgJob::isRootEncrypted()
{ {
const QVariantList partitions = DracutLuksCfgJob::partitions(); const QVariantList partitions = DracutLuksCfgJob::partitions();
for ( const QVariant &partition : partitions ) for ( const QVariant& partition : partitions )
{ {
QVariantMap partitionMap = partition.toMap(); QVariantMap partitionMap = partition.toMap();
QString mountPoint = partitionMap.value( QStringLiteral( "mountPoint" ) ).toString(); QString mountPoint = partitionMap.value( QStringLiteral( "mountPoint" ) ).toString();
if ( mountPoint == QStringLiteral( "/" ) ) if ( mountPoint == QStringLiteral( "/" ) )
{
return partitionMap.contains( QStringLiteral( "luksMapperName" ) ); return partitionMap.contains( QStringLiteral( "luksMapperName" ) );
}
} }
return false; return false;
} }
@ -88,12 +90,14 @@ bool
DracutLuksCfgJob::hasUnencryptedSeparateBoot() DracutLuksCfgJob::hasUnencryptedSeparateBoot()
{ {
const QVariantList partitions = DracutLuksCfgJob::partitions(); const QVariantList partitions = DracutLuksCfgJob::partitions();
for ( const QVariant &partition : partitions ) for ( const QVariant& partition : partitions )
{ {
QVariantMap partitionMap = partition.toMap(); QVariantMap partitionMap = partition.toMap();
QString mountPoint = partitionMap.value( QStringLiteral( "mountPoint" ) ).toString(); QString mountPoint = partitionMap.value( QStringLiteral( "mountPoint" ) ).toString();
if ( mountPoint == QStringLiteral( "/boot" ) ) if ( mountPoint == QStringLiteral( "/boot" ) )
{
return !partitionMap.contains( QStringLiteral( "luksMapperName" ) ); return !partitionMap.contains( QStringLiteral( "luksMapperName" ) );
}
} }
return false; return false;
} }
@ -103,12 +107,14 @@ QString
DracutLuksCfgJob::swapOuterUuid() DracutLuksCfgJob::swapOuterUuid()
{ {
const QVariantList partitions = DracutLuksCfgJob::partitions(); const QVariantList partitions = DracutLuksCfgJob::partitions();
for ( const QVariant &partition : partitions ) for ( const QVariant& partition : partitions )
{ {
QVariantMap partitionMap = partition.toMap(); QVariantMap partitionMap = partition.toMap();
QString fsType = partitionMap.value( QStringLiteral( "fs" ) ).toString(); QString fsType = partitionMap.value( QStringLiteral( "fs" ) ).toString();
if ( fsType == QStringLiteral( "linuxswap" ) && partitionMap.contains( QStringLiteral( "luksMapperName" ) ) ) if ( fsType == QStringLiteral( "linuxswap" ) && partitionMap.contains( QStringLiteral( "luksMapperName" ) ) )
{
return partitionMap.value( QStringLiteral( "luksUuid" ) ).toString(); return partitionMap.value( QStringLiteral( "luksUuid" ) ).toString();
}
} }
return QString(); return QString();
} }
@ -119,18 +125,20 @@ DracutLuksCfgJob::DracutLuksCfgJob( QObject* parent )
} }
DracutLuksCfgJob::~DracutLuksCfgJob() DracutLuksCfgJob::~DracutLuksCfgJob() {}
{
}
QString QString
DracutLuksCfgJob::prettyName() const DracutLuksCfgJob::prettyName() const
{ {
if ( isRootEncrypted() ) if ( isRootEncrypted() )
{
return tr( "Write LUKS configuration for Dracut to %1" ).arg( CONFIG_FILE ); return tr( "Write LUKS configuration for Dracut to %1" ).arg( CONFIG_FILE );
}
else else
{
return tr( "Skip writing LUKS configuration for Dracut: \"/\" partition is not encrypted" ); return tr( "Skip writing LUKS configuration for Dracut: \"/\" partition is not encrypted" );
}
} }
@ -143,26 +151,28 @@ DracutLuksCfgJob::exec()
cDebug() << "[DRACUTLUKSCFG]: Writing" << realConfigFilePath; cDebug() << "[DRACUTLUKSCFG]: Writing" << realConfigFilePath;
QDir( QStringLiteral( "/" ) ).mkpath( QFileInfo( realConfigFilePath ).absolutePath() ); QDir( QStringLiteral( "/" ) ).mkpath( QFileInfo( realConfigFilePath ).absolutePath() );
QFile configFile( realConfigFilePath ); QFile configFile( realConfigFilePath );
if ( ! configFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) if ( !configFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
{ {
cDebug() << "[DRACUTLUKSCFG]: Failed to open" << realConfigFilePath; cDebug() << "[DRACUTLUKSCFG]: Failed to open" << realConfigFilePath;
return Calamares::JobResult::error( tr( "Failed to open %1" ).arg( realConfigFilePath ) ); return Calamares::JobResult::error( tr( "Failed to open %1" ).arg( realConfigFilePath ) );
} }
QTextStream outStream( &configFile ); QTextStream outStream( &configFile );
outStream << CONFIG_FILE_HEADER outStream << CONFIG_FILE_HEADER
<< ( hasUnencryptedSeparateBoot() ? CONFIG_FILE_CRYPTTAB_LINE << ( hasUnencryptedSeparateBoot() ? CONFIG_FILE_CRYPTTAB_LINE : CONFIG_FILE_CRYPTTAB_KEYFILE_LINE );
: CONFIG_FILE_CRYPTTAB_KEYFILE_LINE );
const QString swapOuterUuid = DracutLuksCfgJob::swapOuterUuid(); const QString swapOuterUuid = DracutLuksCfgJob::swapOuterUuid();
if ( ! swapOuterUuid.isEmpty() ) if ( !swapOuterUuid.isEmpty() )
{ {
cDebug() << "[DRACUTLUKSCFG]: Swap outer UUID" << swapOuterUuid; cDebug() << "[DRACUTLUKSCFG]: Swap outer UUID" << swapOuterUuid;
outStream << QString(CONFIG_FILE_SWAPLINE).arg( swapOuterUuid ).toLatin1(); outStream << QString( CONFIG_FILE_SWAPLINE ).arg( swapOuterUuid ).toLatin1();
} }
cDebug() << "[DRACUTLUKSCFG]: Wrote config to" << realConfigFilePath; cDebug() << "[DRACUTLUKSCFG]: Wrote config to" << realConfigFilePath;
} else }
else
{
cDebug() << "[DRACUTLUKSCFG]: / not encrypted, skipping"; cDebug() << "[DRACUTLUKSCFG]: / not encrypted, skipping";
}
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
} }
CALAMARES_PLUGIN_FACTORY_DEFINITION( DracutLuksCfgJobFactory, registerPlugin<DracutLuksCfgJob>(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( DracutLuksCfgJobFactory, registerPlugin< DracutLuksCfgJob >(); )

View File

@ -43,9 +43,9 @@ public:
private: private:
static const QLatin1String CONFIG_FILE; static const QLatin1String CONFIG_FILE;
static const char *CONFIG_FILE_HEADER; static const char* CONFIG_FILE_HEADER;
static const char *CONFIG_FILE_CRYPTTAB_KEYFILE_LINE; static const char* CONFIG_FILE_CRYPTTAB_KEYFILE_LINE;
static const char *CONFIG_FILE_CRYPTTAB_LINE; static const char* CONFIG_FILE_CRYPTTAB_LINE;
static const QLatin1String CONFIG_FILE_SWAPLINE; static const QLatin1String CONFIG_FILE_SWAPLINE;
static QString rootMountPoint(); static QString rootMountPoint();
@ -57,4 +57,4 @@ private:
CALAMARES_PLUGIN_FACTORY_DECLARATION( DracutLuksCfgJobFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( DracutLuksCfgJobFactory )
#endif // DRACUTLUKSCFGJOB_H #endif // DRACUTLUKSCFGJOB_H