2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-10 12:08:43 +02:00
|
|
|
*
|
2015-02-25 13:44:55 +01:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2018-06-15 11:59:11 +02:00
|
|
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
2014-07-10 12:08:43 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ProcessJob.h"
|
|
|
|
|
2014-08-12 14:26:10 +02:00
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
2014-07-10 12:08:43 +02:00
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
namespace Calamares {
|
|
|
|
|
|
|
|
|
2014-07-10 16:45:13 +02:00
|
|
|
ProcessJob::ProcessJob( const QString& command,
|
|
|
|
const QString& workingPath,
|
2014-08-12 14:26:10 +02:00
|
|
|
bool runInChroot,
|
2019-08-01 22:47:42 +02:00
|
|
|
std::chrono::seconds secondsTimeout,
|
2014-07-10 16:45:13 +02:00
|
|
|
QObject* parent )
|
2014-07-10 12:08:43 +02:00
|
|
|
: Job( parent )
|
|
|
|
, m_command( command )
|
2014-07-10 16:45:13 +02:00
|
|
|
, m_workingPath( workingPath )
|
2014-08-12 14:26:10 +02:00
|
|
|
, m_runInChroot( runInChroot )
|
2014-07-10 12:08:43 +02:00
|
|
|
, m_timeoutSec( secondsTimeout )
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
ProcessJob::~ProcessJob()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ProcessJob::prettyName() const
|
|
|
|
{
|
2019-06-07 12:33:31 +02:00
|
|
|
return ( m_runInChroot ? tr( "Run command '%1' in target system." ) : tr( " Run command '%1'." ) )
|
|
|
|
.arg( m_command );
|
2015-06-13 02:23:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ProcessJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Running command %1 %2" )
|
|
|
|
.arg( m_command )
|
|
|
|
.arg( m_runInChroot ? "in chroot." : " ." );
|
2014-07-10 12:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JobResult
|
|
|
|
ProcessJob::exec()
|
|
|
|
{
|
2019-06-07 12:30:38 +02:00
|
|
|
using CalamaresUtils::System;
|
|
|
|
|
2014-08-12 14:26:10 +02:00
|
|
|
if ( m_runInChroot )
|
2019-06-07 12:30:38 +02:00
|
|
|
return CalamaresUtils::System::instance()->
|
|
|
|
targetEnvCommand( { m_command },
|
2015-08-06 19:10:04 +02:00
|
|
|
m_workingPath,
|
|
|
|
QString(),
|
2019-06-07 12:30:38 +02:00
|
|
|
m_timeoutSec )
|
|
|
|
.explainProcess( m_command, m_timeoutSec );
|
2014-08-12 14:26:10 +02:00
|
|
|
else
|
2019-06-07 12:30:38 +02:00
|
|
|
return
|
|
|
|
System::runCommand( System::RunLocation::RunInHost,
|
|
|
|
{ "/bin/sh", "-c", m_command },
|
|
|
|
m_workingPath,
|
|
|
|
QString(),
|
|
|
|
m_timeoutSec )
|
|
|
|
.explainProcess( m_command, m_timeoutSec );
|
2014-07-10 12:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calamares
|