CalamaresUtils::System is now a class.
This commit is contained in:
parent
0803d86c40
commit
42e465aa10
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "modulesystem/ModuleManager.h"
|
#include "modulesystem/ModuleManager.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
@ -384,5 +385,6 @@ void
|
|||||||
CalamaresApplication::initJobQueue()
|
CalamaresApplication::initJobQueue()
|
||||||
{
|
{
|
||||||
Calamares::JobQueue* jobQueue = new Calamares::JobQueue( this );
|
Calamares::JobQueue* jobQueue = new Calamares::JobQueue( this );
|
||||||
|
new CalamaresUtils::System( Calamares::Settings::instance()->doChroot(), this );
|
||||||
Calamares::Branding::instance()->setGlobals( jobQueue->globalStorage() );
|
Calamares::Branding::instance()->setGlobals( jobQueue->globalStorage() );
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@ ProcessJob::exec()
|
|||||||
int ec = 0;
|
int ec = 0;
|
||||||
QString output;
|
QString output;
|
||||||
if ( m_runInChroot )
|
if ( m_runInChroot )
|
||||||
ec = CalamaresUtils::targetEnvOutput( m_command,
|
ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvOutput( m_command,
|
||||||
output,
|
output,
|
||||||
m_workingPath,
|
m_workingPath,
|
||||||
QString(),
|
QString(),
|
||||||
|
@ -38,7 +38,8 @@ mount( const std::string& device_path,
|
|||||||
const std::string& filesystem_name,
|
const std::string& filesystem_name,
|
||||||
const std::string& options )
|
const std::string& options )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::mount( QString::fromStdString( device_path ),
|
return CalamaresUtils::System::instance()->
|
||||||
|
mount( QString::fromStdString( device_path ),
|
||||||
QString::fromStdString( mount_point ),
|
QString::fromStdString( mount_point ),
|
||||||
QString::fromStdString( filesystem_name ),
|
QString::fromStdString( filesystem_name ),
|
||||||
QString::fromStdString( options ) );
|
QString::fromStdString( options ) );
|
||||||
@ -50,7 +51,8 @@ target_env_call( const std::string& command,
|
|||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::targetEnvCall( QString::fromStdString( command ),
|
return CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( QString::fromStdString( command ),
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
timeout );
|
timeout );
|
||||||
@ -69,7 +71,8 @@ target_env_call( const bp::list& args,
|
|||||||
bp::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return CalamaresUtils::targetEnvCall( list,
|
return CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( list,
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
timeout );
|
timeout );
|
||||||
@ -112,7 +115,8 @@ check_target_env_output( const std::string& command,
|
|||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
QString output;
|
QString output;
|
||||||
int ec = CalamaresUtils::targetEnvOutput( QString::fromStdString( command ),
|
int ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvOutput( QString::fromStdString( command ),
|
||||||
output,
|
output,
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
@ -135,7 +139,8 @@ check_target_env_output( const bp::list& args,
|
|||||||
bp::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int ec = CalamaresUtils::targetEnvOutput( list,
|
int ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvOutput( list,
|
||||||
output,
|
output,
|
||||||
QString(),
|
QString(),
|
||||||
QString::fromStdString( stdin ),
|
QString::fromStdString( stdin ),
|
||||||
|
@ -29,8 +29,30 @@
|
|||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
System* System::s_instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
System::System( bool doChroot, QObject* parent )
|
||||||
|
: QObject( parent )
|
||||||
|
, m_doChroot( doChroot )
|
||||||
|
{
|
||||||
|
Q_ASSERT( !s_instance );
|
||||||
|
s_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System::~System()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
System*System::instance()
|
||||||
|
{
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
mount( const QString& devicePath,
|
System::mount( const QString& devicePath,
|
||||||
const QString& mountPoint,
|
const QString& mountPoint,
|
||||||
const QString& filesystemName,
|
const QString& filesystemName,
|
||||||
const QString& options )
|
const QString& options )
|
||||||
@ -59,7 +81,7 @@ mount( const QString& devicePath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
targetEnvCall( const QStringList& args,
|
System::targetEnvCall( const QStringList& args,
|
||||||
const QString& workingPath,
|
const QString& workingPath,
|
||||||
const QString& stdInput,
|
const QString& stdInput,
|
||||||
int timeoutSec )
|
int timeoutSec )
|
||||||
@ -74,7 +96,7 @@ targetEnvCall( const QStringList& args,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
targetEnvCall( const QString& command,
|
System::targetEnvCall( const QString& command,
|
||||||
const QString& workingPath,
|
const QString& workingPath,
|
||||||
const QString& stdInput,
|
const QString& stdInput,
|
||||||
int timeoutSec )
|
int timeoutSec )
|
||||||
@ -87,7 +109,7 @@ targetEnvCall( const QString& command,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
targetEnvOutput( const QStringList& args,
|
System::targetEnvOutput( const QStringList& args,
|
||||||
QString& output,
|
QString& output,
|
||||||
const QString& workingPath,
|
const QString& workingPath,
|
||||||
const QString& stdInput,
|
const QString& stdInput,
|
||||||
@ -100,7 +122,7 @@ targetEnvOutput( const QStringList& args,
|
|||||||
|
|
||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
if ( !gs ||
|
if ( !gs ||
|
||||||
( doChroot && !gs->contains( "rootMountPoint" ) ) )
|
( m_doChroot && !gs->contains( "rootMountPoint" ) ) )
|
||||||
{
|
{
|
||||||
cLog() << "No rootMountPoint in global storage";
|
cLog() << "No rootMountPoint in global storage";
|
||||||
return -3;
|
return -3;
|
||||||
@ -110,7 +132,7 @@ targetEnvOutput( const QStringList& args,
|
|||||||
QString program;
|
QString program;
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
|
|
||||||
if ( doChroot )
|
if ( m_doChroot )
|
||||||
{
|
{
|
||||||
QString destDir = gs->value( "rootMountPoint" ).toString();
|
QString destDir = gs->value( "rootMountPoint" ).toString();
|
||||||
if ( !QDir( destDir ).exists() )
|
if ( !QDir( destDir ).exists() )
|
||||||
@ -177,7 +199,7 @@ targetEnvOutput( const QStringList& args,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
targetEnvOutput( const QString& command,
|
System::targetEnvOutput( const QString& command,
|
||||||
QString& output,
|
QString& output,
|
||||||
const QString& workingPath,
|
const QString& workingPath,
|
||||||
const QString& stdInput,
|
const QString& stdInput,
|
||||||
@ -192,7 +214,7 @@ targetEnvOutput( const QString& command,
|
|||||||
|
|
||||||
|
|
||||||
qint64
|
qint64
|
||||||
getPhysicalMemoryB()
|
System::getPhysicalMemoryB()
|
||||||
{
|
{
|
||||||
QProcess p;
|
QProcess p;
|
||||||
p.start( "dmidecode", { "-t", "17" } );
|
p.start( "dmidecode", { "-t", "17" } );
|
||||||
@ -219,7 +241,7 @@ getPhysicalMemoryB()
|
|||||||
|
|
||||||
|
|
||||||
qint64
|
qint64
|
||||||
getTotalMemoryB()
|
System::getTotalMemoryB()
|
||||||
{
|
{
|
||||||
// A line in meminfo looks like this, with {print $2} we grab the second column.
|
// A line in meminfo looks like this, with {print $2} we grab the second column.
|
||||||
// MemTotal: 8133432 kB
|
// MemTotal: 8133432 kB
|
||||||
|
@ -20,11 +20,20 @@
|
|||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
{
|
{
|
||||||
static bool doChroot = true;
|
|
||||||
|
class DLLEXPORT System : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit System( bool doChroot, QObject* parent = nullptr );
|
||||||
|
virtual ~System();
|
||||||
|
|
||||||
|
static System* instance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the mount utility with the specified parameters.
|
* Runs the mount utility with the specified parameters.
|
||||||
@ -71,6 +80,13 @@ DLLEXPORT int targetEnvOutput( const QString& command,
|
|||||||
DLLEXPORT qint64 getPhysicalMemoryB(); //Better guess, doesn't work in VirualBox
|
DLLEXPORT qint64 getPhysicalMemoryB(); //Better guess, doesn't work in VirualBox
|
||||||
|
|
||||||
DLLEXPORT qint64 getTotalMemoryB(); //Always underguessed, but always works on Linux
|
DLLEXPORT qint64 getTotalMemoryB(); //Always underguessed, but always works on Linux
|
||||||
|
|
||||||
|
private:
|
||||||
|
static System* s_instance;
|
||||||
|
|
||||||
|
bool m_doChroot;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CALAMARESUTILSSYSTEM_H
|
#endif // CALAMARESUTILSSYSTEM_H
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtils.h"
|
#include "utils/CalamaresUtils.h"
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/YamlUtils.h"
|
#include "utils/YamlUtils.h"
|
||||||
|
|
||||||
@ -97,8 +96,7 @@ Settings::Settings( const QString& settingsFilePath,
|
|||||||
.as< std::string >() );
|
.as< std::string >() );
|
||||||
m_promptInstall = config[ "prompt-install" ].as< bool >();
|
m_promptInstall = config[ "prompt-install" ].as< bool >();
|
||||||
|
|
||||||
bool doChroot = !config[ "dont-chroot" ].as< bool >();
|
m_doChroot = !config[ "dont-chroot" ].as< bool >();
|
||||||
CalamaresUtils::doChroot = doChroot;
|
|
||||||
}
|
}
|
||||||
catch ( YAML::Exception& e )
|
catch ( YAML::Exception& e )
|
||||||
{
|
{
|
||||||
@ -158,5 +156,11 @@ Settings::debugMode() const
|
|||||||
return m_debug;
|
return m_debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Settings::doChroot() const
|
||||||
|
{
|
||||||
|
return m_doChroot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,13 @@ public:
|
|||||||
|
|
||||||
bool debugMode() const;
|
bool debugMode() const;
|
||||||
|
|
||||||
|
bool doChroot() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Settings* s_instance;
|
static Settings* s_instance;
|
||||||
|
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
|
bool m_doChroot;
|
||||||
|
|
||||||
QStringList m_modulesSearchPaths;
|
QStringList m_modulesSearchPaths;
|
||||||
|
|
||||||
|
@ -57,11 +57,13 @@ SetTimezoneJob::exec()
|
|||||||
tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );
|
tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );
|
||||||
|
|
||||||
// Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
|
// Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
|
||||||
CalamaresUtils::targetEnvCall( { "rm",
|
CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "rm",
|
||||||
"-f",
|
"-f",
|
||||||
localtimeSlink } );
|
localtimeSlink } );
|
||||||
|
|
||||||
int ec = CalamaresUtils::targetEnvCall( { "ln",
|
int ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "ln",
|
||||||
"-s",
|
"-s",
|
||||||
zoneinfoPath,
|
zoneinfoPath,
|
||||||
localtimeSlink } );
|
localtimeSlink } );
|
||||||
|
@ -286,11 +286,11 @@ EraseDiskPage::swapSuggestion( const qint64 availableSpaceB ) const {
|
|||||||
// = 4 GiB, if mem >= 64 GiB
|
// = 4 GiB, if mem >= 64 GiB
|
||||||
|
|
||||||
qint64 suggestedSwapSizeB = 0;
|
qint64 suggestedSwapSizeB = 0;
|
||||||
qint64 availableRamB = CalamaresUtils::getPhysicalMemoryB();
|
qint64 availableRamB = CalamaresUtils::System::instance()->getPhysicalMemoryB();
|
||||||
qreal overestimationFactor = 1.01;
|
qreal overestimationFactor = 1.01;
|
||||||
if ( !availableRamB )
|
if ( !availableRamB )
|
||||||
{
|
{
|
||||||
availableRamB = CalamaresUtils::getTotalMemoryB();
|
availableRamB = CalamaresUtils::System::instance()->getTotalMemoryB();
|
||||||
overestimationFactor = 1.10;
|
overestimationFactor = 1.10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,8 @@ CreateUserJob::exec()
|
|||||||
|
|
||||||
foreach ( const QString& group, m_defaultGroups )
|
foreach ( const QString& group, m_defaultGroups )
|
||||||
if ( !groupsLines.contains( group ) )
|
if ( !groupsLines.contains( group ) )
|
||||||
CalamaresUtils::targetEnvCall( { "groupadd", group } );
|
CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "groupadd", group } );
|
||||||
|
|
||||||
QString defaultGroups = m_defaultGroups.join( ',' );
|
QString defaultGroups = m_defaultGroups.join( ',' );
|
||||||
if ( m_autologin )
|
if ( m_autologin )
|
||||||
@ -120,11 +121,12 @@ CreateUserJob::exec()
|
|||||||
else
|
else
|
||||||
autologinGroup = QStringLiteral( "autologin" );
|
autologinGroup = QStringLiteral( "autologin" );
|
||||||
|
|
||||||
CalamaresUtils::targetEnvCall( { "groupadd", autologinGroup } );
|
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", autologinGroup } );
|
||||||
defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) );
|
defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int ec = CalamaresUtils::targetEnvCall( { "useradd",
|
int ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "useradd",
|
||||||
"-m",
|
"-m",
|
||||||
"-s",
|
"-s",
|
||||||
"/bin/bash",
|
"/bin/bash",
|
||||||
@ -139,14 +141,15 @@ CreateUserJob::exec()
|
|||||||
tr( "useradd terminated with error code %1." )
|
tr( "useradd terminated with error code %1." )
|
||||||
.arg( ec ) );
|
.arg( ec ) );
|
||||||
|
|
||||||
ec = CalamaresUtils::targetEnvCall( { "chfn", "-f", m_fullName, m_userName } );
|
ec = CalamaresUtils::System::instance()->targetEnvCall( { "chfn", "-f", m_fullName, m_userName } );
|
||||||
if ( ec )
|
if ( ec )
|
||||||
return Calamares::JobResult::error( tr( "Cannot set full name for user %1." )
|
return Calamares::JobResult::error( tr( "Cannot set full name for user %1." )
|
||||||
.arg( m_userName ),
|
.arg( m_userName ),
|
||||||
tr( "chfn terminated with error code %1." )
|
tr( "chfn terminated with error code %1." )
|
||||||
.arg( ec ) );
|
.arg( ec ) );
|
||||||
|
|
||||||
ec = CalamaresUtils::targetEnvCall( { "chown",
|
ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "chown",
|
||||||
"-R",
|
"-R",
|
||||||
QString( "%1:%2" ).arg( m_userName )
|
QString( "%1:%2" ).arg( m_userName )
|
||||||
.arg( m_userGroup ),
|
.arg( m_userGroup ),
|
||||||
|
@ -61,7 +61,8 @@ SetPasswordJob::exec()
|
|||||||
|
|
||||||
QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() );
|
QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() );
|
||||||
|
|
||||||
int ec = CalamaresUtils::targetEnvCall( { "usermod",
|
int ec = CalamaresUtils::System::instance()->
|
||||||
|
targetEnvCall( { "usermod",
|
||||||
"-p",
|
"-p",
|
||||||
QString::fromLatin1( data ),
|
QString::fromLatin1( data ),
|
||||||
m_userName } );
|
m_userName } );
|
||||||
|
@ -246,9 +246,9 @@ RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
|
|||||||
bool
|
bool
|
||||||
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
|
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
|
||||||
{
|
{
|
||||||
qint64 availableRam = CalamaresUtils::getPhysicalMemoryB();
|
qint64 availableRam = CalamaresUtils::System::instance()->getPhysicalMemoryB();
|
||||||
if ( !availableRam )
|
if ( !availableRam )
|
||||||
availableRam = CalamaresUtils::getTotalMemoryB();
|
availableRam = CalamaresUtils::System::instance()->getTotalMemoryB();
|
||||||
return availableRam >= requiredRam * 0.95; // because MemTotal is variable
|
return availableRam >= requiredRam * 0.95; // because MemTotal is variable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user