2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2019-07-04 20:21:13 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
2022-01-01 17:05:00 +01:00
|
|
|
* SPDX-FileCopyrightText: 2022 Evan James <dalto@fastmail.com>
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2019-07-04 20:21:13 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2019-07-04 20:21:13 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "InitcpioJob.h"
|
|
|
|
|
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/UMask.h"
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
2019-07-05 13:17:55 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
|
2019-07-04 20:21:13 +02:00
|
|
|
InitcpioJob::InitcpioJob( QObject* parent )
|
|
|
|
: Calamares::CppJob( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InitcpioJob::~InitcpioJob() {}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
InitcpioJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Creating initramfs with mkinitcpio." );
|
|
|
|
}
|
|
|
|
|
2022-01-01 19:14:42 +01:00
|
|
|
/** @brief Sets secure permissions on each initramfs
|
2022-01-01 17:05:00 +01:00
|
|
|
*
|
|
|
|
* Iterates over each initramfs contained directly in the directory @p d.
|
|
|
|
* For each initramfs found, the permissions are set to owner read/write only.
|
|
|
|
*
|
|
|
|
*/
|
2019-07-05 13:28:32 +02:00
|
|
|
void
|
2019-07-05 13:17:55 +02:00
|
|
|
fixPermissions( const QDir& d )
|
|
|
|
{
|
2022-01-01 17:05:00 +01:00
|
|
|
const auto initramList = d.entryInfoList( { "initramfs*" }, QDir::Files );
|
|
|
|
for ( const auto& fi : initramList )
|
2019-07-05 13:17:55 +02:00
|
|
|
{
|
|
|
|
QFile f( fi.absoluteFilePath() );
|
|
|
|
if ( f.exists() )
|
|
|
|
{
|
2022-01-01 17:05:00 +01:00
|
|
|
cDebug() << "initcpio setting permissions for" << f.fileName();
|
2019-07-05 13:17:55 +02:00
|
|
|
f.setPermissions( QFileDevice::ReadOwner | QFileDevice::WriteOwner );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-04 20:21:13 +02:00
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
InitcpioJob::exec()
|
|
|
|
{
|
|
|
|
CalamaresUtils::UMask m( CalamaresUtils::UMask::Safe );
|
|
|
|
|
2019-07-06 00:04:16 +02:00
|
|
|
if ( m_unsafe )
|
2019-07-05 13:17:55 +02:00
|
|
|
{
|
2019-07-06 00:04:16 +02:00
|
|
|
cDebug() << "Skipping mitigations for unsafe initramfs permissions.";
|
2019-07-05 13:17:55 +02:00
|
|
|
}
|
2019-07-06 00:04:16 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QDir d( CalamaresUtils::System::instance()->targetPath( "/boot" ) );
|
|
|
|
if ( d.exists() )
|
|
|
|
{
|
|
|
|
fixPermissions( d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 17:05:00 +01:00
|
|
|
// If the kernel option isn't set to a specific kernel, run mkinitcpio on all kernels
|
2022-01-01 17:48:48 +01:00
|
|
|
QStringList command = { "mkinitcpio" };
|
2022-01-01 17:05:00 +01:00
|
|
|
if ( m_kernel.isEmpty() || m_kernel == "all" )
|
|
|
|
{
|
|
|
|
command.append( "-P" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command.append( { "-p", m_kernel } );
|
|
|
|
}
|
|
|
|
|
2019-07-04 20:21:13 +02:00
|
|
|
cDebug() << "Updating initramfs with kernel" << m_kernel;
|
2022-01-01 17:05:00 +01:00
|
|
|
auto r = CalamaresUtils::System::instance()->targetEnvCommand( command, QString(), QString() /* no timeout , 0 */ );
|
2019-08-01 22:59:06 +02:00
|
|
|
return r.explainProcess( "mkinitcpio", std::chrono::seconds( 10 ) /* fake timeout */ );
|
2019-07-04 20:21:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InitcpioJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
m_kernel = CalamaresUtils::getString( configurationMap, "kernel" );
|
2019-07-06 00:04:16 +02:00
|
|
|
|
|
|
|
m_unsafe = CalamaresUtils::getBool( configurationMap, "be_unsafe", false );
|
2019-07-04 20:21:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( InitcpioJobFactory, registerPlugin< InitcpioJob >(); )
|