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