2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2017-11-09 11:19:24 +01:00
|
|
|
*
|
2018-06-15 12:15:43 +02:00
|
|
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
2017-11-09 11:19:24 +01: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 "TrackingJobs.h"
|
|
|
|
|
2020-05-19 10:42:25 +02:00
|
|
|
#include "Config.h"
|
|
|
|
|
2019-08-26 15:45:10 +02:00
|
|
|
#include "network/Manager.h"
|
2017-11-22 14:04:37 +01:00
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
2017-11-09 11:19:24 +01:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2020-06-17 10:36:35 +02:00
|
|
|
#include <KMacroExpander>
|
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
#include <QSemaphore>
|
2017-11-13 11:13:19 +01:00
|
|
|
#include <QTimer>
|
2017-11-09 11:19:24 +01:00
|
|
|
|
2019-08-01 23:07:45 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
TrackingInstallJob::TrackingInstallJob( const QString& url )
|
|
|
|
: m_url( url )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:48:32 +02:00
|
|
|
TrackingInstallJob::~TrackingInstallJob() { }
|
2017-11-09 11:45:25 +01:00
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingInstallJob::prettyName() const
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return tr( "Installation feedback" );
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingInstallJob::prettyDescription() const
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return prettyName();
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingInstallJob::prettyStatusMessage() const
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return tr( "Sending installation feedback." );
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
TrackingInstallJob::exec()
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
2019-08-26 15:45:10 +02:00
|
|
|
using CalamaresUtils::Network::Manager;
|
|
|
|
using CalamaresUtils::Network::RequestOptions;
|
|
|
|
using CalamaresUtils::Network::RequestStatus;
|
|
|
|
|
|
|
|
auto result = Manager::instance().synchronousPing(
|
|
|
|
QUrl( m_url ),
|
|
|
|
RequestOptions( RequestOptions::FollowRedirect | RequestOptions::FakeUserAgent,
|
|
|
|
RequestOptions::milliseconds( 5000 ) ) );
|
|
|
|
if ( result.status == RequestStatus::Timeout )
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "install-tracking request timed out.";
|
2017-11-09 11:19:24 +01:00
|
|
|
return Calamares::JobResult::error( tr( "Internal error in install-tracking." ),
|
|
|
|
tr( "HTTP request timed out." ) );
|
|
|
|
}
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
2020-05-19 10:42:25 +02:00
|
|
|
void
|
|
|
|
TrackingInstallJob::addJob( Calamares::JobList& list, InstallTrackingConfig* config )
|
|
|
|
{
|
|
|
|
if ( config->isEnabled() )
|
|
|
|
{
|
|
|
|
const auto* s = CalamaresUtils::System::instance();
|
2020-06-17 10:36:35 +02:00
|
|
|
QHash<QString, QString> map { std::initializer_list< std::pair< QString, QString > > {
|
|
|
|
{ QStringLiteral("CPU"), s->getCpuDescription() },
|
|
|
|
{ QStringLiteral("MEMORY"), QString::number( s->getTotalMemoryB().first ) },
|
|
|
|
{ QStringLiteral("DISK"), QString::number( s->getTotalDiskB() ) }
|
|
|
|
} };
|
|
|
|
QString installUrl = KMacroExpander::expandMacros( config->installTrackingUrl(), map );
|
2020-05-19 10:42:25 +02:00
|
|
|
|
|
|
|
cDebug() << Logger::SubEntry << "install-tracking URL" << installUrl;
|
|
|
|
|
|
|
|
list.append( Calamares::job_ptr( new TrackingInstallJob( installUrl ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingMachineJob::addJob( Calamares::JobList& list, MachineTrackingConfig* config )
|
|
|
|
{
|
|
|
|
if ( config->isEnabled() )
|
|
|
|
{
|
|
|
|
const auto style = config->machineTrackingStyle();
|
|
|
|
if ( style == "neon" )
|
|
|
|
{
|
|
|
|
list.append( Calamares::job_ptr( new TrackingMachineNeonJob() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cWarning() << "Unsupported machine tracking style" << style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingMachineNeonJob::prettyName() const
|
2017-11-22 13:39:52 +01:00
|
|
|
{
|
|
|
|
return tr( "Machine feedback" );
|
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingMachineNeonJob::prettyDescription() const
|
2017-11-22 13:39:52 +01:00
|
|
|
{
|
|
|
|
return prettyName();
|
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
QString
|
|
|
|
TrackingMachineNeonJob::prettyStatusMessage() const
|
2017-11-22 13:39:52 +01:00
|
|
|
{
|
|
|
|
return tr( "Configuring machine feedback." );
|
|
|
|
}
|
|
|
|
|
2019-08-01 23:05:42 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
TrackingMachineNeonJob::exec()
|
2017-11-22 13:39:52 +01:00
|
|
|
{
|
2019-08-02 09:19:15 +02:00
|
|
|
static const auto script = QStringLiteral(
|
|
|
|
R"x(
|
|
|
|
MACHINE_ID=`cat /etc/machine-id`
|
2017-11-22 14:04:37 +01:00
|
|
|
sed -i "s,URI =.*,URI = http://releases.neon.kde.org/meta-release/${MACHINE_ID}," /etc/update-manager/meta-release
|
|
|
|
sed -i "s,URI_LTS =.*,URI_LTS = http://releases.neon.kde.org/meta-release-lts/${MACHINE_ID}," /etc/update-manager/meta-release
|
|
|
|
true
|
2019-08-02 09:19:15 +02:00
|
|
|
)x" );
|
|
|
|
int r = CalamaresUtils::System::instance()->targetEnvCall( "/bin/sh",
|
|
|
|
QString(), // Working dir
|
|
|
|
script,
|
2019-08-01 23:05:42 +02:00
|
|
|
std::chrono::seconds( 1 ) );
|
2017-11-22 14:04:37 +01:00
|
|
|
|
|
|
|
if ( r == 0 )
|
2019-08-02 09:19:15 +02:00
|
|
|
{
|
2017-11-22 14:04:37 +01:00
|
|
|
return Calamares::JobResult::ok();
|
2019-08-02 09:19:15 +02:00
|
|
|
}
|
2017-11-22 14:04:37 +01:00
|
|
|
else if ( r > 0 )
|
2019-08-02 09:19:15 +02:00
|
|
|
{
|
2019-08-01 23:05:42 +02:00
|
|
|
return Calamares::JobResult::error(
|
|
|
|
tr( "Error in machine feedback configuration." ),
|
|
|
|
tr( "Could not configure machine feedback correctly, script error %1." ).arg( r ) );
|
2019-08-02 09:19:15 +02:00
|
|
|
}
|
2017-11-22 14:04:37 +01:00
|
|
|
else
|
2019-08-02 09:19:15 +02:00
|
|
|
{
|
2019-08-01 23:05:42 +02:00
|
|
|
return Calamares::JobResult::error(
|
|
|
|
tr( "Error in machine feedback configuration." ),
|
|
|
|
tr( "Could not configure machine feedback correctly, Calamares error %1." ).arg( r ) );
|
2019-08-02 09:19:15 +02:00
|
|
|
}
|
2017-11-22 13:39:52 +01:00
|
|
|
}
|
2020-05-25 15:56:32 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
TrackingUserJob::addJob( Calamares::JobList& list, UserTrackingConfig* config )
|
|
|
|
{
|
|
|
|
if ( config->isEnabled() )
|
|
|
|
{
|
|
|
|
const auto style = config->userTrackingStyle();
|
|
|
|
if ( style == "kuserfeedback" )
|
|
|
|
{
|
|
|
|
list.append( Calamares::job_ptr( new TrackingKUserFeedbackJob() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cWarning() << "Unsupported user tracking style" << style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TrackingKUserFeedbackJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "KDE user feedback" );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TrackingKUserFeedbackJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
return prettyName();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TrackingKUserFeedbackJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Configuring KDE user feedback." );
|
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
TrackingKUserFeedbackJob::exec()
|
|
|
|
{
|
|
|
|
// This is the contents of a config file to turn on some kind
|
|
|
|
// of KUserFeedback tracking; the level (16) is chosen for minimal
|
|
|
|
// but not zero tracking.
|
|
|
|
static const char config[] = R"x([Global]
|
|
|
|
FeedbackLevel=16
|
|
|
|
)x";
|
|
|
|
|
|
|
|
for ( const QString& area : QStringList { "PlasmaUserFeedback" } )
|
|
|
|
{
|
|
|
|
// TODO: get the configured user name
|
|
|
|
QString path = QStringLiteral( "/home/%1/.config/%2" ).arg( QString(), area );
|
|
|
|
cDebug() << "Configuring KUserFeedback" << path;
|
|
|
|
|
|
|
|
int r = CalamaresUtils::System::instance()->createTargetFile( path, config );
|
|
|
|
if ( r > 0 )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
|
|
|
tr( "Error in KDE user feedback configuration." ),
|
|
|
|
tr( "Could not configure KDE user feedback correctly, script error %1." ).arg( r ) );
|
|
|
|
}
|
|
|
|
else if ( r < 0 )
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error(
|
|
|
|
tr( "Error in KDE user feedback configuration." ),
|
|
|
|
tr( "Could not configure KDE user feedback correctly, Calamares error %1." ).arg( r ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|