From 7d8b122835c31085ba4f12f9b8981ffb10764dfb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 08:49:53 -0400 Subject: [PATCH 1/9] [oemid] New module, stub - OEMID is a module for configuring phase-0 things for an OEM, like batch-ID. This is just a stub. - Currently planned functionality is limited to just batch-ID. --- CHANGES | 2 + src/modules/oemid/CMakeLists.txt | 10 +++++ src/modules/oemid/OEMViewStep.cpp | 75 +++++++++++++++++++++++++++++++ src/modules/oemid/OEMViewStep.h | 60 +++++++++++++++++++++++++ src/modules/oemid/oemid.conf | 7 +++ 5 files changed, 154 insertions(+) create mode 100644 src/modules/oemid/CMakeLists.txt create mode 100644 src/modules/oemid/OEMViewStep.cpp create mode 100644 src/modules/oemid/OEMViewStep.h create mode 100644 src/modules/oemid/oemid.conf diff --git a/CHANGES b/CHANGES index cb4b0a7ce..c6a9c9a8b 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,8 @@ This release contains contributions from (alphabetically by first name): ## Modules ## + - *oemid* is a new module for configuring OEM phase-0 (image pre-mastering, + or pre-deployment) things. It has limited functionality at the moment. - All Python modules now bail out gracefully on (at least some) bad configurations, rather than raising an exception. The pre-release scripts now test for exceptions to avoid shipping modules with diff --git a/src/modules/oemid/CMakeLists.txt b/src/modules/oemid/CMakeLists.txt new file mode 100644 index 000000000..be7c97c61 --- /dev/null +++ b/src/modules/oemid/CMakeLists.txt @@ -0,0 +1,10 @@ +calamares_add_plugin( oemid + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + OEMViewStep.cpp + LINK_PRIVATE_LIBRARIES + calamaresui + Qt5::Widgets + SHARED_LIB +) diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp new file mode 100644 index 000000000..8e038e7ff --- /dev/null +++ b/src/modules/oemid/OEMViewStep.cpp @@ -0,0 +1,75 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#include "OEMViewStep.h" + +#include "utils/Variant.h" + +#include + +OEMViewStep::OEMViewStep(QObject* parent) + : Calamares::ViewStep( parent ) + , m_widget( nullptr ) +{ +} + +OEMViewStep::~OEMViewStep() +{ +} + +bool OEMViewStep::isBackEnabled() const +{ + return true; +} + +bool OEMViewStep::isNextEnabled() const +{ + return true; +} + +bool OEMViewStep::isAtBeginning() const +{ + return true; +} + +bool OEMViewStep::isAtEnd() const +{ + return true; +} + +QString OEMViewStep::prettyName() const +{ + return tr( "OEM Configuration" ); +} + +QWidget * OEMViewStep::widget() +{ + return nullptr; // m_widget; +} + +Calamares::JobList OEMViewStep::jobs() const +{ + return Calamares::JobList(); +} + +void OEMViewStep::setConfigurationMap(const QVariantMap& configurationMap) +{ + m_batch = CalamaresUtils::getString( configurationMap, "batch-identifier" ); +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( OEMViewStepFactory, registerPlugin(); ) diff --git a/src/modules/oemid/OEMViewStep.h b/src/modules/oemid/OEMViewStep.h new file mode 100644 index 000000000..137047b11 --- /dev/null +++ b/src/modules/oemid/OEMViewStep.h @@ -0,0 +1,60 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#ifndef OEMVIEWSTEP_H +#define OEMVIEWSTEP_H + +#include +#include + +#include + +#include + +class OEMPage; + +class PLUGINDLLEXPORT OEMViewStep : public Calamares::ViewStep +{ + Q_OBJECT + +public: + explicit OEMViewStep( QObject* parent = nullptr ); + virtual ~OEMViewStep() override; + + QString prettyName() const override; + + QWidget* widget() override; + + bool isNextEnabled() const override; + bool isBackEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + Calamares::JobList jobs() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QString m_batch; + OEMPage* m_widget; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( OEMViewStepFactory ) + +#endif diff --git a/src/modules/oemid/oemid.conf b/src/modules/oemid/oemid.conf new file mode 100644 index 000000000..90587faae --- /dev/null +++ b/src/modules/oemid/oemid.conf @@ -0,0 +1,7 @@ +# This is an OEM setup (phase-0) configuration file. +--- +# The batch-identifier is written to /var/log/installer/oem-id. +# This value is put into the text box as the **suggested** +# OEM ID. If @@DATE@@ is included in the identifier, then +# that is replaced by the current date in YYYYMMDD (ISO) format. +batch-identifier: neon-@@DATE@@ From 96828c1df0fafbcc2ef97e2d91bdffbb908d8189 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 09:03:10 -0400 Subject: [PATCH 2/9] [oemid] Handle substitution in config-string --- src/modules/oemid/OEMViewStep.cpp | 31 ++++++++++++++++++++++++++++++- src/modules/oemid/OEMViewStep.h | 7 ++++++- src/modules/oemid/oemid.conf | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp index 8e038e7ff..b91dceed9 100644 --- a/src/modules/oemid/OEMViewStep.cpp +++ b/src/modules/oemid/OEMViewStep.cpp @@ -20,11 +20,13 @@ #include "utils/Variant.h" +#include #include OEMViewStep::OEMViewStep(QObject* parent) : Calamares::ViewStep( parent ) , m_widget( nullptr ) + , m_visited( false ) { } @@ -52,6 +54,33 @@ bool OEMViewStep::isAtEnd() const return true; } +static QString substitute( QString s ) +{ + QString t_date = QStringLiteral( "@@DATE@@" ); + if ( s.contains( t_date ) ) + { + auto date = QDate::currentDate(); + s = s.replace( t_date, date.toString( Qt::ISODate )); + } + + return s; +} + +void OEMViewStep::onActivate() +{ + if ( !m_visited && m_user_batchIdentifier.isEmpty() ) + { + m_user_batchIdentifier = substitute( m_conf_batchIdentifier ); + // m_widget->setIdentifier( m_user_batchIdentifier ); + } + m_visited = true; +} + +void OEMViewStep::onLeave() +{ + // m_user_batchIdentifier = m_widget->identifier(); +} + QString OEMViewStep::prettyName() const { return tr( "OEM Configuration" ); @@ -69,7 +98,7 @@ Calamares::JobList OEMViewStep::jobs() const void OEMViewStep::setConfigurationMap(const QVariantMap& configurationMap) { - m_batch = CalamaresUtils::getString( configurationMap, "batch-identifier" ); + m_conf_batchIdentifier = CalamaresUtils::getString( configurationMap, "batch-identifier" ); } CALAMARES_PLUGIN_FACTORY_DEFINITION( OEMViewStepFactory, registerPlugin(); ) diff --git a/src/modules/oemid/OEMViewStep.h b/src/modules/oemid/OEMViewStep.h index 137047b11..a4d917278 100644 --- a/src/modules/oemid/OEMViewStep.h +++ b/src/modules/oemid/OEMViewStep.h @@ -46,13 +46,18 @@ public: bool isAtBeginning() const override; bool isAtEnd() const override; + void onActivate() override; + void onLeave() override; + Calamares::JobList jobs() const override; void setConfigurationMap( const QVariantMap& configurationMap ) override; private: - QString m_batch; + QString m_conf_batchIdentifier; + QString m_user_batchIdentifier; OEMPage* m_widget; + bool m_visited; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( OEMViewStepFactory ) diff --git a/src/modules/oemid/oemid.conf b/src/modules/oemid/oemid.conf index 90587faae..36233858c 100644 --- a/src/modules/oemid/oemid.conf +++ b/src/modules/oemid/oemid.conf @@ -3,5 +3,5 @@ # The batch-identifier is written to /var/log/installer/oem-id. # This value is put into the text box as the **suggested** # OEM ID. If @@DATE@@ is included in the identifier, then -# that is replaced by the current date in YYYYMMDD (ISO) format. +# that is replaced by the current date in yyyy-MM-dd (ISO) format. batch-identifier: neon-@@DATE@@ From ae85381aae7540eddf4a223e17c040304f941990 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 09:40:13 -0400 Subject: [PATCH 3/9] [oemid] Initial version of UI --- src/modules/oemid/CMakeLists.txt | 2 ++ src/modules/oemid/OEMPage.ui | 45 +++++++++++++++++++++++++++++++ src/modules/oemid/OEMViewStep.cpp | 35 +++++++++++++++++++----- 3 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/modules/oemid/OEMPage.ui diff --git a/src/modules/oemid/CMakeLists.txt b/src/modules/oemid/CMakeLists.txt index be7c97c61..a2c807a60 100644 --- a/src/modules/oemid/CMakeLists.txt +++ b/src/modules/oemid/CMakeLists.txt @@ -3,6 +3,8 @@ calamares_add_plugin( oemid EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES OEMViewStep.cpp + UI + OEMPage.ui LINK_PRIVATE_LIBRARIES calamaresui Qt5::Widgets diff --git a/src/modules/oemid/OEMPage.ui b/src/modules/oemid/OEMPage.ui new file mode 100644 index 000000000..d84984f0a --- /dev/null +++ b/src/modules/oemid/OEMPage.ui @@ -0,0 +1,45 @@ + + + OEMPage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + -1 + 9 + 391 + 281 + + + + + + + <html><head/><body><p>Enter a batch-identifier here. This will be stored in the target system.</p></body></html> + + + + + + + Batch: + + + + + + + + + diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp index b91dceed9..7af97a3a3 100644 --- a/src/modules/oemid/OEMViewStep.cpp +++ b/src/modules/oemid/OEMViewStep.cpp @@ -18,10 +18,27 @@ #include "OEMViewStep.h" +#include "ui_OEMPage.h" + #include "utils/Variant.h" #include #include +#include + +class OEMPage : public QWidget +{ +public: + OEMPage() + : QWidget( nullptr ) + , m_ui( new Ui_OEMPage() ) + { + m_ui->setupUi( this ); + } + + Ui_OEMPage* m_ui; +} ; + OEMViewStep::OEMViewStep(QObject* parent) : Calamares::ViewStep( parent ) @@ -32,6 +49,8 @@ OEMViewStep::OEMViewStep(QObject* parent) OEMViewStep::~OEMViewStep() { + if ( m_widget && m_widget->parent() == nullptr ) + m_widget->deleteLater(); } bool OEMViewStep::isBackEnabled() const @@ -68,17 +87,16 @@ static QString substitute( QString s ) void OEMViewStep::onActivate() { - if ( !m_visited && m_user_batchIdentifier.isEmpty() ) - { - m_user_batchIdentifier = substitute( m_conf_batchIdentifier ); - // m_widget->setIdentifier( m_user_batchIdentifier ); - } + if ( !m_widget ) + (void) widget(); + if ( !m_visited && m_widget ) + m_widget->m_ui->batchIdentifier->setText( m_user_batchIdentifier ); m_visited = true; } void OEMViewStep::onLeave() { - // m_user_batchIdentifier = m_widget->identifier(); + m_user_batchIdentifier = m_widget->m_ui->batchIdentifier->text(); } QString OEMViewStep::prettyName() const @@ -88,7 +106,9 @@ QString OEMViewStep::prettyName() const QWidget * OEMViewStep::widget() { - return nullptr; // m_widget; + if (!m_widget) + m_widget = new OEMPage; + return m_widget; } Calamares::JobList OEMViewStep::jobs() const @@ -99,6 +119,7 @@ Calamares::JobList OEMViewStep::jobs() const void OEMViewStep::setConfigurationMap(const QVariantMap& configurationMap) { m_conf_batchIdentifier = CalamaresUtils::getString( configurationMap, "batch-identifier" ); + m_user_batchIdentifier = substitute( m_conf_batchIdentifier ); } CALAMARES_PLUGIN_FACTORY_DEFINITION( OEMViewStepFactory, registerPlugin(); ) From e510c829e1fe68379cc413bab75b4d5f6a2b179e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 10:16:59 -0400 Subject: [PATCH 4/9] [oemid] Add form explanation --- src/modules/oemid/OEMPage.ui | 44 +++++++++++++++++++++++++------ src/modules/oemid/OEMViewStep.cpp | 9 +++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/modules/oemid/OEMPage.ui b/src/modules/oemid/OEMPage.ui index d84984f0a..8a6d1c1fa 100644 --- a/src/modules/oemid/OEMPage.ui +++ b/src/modules/oemid/OEMPage.ui @@ -6,34 +6,62 @@ 0 0 - 400 + 592 300 + + + 1 + 0 + + - Form + OEMPage -1 9 - 391 - 281 + 601 + 271 - - + + <html><head/><body><p>Enter a batch-identifier here. This will be stored in the target system.</p></body></html> + + batch-identifier + - + - Batch: + Ba&tch: + + + batchIdentifier + + + + + + + <html><head/><body><h1>OEM Configuration</h1><p>Calamares will use OEM settings while configuring the target system.</p></body></html> + + + Qt::RichText + + + Qt::AlignCenter + + + true diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp index 7af97a3a3..3cec79361 100644 --- a/src/modules/oemid/OEMViewStep.cpp +++ b/src/modules/oemid/OEMViewStep.cpp @@ -20,6 +20,7 @@ #include "ui_OEMPage.h" +#include "utils/Retranslator.h" #include "utils/Variant.h" #include @@ -34,6 +35,10 @@ public: , m_ui( new Ui_OEMPage() ) { m_ui->setupUi( this ); + + CALAMARES_RETRANSLATE( + m_ui->retranslateUi( this ); + ) } Ui_OEMPage* m_ui; @@ -92,11 +97,15 @@ void OEMViewStep::onActivate() if ( !m_visited && m_widget ) m_widget->m_ui->batchIdentifier->setText( m_user_batchIdentifier ); m_visited = true; + + ViewStep::onActivate(); } void OEMViewStep::onLeave() { m_user_batchIdentifier = m_widget->m_ui->batchIdentifier->text(); + + ViewStep::onLeave(); } QString OEMViewStep::prettyName() const From 672634547b1bee56655e0b7982af5d655c786c0d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 10:19:28 -0400 Subject: [PATCH 5/9] [oemid] Tweak UI layout --- src/modules/oemid/OEMPage.ui | 119 +++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/src/modules/oemid/OEMPage.ui b/src/modules/oemid/OEMPage.ui index 8a6d1c1fa..7406c032f 100644 --- a/src/modules/oemid/OEMPage.ui +++ b/src/modules/oemid/OEMPage.ui @@ -19,54 +19,77 @@ OEMPage - - - - -1 - 9 - 601 - 271 - - - - - - - <html><head/><body><p>Enter a batch-identifier here. This will be stored in the target system.</p></body></html> - - - batch-identifier - - - - - - - Ba&tch: - - - batchIdentifier - - - - - - - <html><head/><body><h1>OEM Configuration</h1><p>Calamares will use OEM settings while configuring the target system.</p></body></html> - - - Qt::RichText - - - Qt::AlignCenter - - - true - - - - - + + + + + + + <html><head/><body><p>Enter a batch-identifier here. This will be stored in the target system.</p></body></html> + + + batch-identifier + + + + + + + Ba&tch: + + + batchIdentifier + + + + + + + <html><head/><body><h1>OEM Configuration</h1><p>Calamares will use OEM settings while configuring the target system.</p></body></html> + + + Qt::RichText + + + Qt::AlignCenter + + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 40 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + From 1df726fc1d5d5bf42680b4ef1a6cc79b90c8039e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 10:37:32 -0400 Subject: [PATCH 6/9] [oemid] Add summary widget text --- src/modules/oemid/OEMViewStep.cpp | 6 ++++++ src/modules/oemid/OEMViewStep.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp index 3cec79361..5f3d81d69 100644 --- a/src/modules/oemid/OEMViewStep.cpp +++ b/src/modules/oemid/OEMViewStep.cpp @@ -113,6 +113,12 @@ QString OEMViewStep::prettyName() const return tr( "OEM Configuration" ); } +QString OEMViewStep::prettyStatus() const +{ + return tr( "Set the OEM Batch Identifier to %1." ).arg( m_user_batchIdentifier ); +} + + QWidget * OEMViewStep::widget() { if (!m_widget) diff --git a/src/modules/oemid/OEMViewStep.h b/src/modules/oemid/OEMViewStep.h index a4d917278..d8722594a 100644 --- a/src/modules/oemid/OEMViewStep.h +++ b/src/modules/oemid/OEMViewStep.h @@ -37,6 +37,7 @@ public: virtual ~OEMViewStep() override; QString prettyName() const override; + QString prettyStatus() const override; QWidget* widget() override; From 2b12bd82e41e23a26a99d8afbd4918409469c27f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 10:38:25 -0400 Subject: [PATCH 7/9] [oemid] Stub of a Job - Create job, run it, and just debug-log what it should do. --- src/modules/oemid/CMakeLists.txt | 1 + src/modules/oemid/IDJob.cpp | 38 ++++++++++++++++++++++++++++++ src/modules/oemid/IDJob.h | 39 +++++++++++++++++++++++++++++++ src/modules/oemid/OEMViewStep.cpp | 4 +++- 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/modules/oemid/IDJob.cpp create mode 100644 src/modules/oemid/IDJob.h diff --git a/src/modules/oemid/CMakeLists.txt b/src/modules/oemid/CMakeLists.txt index a2c807a60..0c4ad03ad 100644 --- a/src/modules/oemid/CMakeLists.txt +++ b/src/modules/oemid/CMakeLists.txt @@ -2,6 +2,7 @@ calamares_add_plugin( oemid TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES + IDJob.cpp OEMViewStep.cpp UI OEMPage.ui diff --git a/src/modules/oemid/IDJob.cpp b/src/modules/oemid/IDJob.cpp new file mode 100644 index 000000000..db62b39c5 --- /dev/null +++ b/src/modules/oemid/IDJob.cpp @@ -0,0 +1,38 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#include "IDJob.h" + +#include "utils/Logger.h" + +IDJob::IDJob(const QString& id, QObject* parent) + : Job( parent ) + , m_batchIdentifier( id ) +{ +} + +QString IDJob::prettyName() const +{ + return tr( "OEM Batch Identifier" ); +} + +Calamares::JobResult IDJob::exec() +{ + cDebug() << "Setting OEM Batch ID to" << m_batchIdentifier; + return Calamares::JobResult::ok(); +} diff --git a/src/modules/oemid/IDJob.h b/src/modules/oemid/IDJob.h new file mode 100644 index 000000000..0f563837e --- /dev/null +++ b/src/modules/oemid/IDJob.h @@ -0,0 +1,39 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#ifndef IDJOB_H +#define IDJOB_H + +#include "Job.h" + +#include + +class IDJob : public Calamares::Job +{ +public: + explicit IDJob( const QString& id, QObject* parent = nullptr ); + + virtual QString prettyName() const override; + virtual Calamares::JobResult exec() override; + +private: + QString m_batchIdentifier; +} ; + + +#endif diff --git a/src/modules/oemid/OEMViewStep.cpp b/src/modules/oemid/OEMViewStep.cpp index 5f3d81d69..0f076927b 100644 --- a/src/modules/oemid/OEMViewStep.cpp +++ b/src/modules/oemid/OEMViewStep.cpp @@ -20,6 +20,8 @@ #include "ui_OEMPage.h" +#include "IDJob.h" + #include "utils/Retranslator.h" #include "utils/Variant.h" @@ -128,7 +130,7 @@ QWidget * OEMViewStep::widget() Calamares::JobList OEMViewStep::jobs() const { - return Calamares::JobList(); + return Calamares::JobList() << Calamares::job_ptr( new IDJob( m_user_batchIdentifier ) ); } void OEMViewStep::setConfigurationMap(const QVariantMap& configurationMap) From 127c425a9a7479433c39ac6a51f80d89417e7a17 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 11:22:53 -0400 Subject: [PATCH 8/9] [oemid] Write batch-identifier into standard file location --- src/modules/oemid/IDJob.cpp | 58 ++++++++++++++++++++++++++++++++++++- src/modules/oemid/IDJob.h | 3 ++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/modules/oemid/IDJob.cpp b/src/modules/oemid/IDJob.cpp index db62b39c5..07ce1efad 100644 --- a/src/modules/oemid/IDJob.cpp +++ b/src/modules/oemid/IDJob.cpp @@ -18,8 +18,15 @@ #include "IDJob.h" +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "Settings.h" + #include "utils/Logger.h" +#include +#include + IDJob::IDJob(const QString& id, QObject* parent) : Job( parent ) , m_batchIdentifier( id ) @@ -31,8 +38,57 @@ QString IDJob::prettyName() const return tr( "OEM Batch Identifier" ); } +Calamares::JobResult IDJob::writeId( const QString& dirs, const QString& filename, const QString& contents ) +{ + if ( !QDir().mkpath( dirs ) ) + { + cError() << "Could not create directories" << dirs; + return Calamares::JobResult::error( + tr( "OEM Batch Identifier" ), + tr( "Could not create directories %1." ).arg( dirs ) ); + } + + QFile output( QDir( dirs ).filePath( filename ) ); + if ( output.exists() ) + cWarning() << "Existing OEM Batch ID" << output.fileName() << "overwritten."; + + if ( !output.open( QIODevice::WriteOnly ) ) + { + cError() << "Could not write to" << output.fileName(); + return Calamares::JobResult::error( + tr( "OEM Batch Identifier" ), + tr( "Could not open file %1." ).arg( output.fileName() ) ); + } + + if ( output.write( contents.toUtf8() ) < 0 ) + { + cError() << "Write error on" << output.fileName(); + return Calamares::JobResult::error( + tr( "OEM Batch Identifier" ), + tr( "Could not write to file %1." ).arg( output.fileName() ) ); + } + output.write( "\n" ); // Ignore error on this one + + return Calamares::JobResult::ok(); +} + Calamares::JobResult IDJob::exec() { cDebug() << "Setting OEM Batch ID to" << m_batchIdentifier; - return Calamares::JobResult::ok(); + + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + + QString targetDir = QStringLiteral( "/var/log/installer/" ); + QString targetFile = QStringLiteral( "oem-id" ); + QString rootMount = gs->value( "rootMountPoint" ).toString(); + + static const char noRoot[] = "No rootMountPoint is set."; + static const char yesRoot[] = "rootMountPoint is set:"; + + QString targetPath; + + if ( rootMount.isEmpty() && Calamares::Settings::instance()->doChroot() ) + cWarning() << Logger::SubEntry << noRoot; + + return writeId( Calamares::Settings::instance()->doChroot() ? rootMount + targetDir : targetDir, targetFile, m_batchIdentifier ); } diff --git a/src/modules/oemid/IDJob.h b/src/modules/oemid/IDJob.h index 0f563837e..845a3f451 100644 --- a/src/modules/oemid/IDJob.h +++ b/src/modules/oemid/IDJob.h @@ -25,6 +25,7 @@ class IDJob : public Calamares::Job { + Q_OBJECT public: explicit IDJob( const QString& id, QObject* parent = nullptr ); @@ -32,6 +33,8 @@ public: virtual Calamares::JobResult exec() override; private: + Calamares::JobResult writeId( const QString&, const QString&, const QString& ); + QString m_batchIdentifier; } ; From ea95913be9aea2c7eda6028e1de173fcc737eb59 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 11:25:34 -0400 Subject: [PATCH 9/9] [oemid] Expand documentation a little. --- CHANGES | 3 ++- src/modules/oemid/oemid.conf | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c6a9c9a8b..db141384d 100644 --- a/CHANGES +++ b/CHANGES @@ -25,7 +25,8 @@ This release contains contributions from (alphabetically by first name): ## Modules ## - *oemid* is a new module for configuring OEM phase-0 (image pre-mastering, - or pre-deployment) things. It has limited functionality at the moment. + or pre-deployment) things. It has limited functionality at the moment, + writing only a single batch-identifier file. - All Python modules now bail out gracefully on (at least some) bad configurations, rather than raising an exception. The pre-release scripts now test for exceptions to avoid shipping modules with diff --git a/src/modules/oemid/oemid.conf b/src/modules/oemid/oemid.conf index 36233858c..8f9bc3d08 100644 --- a/src/modules/oemid/oemid.conf +++ b/src/modules/oemid/oemid.conf @@ -4,4 +4,10 @@ # This value is put into the text box as the **suggested** # OEM ID. If @@DATE@@ is included in the identifier, then # that is replaced by the current date in yyyy-MM-dd (ISO) format. +# +# it is ok for the identifier to be empty. +# +# The identifier is written to the file as UTF-8 (this will be no +# different from ASCII, for most inputs) and followed by a newline. +# If the identifier is empty, only a newline is written. batch-identifier: neon-@@DATE@@