2014-07-22 17:32:26 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2015-04-10 17:46:42 +02:00
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
2014-07-22 17:32:26 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "jobs/FillGlobalStorageJob.h"
|
2014-07-22 17:32:26 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
|
|
|
#include "core/PartitionInfo.h"
|
|
|
|
#include "core/PartitionIterator.h"
|
2015-09-18 15:41:07 +02:00
|
|
|
#include "core/KPMHelpers.h"
|
2015-04-10 17:46:42 +02:00
|
|
|
#include "Branding.h"
|
2015-06-04 18:57:50 +02:00
|
|
|
#include "utils/Logger.h"
|
2014-07-22 17:32:26 +02:00
|
|
|
|
|
|
|
// CalaPM
|
2015-07-02 13:49:21 +02:00
|
|
|
#include <kpmcore/core/device.h>
|
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
#include <kpmcore/fs/filesystem.h>
|
2016-04-22 16:50:46 +02:00
|
|
|
#include <kpmcore/fs/luks.h>
|
2014-07-22 17:32:26 +02:00
|
|
|
|
2014-07-28 14:58:06 +02:00
|
|
|
// Qt
|
2014-07-23 18:16:55 +02:00
|
|
|
#include <QDebug>
|
2014-07-28 14:58:06 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2016-05-05 13:29:08 +02:00
|
|
|
#include <QProcess>
|
2014-07-28 14:58:06 +02:00
|
|
|
|
|
|
|
typedef QHash<QString, QString> UuidForPartitionHash;
|
|
|
|
|
|
|
|
static const char* UUID_DIR = "/dev/disk/by-uuid";
|
|
|
|
|
|
|
|
static UuidForPartitionHash
|
2015-06-04 19:34:30 +02:00
|
|
|
findPartitionUuids( QList < Device* > devices )
|
2014-07-28 14:58:06 +02:00
|
|
|
{
|
2015-06-04 18:57:50 +02:00
|
|
|
cDebug() << "Gathering UUIDs for partitions that exist now.";
|
2014-07-28 14:58:06 +02:00
|
|
|
UuidForPartitionHash hash;
|
2015-06-04 19:34:30 +02:00
|
|
|
foreach ( Device* device, devices )
|
2014-07-28 14:58:06 +02:00
|
|
|
{
|
2015-06-04 19:34:30 +02:00
|
|
|
for ( auto it = PartitionIterator::begin( device );
|
|
|
|
it != PartitionIterator::end( device ); ++it )
|
|
|
|
{
|
|
|
|
Partition* p = *it;
|
|
|
|
QString path = p->partitionPath();
|
|
|
|
QString uuid = p->fileSystem().readUUID( p->partitionPath() );
|
|
|
|
hash.insert( path, uuid );
|
|
|
|
}
|
2014-07-28 14:58:06 +02:00
|
|
|
}
|
2015-06-04 18:57:50 +02:00
|
|
|
cDebug() << hash;
|
2014-07-28 14:58:06 +02:00
|
|
|
return hash;
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
|
2016-05-05 13:29:08 +02:00
|
|
|
|
|
|
|
static QString
|
|
|
|
getLuksUuid( const QString& path )
|
|
|
|
{
|
|
|
|
QProcess process;
|
|
|
|
process.setProgram( "cryptsetup" );
|
|
|
|
process.setArguments( { "luksUUID", path } );
|
|
|
|
process.start();
|
|
|
|
process.waitForFinished();
|
|
|
|
if ( process.exitStatus() != QProcess::NormalExit || process.exitCode() )
|
|
|
|
return QString();
|
|
|
|
QString uuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed();
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-23 18:16:55 +02:00
|
|
|
static QVariant
|
2014-07-28 14:58:06 +02:00
|
|
|
mapForPartition( Partition* partition, const QString& uuid )
|
2014-07-23 18:16:55 +02:00
|
|
|
{
|
|
|
|
QVariantMap map;
|
|
|
|
map[ "device" ] = partition->partitionPath();
|
|
|
|
map[ "mountPoint" ] = PartitionInfo::mountPoint( partition );
|
|
|
|
map[ "fs" ] = partition->fileSystem().name();
|
2014-07-28 14:58:06 +02:00
|
|
|
map[ "uuid" ] = uuid;
|
2015-06-04 18:57:50 +02:00
|
|
|
cDebug() << partition->partitionPath()
|
|
|
|
<< "mtpoint:" << PartitionInfo::mountPoint( partition )
|
|
|
|
<< "fs:" << partition->fileSystem().name()
|
|
|
|
<< uuid;
|
2016-04-22 16:50:46 +02:00
|
|
|
|
|
|
|
if ( partition->roles().has( PartitionRole::Luks ) )
|
|
|
|
{
|
|
|
|
const FileSystem& fsRef = partition->fileSystem();
|
|
|
|
const FS::luks* luksFs = dynamic_cast< const FS::luks* >( &fsRef );
|
|
|
|
if ( luksFs )
|
|
|
|
{
|
|
|
|
map[ "luksMapperName" ] = luksFs->suggestedMapperName( partition->partitionPath() );
|
2016-05-05 13:29:08 +02:00
|
|
|
map[ "luksUuid" ] = getLuksUuid( partition->partitionPath() );
|
2016-04-22 16:50:46 +02:00
|
|
|
cDebug() << "luksMapperName:" << map[ "luksMapperName" ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:16:55 +02:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillGlobalStorageJob::FillGlobalStorageJob( QList< Device* > devices, const QString& bootLoaderPath )
|
2014-07-22 17:32:26 +02:00
|
|
|
: m_devices( devices )
|
2014-07-23 18:16:55 +02:00
|
|
|
, m_bootLoaderPath( bootLoaderPath )
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Set partition information" );
|
|
|
|
}
|
|
|
|
|
2015-04-10 17:46:42 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
QStringList lines;
|
|
|
|
|
|
|
|
foreach ( QVariant partitionItem, createPartitionList().toList() )
|
|
|
|
{
|
|
|
|
if ( partitionItem.type() == QVariant::Map )
|
|
|
|
{
|
|
|
|
QVariantMap partitionMap = partitionItem.toMap();
|
|
|
|
QString path = partitionMap.value( "device" ).toString();
|
|
|
|
QString mountPoint = partitionMap.value( "mountPoint" ).toString();
|
|
|
|
QString fsType = partitionMap.value( "fs" ).toString();
|
|
|
|
qDebug() << partitionMap.value( "uuid" ) << path << mountPoint << fsType;
|
|
|
|
if ( mountPoint.isEmpty() || fsType.isEmpty() )
|
|
|
|
continue;
|
|
|
|
if ( path.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( mountPoint == "/" )
|
|
|
|
lines.append( tr( "Install %1 on <strong>new</strong> %2 system partition." )
|
|
|
|
.arg( Calamares::Branding::instance()->string(
|
|
|
|
Calamares::Branding::ShortProductName ) )
|
|
|
|
.arg( fsType ) );
|
|
|
|
else
|
|
|
|
lines.append( tr( "Set up <strong>new</strong> %2 partition with mount point "
|
|
|
|
"<strong>%1</strong>." )
|
|
|
|
.arg( mountPoint )
|
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( mountPoint == "/" )
|
|
|
|
lines.append( tr( "Install %2 on %3 system partition <strong>%1</strong>." )
|
|
|
|
.arg( path )
|
|
|
|
.arg( Calamares::Branding::instance()->string(
|
|
|
|
Calamares::Branding::ShortProductName ) )
|
|
|
|
.arg( fsType ) );
|
|
|
|
else
|
|
|
|
lines.append( tr( "Set up %3 partition <strong>%1</strong> with mount point "
|
|
|
|
"<strong>%2</strong>." )
|
|
|
|
.arg( path )
|
|
|
|
.arg( mountPoint )
|
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant bootloaderMap = createBootLoaderMap();
|
|
|
|
if ( !m_bootLoaderPath.isEmpty() )
|
|
|
|
{
|
|
|
|
lines.append( tr( "Install boot loader on <strong>%1</strong>." )
|
|
|
|
.arg( m_bootLoaderPath ) );
|
|
|
|
}
|
|
|
|
return lines.join( "<br/>" );
|
|
|
|
}
|
|
|
|
|
2015-06-13 02:26:38 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Setting up mount points." );
|
|
|
|
}
|
|
|
|
|
2014-07-22 17:32:26 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
FillGlobalStorageJob::exec()
|
2014-07-23 18:16:55 +02:00
|
|
|
{
|
|
|
|
Calamares::GlobalStorage* storage = Calamares::JobQueue::instance()->globalStorage();
|
|
|
|
storage->insert( "partitions", createPartitionList() );
|
2015-07-07 19:16:22 +02:00
|
|
|
if ( !m_bootLoaderPath.isEmpty() )
|
|
|
|
{
|
|
|
|
QVariant var = createBootLoaderMap();
|
|
|
|
if ( !var.isValid() )
|
|
|
|
cDebug() << "Failed to find path for boot loader";
|
|
|
|
storage->insert( "bootLoader", var );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
storage->insert( "bootLoader", QVariant() );
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
2015-04-10 17:46:42 +02:00
|
|
|
FillGlobalStorageJob::createPartitionList() const
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
2015-06-04 19:34:30 +02:00
|
|
|
UuidForPartitionHash hash = findPartitionUuids( m_devices );
|
2014-07-22 17:32:26 +02:00
|
|
|
QVariantList lst;
|
2015-06-04 18:57:50 +02:00
|
|
|
cDebug() << "Writing to GlobalStorage[\"partitions\"]";
|
2014-07-28 14:58:06 +02:00
|
|
|
for ( auto device : m_devices )
|
2015-06-04 18:57:50 +02:00
|
|
|
{
|
|
|
|
for ( auto it = PartitionIterator::begin( device );
|
|
|
|
it != PartitionIterator::end( device ); ++it )
|
|
|
|
{
|
2014-07-28 14:58:06 +02:00
|
|
|
lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) );
|
2015-06-04 18:57:50 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
return lst;
|
2014-07-22 17:32:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
2015-04-10 17:46:42 +02:00
|
|
|
FillGlobalStorageJob::createBootLoaderMap() const
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
|
|
|
QVariantMap map;
|
2014-07-23 18:16:55 +02:00
|
|
|
QString path = m_bootLoaderPath;
|
|
|
|
if ( !path.startsWith( "/dev/" ) )
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, path );
|
2014-07-23 18:16:55 +02:00
|
|
|
if ( !partition )
|
|
|
|
return QVariant();
|
|
|
|
path = partition->partitionPath();
|
|
|
|
}
|
|
|
|
map[ "installPath" ] = path;
|
2014-07-22 17:32:26 +02:00
|
|
|
return map;
|
|
|
|
}
|