[dracutlukscfg] set NO_CONFIG and coding style

main
Adriaan de Groot 5 years ago
parent 6530c889f0
commit fd058302b8

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

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

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

Loading…
Cancel
Save