2023-06-16 16:47:13 +02:00
|
|
|
#include "worker.h"
|
|
|
|
#include "update.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
2023-07-14 13:32:00 +02:00
|
|
|
#include <QDirIterator>
|
2023-06-16 16:47:13 +02:00
|
|
|
#include <QThread>
|
2023-07-14 13:32:00 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
2023-08-02 15:50:04 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QJsonParseError>
|
2023-08-23 16:26:55 +02:00
|
|
|
#include <Qt>
|
2023-10-30 15:29:23 +01:00
|
|
|
#include <QScopedPointer>
|
2024-04-29 14:58:29 +02:00
|
|
|
#include <QRegularExpression>
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-06-16 16:47:13 +02:00
|
|
|
#include "message_handler.h"
|
2024-03-15 12:07:15 +01:00
|
|
|
#include <DeviceController/interfaces.h>
|
2023-07-11 16:58:49 +02:00
|
|
|
#include "ismas/ismas_client.h"
|
2023-08-05 18:50:50 +02:00
|
|
|
#include "progress_event.h"
|
|
|
|
#include "mainwindow.h"
|
2023-08-11 10:52:31 +02:00
|
|
|
#include "utils.h"
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-10-30 15:20:15 +01:00
|
|
|
QString const Worker::UPDATE_STEP_OK ( " [ ok]");
|
|
|
|
QString const Worker::UPDATE_STEP_DONE ( " [done]");
|
|
|
|
QString const Worker::UPDATE_STEP_WRONG ( "[WRONG]");
|
|
|
|
QString const Worker::UPDATE_STEP_FAIL ( " [FAIL]");
|
2023-08-02 15:50:04 +02:00
|
|
|
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
|
2023-07-17 16:43:05 +02:00
|
|
|
|
2023-10-23 16:16:11 +02:00
|
|
|
using UPDATE_STEP = Worker::UPDATE_STEP;
|
|
|
|
const QMap<UPDATE_STEP, const char*> Worker::smap (
|
|
|
|
std::initializer_list<std::pair<UPDATE_STEP, const char*>>{
|
|
|
|
#define INSERT_ELEMENT(p) std::pair(p, #p)
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::STARTED),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER),
|
2023-10-30 15:21:26 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE),
|
2023-10-30 15:21:26 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER),
|
2024-04-11 16:15:49 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::PULL_NEW_BRANCH),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::PULL_NEW_BRANCH_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::PULL_NEW_BRANCH_SUCCESS),
|
2023-10-30 15:21:26 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH_FAILURE),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE),
|
2023-10-30 15:21:26 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::FILES_TO_UPDATE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::FILES_TO_DOWNLOAD),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMANDS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_1),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_2),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_3),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_4),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_5),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_6),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_7),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_8),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_9),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_LAST),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE),
|
2023-11-07 09:08:33 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_SUCCESS),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_FAILURE),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::SEND_LAST_VERSION),
|
2024-01-23 15:31:12 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_FINALIZE),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_SUCCEEDED),
|
2024-01-19 13:01:46 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_NOT_NECESSARY),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_FAILED),
|
2023-10-30 15:21:26 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::UPDATE_ACTIVATED),
|
2023-10-23 16:16:11 +02:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::FINISHED),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::DEBUG),
|
2024-01-19 08:24:54 +01:00
|
|
|
INSERT_ELEMENT(UPDATE_STEP::ERROR),
|
|
|
|
INSERT_ELEMENT(UPDATE_STEP::NONE)
|
2023-10-23 16:16:11 +02:00
|
|
|
#undef INSERT_ELEMENT
|
|
|
|
});
|
|
|
|
|
|
|
|
Worker *Worker::instance = nullptr;
|
2023-10-20 13:55:18 +02:00
|
|
|
|
2023-09-06 09:04:43 +02:00
|
|
|
Worker::Worker(int customerNr,
|
2023-07-17 16:43:05 +02:00
|
|
|
int machineNr,
|
|
|
|
int zoneNr,
|
2023-11-16 14:15:05 +01:00
|
|
|
QString repositoryUrl,
|
2023-07-17 16:43:05 +02:00
|
|
|
QString branchName,
|
2023-11-07 09:10:01 +01:00
|
|
|
QString pluginDir,
|
2023-09-06 09:04:43 +02:00
|
|
|
QString pluginName,
|
2023-07-17 16:43:05 +02:00
|
|
|
QString workingDirectory,
|
2023-11-07 09:10:01 +01:00
|
|
|
bool noUpdatePsaHardware,
|
2023-11-21 09:54:57 +01:00
|
|
|
bool alwaysDownloadConfig,
|
|
|
|
bool alwaysDownloadDC,
|
2023-07-17 16:43:05 +02:00
|
|
|
bool dryRun,
|
|
|
|
QObject *parent,
|
|
|
|
char const *serialInterface,
|
|
|
|
char const *baudrate)
|
2023-11-07 09:10:01 +01:00
|
|
|
: m_customerNr(customerNr)
|
2023-07-17 16:43:05 +02:00
|
|
|
, m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0'))
|
|
|
|
, m_machineNr(machineNr)
|
|
|
|
, m_zoneNr(zoneNr)
|
2023-11-07 09:10:01 +01:00
|
|
|
, m_pluginDir(pluginDir)
|
2023-09-06 09:04:43 +02:00
|
|
|
, m_pluginName(pluginName)
|
2023-07-14 13:32:00 +02:00
|
|
|
, m_workingDirectory(workingDirectory)
|
|
|
|
, m_branchName(branchName)
|
2023-11-16 14:15:05 +01:00
|
|
|
, m_customerRepositoryPath(QString("%1/%2.git").arg(repositoryUrl).arg(m_customerNrStr))
|
2023-07-17 16:43:05 +02:00
|
|
|
, m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr))
|
2023-11-07 09:10:01 +01:00
|
|
|
, m_noUpdatePsaHardware(noUpdatePsaHardware)
|
2023-11-21 09:54:57 +01:00
|
|
|
, m_alwaysDownloadConfig(alwaysDownloadConfig)
|
|
|
|
, m_alwaysDownloadDC(alwaysDownloadDC)
|
2023-09-06 09:04:43 +02:00
|
|
|
, m_dryRun(dryRun)
|
|
|
|
, m_parent(parent)
|
|
|
|
, m_serialInterface(serialInterface)
|
|
|
|
, m_baudrate(baudrate)
|
2023-07-17 16:43:05 +02:00
|
|
|
, m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this)
|
2024-01-17 15:28:49 +01:00
|
|
|
, m_versionInfo(QStringList())
|
2023-07-17 16:43:05 +02:00
|
|
|
, m_osVersion(getOsVersion())
|
2023-07-19 16:42:18 +02:00
|
|
|
, m_atbqtVersion(getATBQTVersion())
|
2023-10-12 12:09:19 +02:00
|
|
|
, m_atbUpdateToolVersion(getATBUpdateToolVersion())
|
2023-07-19 16:42:18 +02:00
|
|
|
, m_cpuSerial(getCPUSerial())
|
|
|
|
, m_pluginVersionATBDeciceController(getPluginVersion("/opt/app/ATBAPP/plugins/libATBDeviceControllerPlugin.so"))
|
|
|
|
, m_pluginVersionIngenicoISelf(getPluginVersion("/opt/app/ATBAPP/plugins/libIngenicoISelf_CCPlugin.so"))
|
|
|
|
, m_pluginVersionMobilisisCalc(getPluginVersion("/opt/app/ATBAPP/plugins/libMOBILISIS_CalculatePricePlugin.so"))
|
|
|
|
, m_pluginVersionMobilisisCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libMOBILISIS_CalculatePricePlugin_ConfigUi.so"))
|
|
|
|
, m_pluginVersionPrmCalc(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin.so"))
|
|
|
|
, m_pluginVersionPrmCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin_ConfigUi.so"))
|
|
|
|
, m_pluginVersionTcpZvt(getPluginVersion("/opt/app/ATBAPP/plugins/libTCP_ZVT_CCPlugin.so"))
|
2023-07-14 13:32:00 +02:00
|
|
|
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
|
2023-08-02 15:50:04 +02:00
|
|
|
, m_waitForNewUpdates(this)
|
|
|
|
, m_filesToUpdate()
|
2023-08-11 10:55:53 +02:00
|
|
|
, m_updateProcessRunning(true)
|
2023-10-12 12:09:19 +02:00
|
|
|
, m_mainWindow(nullptr) /* contains plugin */
|
2023-09-09 14:40:43 +02:00
|
|
|
//, m_withoutIsmasDirectPort(true) /* useful for testing */ {
|
|
|
|
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
|
2023-07-11 16:58:49 +02:00
|
|
|
|
2023-10-20 13:55:18 +02:00
|
|
|
// TODO: turn object into singleton
|
|
|
|
instance = this;
|
2024-01-19 08:27:07 +01:00
|
|
|
m_lastFailedUpdateStep = UPDATE_STEP::NONE;
|
2024-05-03 13:32:39 +02:00
|
|
|
|
|
|
|
if (m_noUpdatePsaHardware == false) {
|
|
|
|
m_update = new Update(this,
|
|
|
|
QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr),
|
|
|
|
m_customerNrStr,
|
|
|
|
m_branchName,
|
|
|
|
m_pluginDir,
|
|
|
|
m_pluginName,
|
|
|
|
m_workingDirectory);
|
|
|
|
}
|
2024-01-19 08:27:07 +01:00
|
|
|
|
2023-09-09 14:40:43 +02:00
|
|
|
this->setObjectName("worker-object");
|
2023-07-17 16:43:05 +02:00
|
|
|
QDir::setCurrent(m_workingDirectory);
|
|
|
|
|
2023-10-30 15:22:59 +01:00
|
|
|
m_apismVersion = getAPISMYoctoVersion();
|
2023-06-16 16:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Worker::~Worker() {
|
2024-02-06 11:25:46 +01:00
|
|
|
if (m_update != nullptr) {
|
|
|
|
delete m_update;
|
|
|
|
m_update = nullptr;
|
|
|
|
}
|
2023-06-16 16:47:13 +02:00
|
|
|
}
|
|
|
|
|
2023-10-20 13:55:18 +02:00
|
|
|
void Worker::displayProgressInMainWindow(int progress) {
|
2023-08-05 18:50:50 +02:00
|
|
|
if (m_mainWindow) {
|
2023-10-20 13:55:18 +02:00
|
|
|
QApplication::postEvent(m_mainWindow,
|
|
|
|
new ProgressEvent(this, progress));
|
2023-08-05 18:50:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 13:55:18 +02:00
|
|
|
void Worker::setProgress(int progress) {
|
|
|
|
m_ismasClient.setProgressInPercent(progress);
|
|
|
|
displayProgressInMainWindow(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-06 20:44:26 +02:00
|
|
|
void Worker::startProgressLoop() {
|
2023-10-20 13:55:18 +02:00
|
|
|
displayProgressInMainWindow(MainWindow::START_PROGRESS_LOOP);
|
2023-08-06 20:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::stopProgressLoop() {
|
2023-10-20 13:55:18 +02:00
|
|
|
displayProgressInMainWindow(MainWindow::STOP_PROGRESS_LOOP);
|
2023-08-06 20:44:26 +02:00
|
|
|
}
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
static std::once_flag once;
|
2023-11-07 09:07:08 +01:00
|
|
|
void Worker::run() {
|
2023-08-05 18:50:50 +02:00
|
|
|
// user should not start the update process several times
|
2023-08-02 15:50:04 +02:00
|
|
|
std::call_once(once, &Worker::privateUpdate, this);
|
|
|
|
}
|
|
|
|
|
2023-10-19 13:39:48 +02:00
|
|
|
bool Worker::isRepositoryCorrupted() {
|
|
|
|
QDir customerRepository(m_customerRepository);
|
|
|
|
if (customerRepository.exists()) {
|
|
|
|
QDir customerRepositoryGit(QDir::cleanPath(m_customerRepository + QDir::separator() + ".git/"));
|
2023-11-03 13:44:15 +01:00
|
|
|
if (!m_gc.gitFsck()) {
|
2023-10-19 13:39:48 +02:00
|
|
|
// should never happen
|
2023-11-03 13:44:15 +01:00
|
|
|
Utils::printCriticalErrorMsg("CORRUPTED CUSTOMER REPOSITORY: GIT_FSCK FAILED");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// .git-directory inside git-repository does not exist, which means the
|
|
|
|
// git-repository is corrupted -> remove it and start from scratch
|
|
|
|
if (!customerRepositoryGit.exists()) {
|
|
|
|
// should never happen
|
|
|
|
Utils::printCriticalErrorMsg("CORRUPTED CUSTOMER REPOSITORY .GIT DOES NOT EXIST");
|
2023-10-19 13:39:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-12-13 13:42:12 +01:00
|
|
|
QDir customerRepositoryEtc(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/"));
|
|
|
|
if (!customerRepositoryEtc.exists()) {
|
|
|
|
// should never happen
|
|
|
|
Utils::printCriticalErrorMsg(QString("CORRUPTED CUSTOMER REPOSITORY %1/etc DOES NOT EXIST").arg(m_customerRepository));
|
|
|
|
return true;
|
|
|
|
}
|
2023-10-19 13:39:48 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Worker::repairCorruptedRepository() {
|
|
|
|
QDir customerRepository(m_customerRepository);
|
|
|
|
if (!customerRepository.removeRecursively()) {
|
2023-10-30 15:25:49 +01:00
|
|
|
|
2023-10-19 13:39:48 +02:00
|
|
|
Utils::printCriticalErrorMsg("ERROR REMOVING CORR. CUST-REPOSITORY");
|
2023-10-30 15:25:49 +01:00
|
|
|
|
|
|
|
//m_updateStatus = UpdateStatus(UPDATE_STATUS::REMOVE_GIT_REPOSITORY_FAILED,
|
|
|
|
// QString("REMOVAL OF GIT-REPOSITORY %1 FAILED").arg(m_customerRepository));
|
|
|
|
//IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
|
|
|
// QString("#M=APISM#C=CMD_EVENT#J=") +
|
|
|
|
// m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
|
|
|
// m_updateStatus.m_statusDescription));
|
|
|
|
//emit showErrorMessage("apism sanity check", m_updateStatus.m_statusDescription);
|
|
|
|
|
2023-10-19 13:39:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
void Worker::privateUpdate() {
|
2023-09-06 09:04:43 +02:00
|
|
|
if (!m_mainWindow) {
|
|
|
|
Utils::printCriticalErrorMsg("m_mainWindow NOT SET");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
QString func(__PRETTY_FUNCTION__);
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::STARTED));
|
2023-08-09 16:14:59 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
QScopedPointer<UpdateProcessRunning> upr(new UpdateProcessRunning(this));
|
2024-01-23 15:31:12 +01:00
|
|
|
QStringList lst;
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2024-01-19 13:02:59 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CHECK UPDATE TRIGGER
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NOTE: make sure that nothing is sent to ISMAS during updateTriggerSet
|
|
|
|
ISMAS() << UPDATE_STEP::CHECK_ISMAS_TRIGGER;
|
|
|
|
m_ismasTriggerActive = false;
|
|
|
|
m_updateNotNecessary = false;
|
|
|
|
|
2024-01-25 15:14:42 +01:00
|
|
|
if (QDir(m_customerRepository).exists()) { // ignore a possibly corrupted repository
|
|
|
|
m_ismasTriggerActive = updateTriggerSet();
|
|
|
|
if (m_ismasTriggerActive == false) {
|
|
|
|
QDateTime const ¤t = QDateTime::currentDateTime();
|
|
|
|
m_automaticUpdate = (current.time().hour() < 4);
|
2024-01-19 13:02:59 +01:00
|
|
|
m_versionInfo = m_gc.gitShowReason(m_branchName);
|
2024-01-24 13:07:39 +01:00
|
|
|
|
|
|
|
qCritical() << "***";
|
|
|
|
qCritical() << "privateUpdate ............. m_versionInfo:" << m_versionInfo;
|
|
|
|
qCritical() << "privateUpdate ......... m_automaticUpdate:" << m_automaticUpdate;
|
|
|
|
|
2024-01-19 13:40:24 +01:00
|
|
|
if (m_automaticUpdate) { // update has been triggered within [00:00:00, 00:03:59]
|
2024-01-19 13:02:59 +01:00
|
|
|
m_updateNotNecessary = true;
|
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("NO UPDATE NECESSARY (%1)").arg(current.toString(Qt::ISODate)));
|
2024-01-24 13:07:39 +01:00
|
|
|
|
2024-04-29 14:58:29 +02:00
|
|
|
qCritical() << "privateUpdate m_ismasTriggerStatusMessage:"
|
|
|
|
<< QStringList(m_ismasTriggerStatusMessage);
|
2024-01-25 15:14:42 +01:00
|
|
|
qCritical() << "***";
|
|
|
|
|
2024-04-29 14:58:29 +02:00
|
|
|
// the customer-repository does exist, and the ISMAS-trigger is
|
2024-01-25 15:14:42 +01:00
|
|
|
// *NOT* "WAIT", but from 00:00:00 - 00:03:59 this counts as an
|
|
|
|
// automatic update
|
2024-01-24 13:07:39 +01:00
|
|
|
|
2024-04-29 14:58:29 +02:00
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
|
|
|
// trigger message to ISMAS and CONSOLE
|
|
|
|
ISMAS(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS));
|
|
|
|
// overwrite m_lastFailedUpdateStep
|
2024-01-19 13:02:59 +01:00
|
|
|
m_lastFailedUpdateStep = UPDATE_STEP::NONE;
|
2024-01-25 15:14:42 +01:00
|
|
|
return;
|
2024-01-19 13:02:59 +01:00
|
|
|
}
|
2024-01-24 13:07:39 +01:00
|
|
|
|
|
|
|
qCritical() << "***";
|
|
|
|
|
2024-01-19 13:02:59 +01:00
|
|
|
// the customer-repository does exist, but the ISMAS-trigger is
|
|
|
|
// *NOT* "WAIT", so STOP the update procedure
|
|
|
|
return;
|
|
|
|
}
|
2024-01-25 15:14:42 +01:00
|
|
|
// the customer-repository does exist, and the ISMAS-trigger is "WAIT",
|
|
|
|
// so continue the update procedure
|
|
|
|
} else {
|
2024-01-19 13:58:08 +01:00
|
|
|
// the customer-repository does not exist, so PROCEED with the
|
2024-01-19 13:02:59 +01:00
|
|
|
// update procedure, even if ISMAS-trigger is not correctly set ("WAIT")
|
|
|
|
}
|
|
|
|
|
2024-01-23 12:02:18 +01:00
|
|
|
emit this->disableExit();
|
|
|
|
|
2023-10-19 13:41:44 +02:00
|
|
|
QDir customerRepository(m_customerRepository);
|
|
|
|
|
2024-01-19 13:58:08 +01:00
|
|
|
CONSOLE() << (ISMAS() << UPDATE_STEP::CHECK_SANITY);
|
2023-10-19 13:41:44 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
m_clone = false;
|
|
|
|
m_repairClone = false;
|
|
|
|
m_initialClone = false;
|
2024-04-11 16:16:34 +02:00
|
|
|
m_pulledNewBranch = false;
|
2023-10-30 15:25:49 +01:00
|
|
|
// the customer repository is cloned or
|
|
|
|
// repaired/re-cloned without checking the
|
|
|
|
// ISMAS-trigger (WAIT-)button.
|
|
|
|
|
|
|
|
// Case 1: no existing repository:
|
|
|
|
|
|
|
|
// if there was a sane repository
|
|
|
|
// available, then the trigger-button is
|
|
|
|
// checked:
|
|
|
|
// 1: trigger == WAIT: then
|
2023-10-19 13:41:44 +02:00
|
|
|
// have been activated in ISMAS.
|
|
|
|
|
|
|
|
bool continueUpdate = true; // check if git-clone command has timed-out,
|
|
|
|
// resulting in a corrupted git-repository, which
|
|
|
|
// does not contain an ./etc-directory
|
2023-10-30 15:25:49 +01:00
|
|
|
|
|
|
|
if (isRepositoryCorrupted()) { // a not-existing repository is not meant
|
|
|
|
// to be corrupted
|
2024-01-19 13:58:08 +01:00
|
|
|
CONSOLE() << (ISMAS() << UPDATE_STEP::CHECK_SANITY_FAILURE);
|
2023-10-19 13:41:44 +02:00
|
|
|
if ((continueUpdate = repairCorruptedRepository()) == true) {
|
2023-10-30 15:25:49 +01:00
|
|
|
m_repairClone = true;
|
2024-01-19 13:58:08 +01:00
|
|
|
CONSOLE() << (ISMAS() << UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS);
|
2023-08-07 13:56:51 +02:00
|
|
|
} else {
|
2024-01-19 13:58:08 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE));
|
2023-10-30 15:25:49 +01:00
|
|
|
return;
|
2023-10-19 13:41:44 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-07 13:56:51 +02:00
|
|
|
|
2024-01-19 13:58:08 +01:00
|
|
|
CONSOLE() << (ISMAS() << UPDATE_STEP::CHECK_SANITY_SUCCESS);
|
2023-10-30 15:25:49 +01:00
|
|
|
|
2023-10-19 13:41:44 +02:00
|
|
|
if (continueUpdate) {
|
|
|
|
if ((continueUpdate = customerRepository.exists()) == false) {
|
2023-10-30 15:25:49 +01:00
|
|
|
m_initialClone = (m_repairClone == false);
|
2024-01-19 13:58:08 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::CLONE_REPOSITORY));
|
2023-10-23 16:16:11 +02:00
|
|
|
for (int i = 0; i < 5; ++i) { // try to checkout git repository
|
|
|
|
setProgress(i); // and switch to branch
|
|
|
|
if (m_gc.gitCloneAndCheckoutBranch()) {
|
|
|
|
if (!isRepositoryCorrupted()) {
|
2024-01-26 11:17:06 +01:00
|
|
|
m_versionInfo = m_gc.gitShowReason(m_branchName);
|
2023-10-23 16:16:11 +02:00
|
|
|
GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CLONE_REPOSITORY_SUCCESS));
|
2023-10-19 13:41:44 +02:00
|
|
|
continueUpdate = true;
|
2023-10-30 15:25:49 +01:00
|
|
|
m_clone = true;
|
2023-10-19 13:41:44 +02:00
|
|
|
break;
|
2023-10-23 16:16:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
QThread::sleep(1); // maybe git needs more time
|
|
|
|
}
|
|
|
|
|
|
|
|
if (continueUpdate == false) {
|
2024-01-19 08:27:07 +01:00
|
|
|
GUI() << (ISMAS() << (CONSOLE() << (m_lastFailedUpdateStep = UPDATE_STEP::CLONE_REPOSITORY_FAILURE)));
|
2023-10-30 15:25:49 +01:00
|
|
|
return;
|
2023-10-23 16:16:11 +02:00
|
|
|
}
|
2023-08-30 11:46:00 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
Q_ASSERT_X(m_clone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "clone failed");
|
|
|
|
|
2023-10-20 13:55:18 +02:00
|
|
|
} else {
|
2023-10-23 16:16:11 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
Q_ASSERT_X(!m_clone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_clone not false");
|
|
|
|
Q_ASSERT_X(!m_initialClone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_initialClone not false");
|
|
|
|
Q_ASSERT_X(!m_repairClone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_repairClone not false");
|
|
|
|
|
2023-10-23 16:16:11 +02:00
|
|
|
CONSOLE() << UPDATE_STEP::CHECK_REPOSITORY;
|
|
|
|
if (isRepositoryCorrupted()) {
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_REPOSITORY_FAILURE)));
|
2023-10-30 15:25:49 +01:00
|
|
|
return;
|
2023-10-20 13:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-30 15:25:49 +01:00
|
|
|
}
|
2024-01-26 11:17:06 +01:00
|
|
|
m_versionInfo = m_gc.gitShowReason(m_branchName);
|
2024-01-17 15:28:49 +01:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
CONSOLE() << UPDATE_STEP::CHECK_REPOSITORY_SUCCESS;
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_CHECKOUT_REPOSITORY_SUCCESS);
|
2023-10-30 15:25:49 +01:00
|
|
|
|
2023-12-13 13:49:22 +01:00
|
|
|
if (m_clone == false) {
|
2024-01-19 13:02:59 +01:00
|
|
|
if (m_ismasTriggerActive == false) {
|
2023-12-13 13:49:22 +01:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS));
|
|
|
|
setProgress(_CHECK_ISMAS_TRIGGER_SUCCESS);
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-30 15:25:49 +01:00
|
|
|
if (m_initialClone) {
|
|
|
|
GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER));
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-10-30 15:25:49 +01:00
|
|
|
}
|
2023-12-13 13:49:22 +01:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
if (m_ismasTriggerActive == false) {// make it explicit again: only if the
|
|
|
|
// ismas trigger is active ('WAIT'),
|
|
|
|
// then proceed
|
2023-12-13 13:49:22 +01:00
|
|
|
|
|
|
|
if (m_clone == false) { // if it is an (initial) clone, then
|
|
|
|
return; // run the whole update process:
|
|
|
|
} // sync tariff-files, download jsons,
|
|
|
|
} // download device controller
|
2023-09-28 11:53:59 +02:00
|
|
|
|
2023-08-11 12:20:09 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CHECK-OUT BRANCH
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
if ((continueUpdate = customerEnvironment()) == false) {
|
|
|
|
return;
|
2023-08-11 12:20:09 +02:00
|
|
|
}
|
2024-01-26 11:17:06 +01:00
|
|
|
m_versionInfo = m_gc.gitShowReason(m_branchName);
|
2024-01-23 15:31:12 +01:00
|
|
|
lst = QStringList(QString(smap[UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS]));
|
|
|
|
ISMAS(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECKOUT_BRANCH);
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_CHECKOUT_BRANCH_SUCCESS);
|
2023-10-30 15:25:49 +01:00
|
|
|
|
2024-02-27 13:56:38 +01:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// COMPUTE CHANGED FILES OF CUSTOMER REPOSITORY
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
if ((continueUpdate = filesToUpdate()) == false) {
|
|
|
|
return;
|
2023-08-04 13:48:40 +02:00
|
|
|
}
|
2024-01-26 11:17:06 +01:00
|
|
|
m_versionInfo = m_gc.gitShowReason(m_branchName);
|
2024-01-23 15:31:12 +01:00
|
|
|
lst = QStringList(QString(smap[UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS]));
|
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_REPOSITORY));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_UPDATE_REPOSITORY_SUCCESS);
|
2023-08-04 13:48:40 +02:00
|
|
|
|
2024-04-09 14:56:25 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// (R)SYNC THE REPOSITORY WITH THE LOCAL FILEYSTEM
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
if ((continueUpdate = syncCustomerRepositoryAndFS()) == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lst = QStringList(QString(smap[UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS]));
|
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS));
|
|
|
|
setProgress(_SYNC_CUSTOMER_REPOSITORY_SUCCESS);
|
|
|
|
|
2023-10-23 16:16:11 +02:00
|
|
|
|
2023-11-07 09:11:42 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// EXECUTE OPKG COMMANDS
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
if ((continueUpdate = execOpkgCommands()) == false) {
|
|
|
|
return;
|
|
|
|
}
|
2024-01-23 15:31:12 +01:00
|
|
|
lst = QStringList(QString(smap[UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS]));
|
|
|
|
GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::EXEC_OPKG_COMMANDS);
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_SUCCESS);
|
2023-11-07 09:11:42 +01:00
|
|
|
|
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// UPDATE THE PSA USING THE CHANGED FILES
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2023-11-07 09:11:42 +01:00
|
|
|
if ((continueUpdate = downloadFilesToPSAHardware()) == false) {
|
2023-10-30 15:25:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-01-23 15:31:12 +01:00
|
|
|
lst = QStringList(QString(smap[UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS]));
|
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS);
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-10-30 15:25:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// FUTURE: SAVE LOG FILES
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
if ((continueUpdate = saveLogFile()) == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS_SUCCESS));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_SAVE_LOGS_SUCCESS);
|
2023-10-30 15:25:49 +01:00
|
|
|
|
2024-01-19 13:04:12 +01:00
|
|
|
// final messages: see destructor of UpdateProcessRunning subclass
|
2024-01-24 08:31:22 +01:00
|
|
|
m_lastFailedUpdateStep = UPDATE_STEP::NONE;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 16:16:11 +02:00
|
|
|
bool Worker::updateTriggerSet() {
|
2023-10-30 15:25:49 +01:00
|
|
|
// repository is existent and not corrupted. check now if the ISMAS-trigger
|
|
|
|
// (WAIT-button) is activated even in case of initial checkout
|
|
|
|
static const QString func = "UPDATE-TRIGGER-SET";
|
2023-08-14 14:33:12 +02:00
|
|
|
|
2024-01-19 13:01:46 +01:00
|
|
|
// if (m_withoutIsmasDirectPort) { // useful for testing
|
|
|
|
// return true;
|
|
|
|
//}
|
|
|
|
|
|
|
|
m_ismasTriggerStatusMessage.clear();
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2024-01-19 13:01:46 +01:00
|
|
|
GUI() << (CONSOLE() << UPDATE_STEP::CHECK_ISMAS_TRIGGER);
|
2023-10-23 16:16:11 +02:00
|
|
|
|
2024-03-19 12:41:42 +01:00
|
|
|
bool const automaticUpdate = (QDateTime::currentDateTime().time().hour() < 4);
|
|
|
|
|
2023-11-29 11:28:35 +01:00
|
|
|
QString triggerValue("NOT CHECKED YET");
|
2023-12-13 13:44:55 +01:00
|
|
|
static constexpr int const repeats = 15;
|
|
|
|
for (int repeat = 1; repeat <= repeats; ++repeat) {
|
2023-08-11 10:56:36 +02:00
|
|
|
|
2023-08-18 11:52:34 +02:00
|
|
|
if (repeat > 1) {
|
2023-10-23 16:16:11 +02:00
|
|
|
int const startMs = QTime::currentTime().msecsSinceStartOfDay();
|
2023-08-18 11:52:34 +02:00
|
|
|
int const durationMs = QTime::currentTime().msecsSinceStartOfDay() - startMs;
|
2023-10-23 16:16:11 +02:00
|
|
|
QString const &s = QString("elapsed: %1.%2s").arg(durationMs / 1000).arg(durationMs % 1000);
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = (m_ismasTriggerStatusMessage = (QStringList(func) << s));
|
|
|
|
CONSOLE(lst) << UPDATE_STEP::DEBUG;
|
2023-08-22 13:49:42 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = (m_ismasTriggerStatusMessage = (QStringList(func) << QString("-> REPEAT=%1 (%2)").arg(repeat).arg(repeats-repeat)));
|
2023-12-13 13:44:55 +01:00
|
|
|
CONSOLE(lst) << UPDATE_STEP::DEBUG;
|
2023-08-18 11:52:34 +02:00
|
|
|
}
|
2023-08-22 13:49:42 +02:00
|
|
|
|
2023-12-13 13:44:55 +01:00
|
|
|
if ((repeat % 8) == 0) {
|
2023-10-30 15:28:25 +01:00
|
|
|
CONSOLE(QStringList(func) << "RESTART APISM") << UPDATE_STEP::DEBUG;
|
2023-08-18 11:52:34 +02:00
|
|
|
Command c("systemctl restart apism");
|
|
|
|
if (c.execute("/tmp")) {
|
|
|
|
QThread::sleep(20); // give APISM some time to reconnect
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = (m_ismasTriggerStatusMessage = (QStringList(func) << "RESTART APISM DONE"));
|
|
|
|
CONSOLE(lst) << UPDATE_STEP::DEBUG;
|
2023-08-18 11:52:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 16:17:28 +02:00
|
|
|
if (std::optional<QString> result
|
|
|
|
= IsmasClient::sendRequestReceiveResponse(
|
|
|
|
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-10-23 16:16:11 +02:00
|
|
|
QString const &msg = QString("APISM RESPONSE(%1)=(").arg(repeat) + result.value() + ")";
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = (m_ismasTriggerStatusMessage = (QStringList(func) << msg));
|
|
|
|
CONSOLE(lst) << UPDATE_STEP::DEBUG;
|
2023-08-09 16:17:28 +02:00
|
|
|
|
|
|
|
QJsonParseError parseError;
|
2023-10-30 15:28:25 +01:00
|
|
|
QJsonDocument document(QJsonDocument::fromJson(result.value().toUtf8(), &parseError));
|
2023-08-09 16:17:28 +02:00
|
|
|
if (parseError.error != QJsonParseError::NoError) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("INVALID JSON MSG: PARSING FAILED (json=<START>%1<END> error=[%2] str=[%3] offset=[%4])")
|
|
|
|
.arg(msg)
|
|
|
|
.arg(parseError.error)
|
|
|
|
.arg(parseError.errorString())
|
|
|
|
.arg(parseError.offset));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-09 16:17:28 +02:00
|
|
|
if (!document.isObject()) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("not a json-object %1").arg(result.value()));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject obj = document.object();
|
2023-08-14 14:33:12 +02:00
|
|
|
|
|
|
|
// always look for an 'error' first
|
|
|
|
if (obj.contains("error")) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(obj.value("error").toString());
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-19 08:27:07 +01:00
|
|
|
CONSOLE(QStringList(lst)) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE);
|
2023-08-14 14:33:12 +02:00
|
|
|
QThread::sleep(6);
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-09 16:17:28 +02:00
|
|
|
// sanity check: cust_nr and machine_nr of PSA correct ?
|
|
|
|
// note: this check has to be done here, as the cust_nr and the machine_nr
|
|
|
|
// of the PSA are sent by ISMAS.
|
|
|
|
if (obj.contains("Dev_ID")) {
|
|
|
|
QJsonValue v = obj.value("Dev_ID");
|
|
|
|
if (v.isObject()) {
|
|
|
|
QJsonObject obj = v.toObject();
|
|
|
|
if (obj.contains("Custom_ID") && obj.contains("Device_ID")) {
|
2023-10-23 16:16:11 +02:00
|
|
|
int const customerNr = obj.value("Custom_ID").toInt(-1);
|
|
|
|
int const machineNr = obj.value("Device_ID").toInt(-1);
|
2023-08-09 16:17:28 +02:00
|
|
|
if (customerNr != m_customerNr) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)")
|
|
|
|
.arg(customerNr).arg(m_customerNr));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
|
|
|
if (machineNr != m_machineNr) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)")
|
|
|
|
.arg(machineNr).arg(m_machineNr));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
2023-08-11 10:58:29 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst(QString("Dev_ID DOES NOT CONTAIN Custom_ID AND/OR Device_ID (LINE=%1)").arg(__LINE__));
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
2023-08-11 10:58:29 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("Dev_ID KEY NOT A JSON-OBJECT (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
2023-08-11 10:58:29 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("Dev_ID KEY NOT AVAILABLE (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-09 16:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.contains("Fileupload")) {
|
|
|
|
QJsonValue v = obj.value("Fileupload");
|
|
|
|
if (v.isObject()) {
|
|
|
|
obj = v.toObject();
|
|
|
|
if (obj.contains("TRG")) {
|
2023-10-23 16:16:11 +02:00
|
|
|
if ((triggerValue = obj.value("TRG").toString()) == "WAIT") {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList("ISMAS_UPDATE-TRIGGER SET TO WAIT");
|
2023-10-30 15:28:25 +01:00
|
|
|
m_ismasTriggerActive = true;
|
|
|
|
return m_ismasTriggerActive;
|
2023-08-14 14:33:12 +02:00
|
|
|
} else
|
|
|
|
if (QRegExp("\\s*").exactMatch(triggerValue)) { // check for whitespace
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("%1 EMPTY UPDATE TRIGGER (%2)").arg(repeat).arg(repeats-repeat));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2023-10-30 15:28:25 +01:00
|
|
|
if (m_clone) {
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE)));
|
2023-10-30 15:28:25 +01:00
|
|
|
// if the customer repository has just been cloned
|
2024-01-19 13:01:46 +01:00
|
|
|
return false; // it is OK the ISMAS trigger might not be 'WAIT'
|
2023-10-30 15:28:25 +01:00
|
|
|
}
|
2024-03-19 12:41:42 +01:00
|
|
|
// not a clone and empty update-trigger
|
|
|
|
if (automaticUpdate) {
|
|
|
|
// do not inform ISMAS in case of automatic update, because the
|
|
|
|
// update is not necessary as the trigger-button is not set to WAIT.
|
|
|
|
GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE);
|
|
|
|
|
2023-08-14 14:33:12 +02:00
|
|
|
QThread::sleep(6);
|
|
|
|
continue;
|
2023-08-11 10:58:29 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
// if the download-button once has a wrong value, it will never recover
|
2023-10-30 15:28:25 +01:00
|
|
|
if (m_clone) {
|
2024-01-23 15:31:12 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("TRIGGER-VALUE='%1' != 'WAIT'").arg(triggerValue));
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-03-19 12:41:42 +01:00
|
|
|
if (automaticUpdate) {
|
|
|
|
// do not inform ISMAS in case of automatic update
|
|
|
|
GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE));
|
|
|
|
} else {
|
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE)));
|
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
} else {
|
2024-01-23 15:31:12 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("TRIGGER-VALUE='%1' != 'WAIT'").arg(triggerValue));
|
2024-01-19 13:01:46 +01:00
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-03-19 12:41:42 +01:00
|
|
|
if (automaticUpdate) {
|
|
|
|
// do not inform ISMAS in case of automatic update
|
|
|
|
GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE));
|
|
|
|
} else {
|
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
}
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-09 16:17:28 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("TRG key not available (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("Fileupload not a json-object (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-11 10:58:29 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("Fileupload not available (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-09 16:17:28 +02:00
|
|
|
} else {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("no ISMAS response (LINE=%1)").arg(__LINE__));
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 12:03:46 +01:00
|
|
|
CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE);
|
2023-08-09 16:17:28 +02:00
|
|
|
QThread::sleep(6);
|
2024-01-19 13:01:46 +01:00
|
|
|
continue;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
if (m_initialClone == false) {
|
|
|
|
if (!triggerValue.contains("WAIT", Qt::CaseInsensitive)) {
|
2024-01-19 13:01:46 +01:00
|
|
|
m_ismasTriggerStatusMessage = QStringList(QString("ISMAS_UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") + triggerValue + ")");
|
|
|
|
QStringList lst = m_ismasTriggerStatusMessage;
|
2024-01-23 15:31:12 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)));
|
2024-01-19 13:01:46 +01:00
|
|
|
return false;
|
2023-10-30 15:28:25 +01:00
|
|
|
}
|
2023-10-23 16:16:11 +02:00
|
|
|
}
|
2023-08-07 13:56:51 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
bool Worker::customerEnvironment() {
|
|
|
|
// configure customer environment -> checkout branch in case someone has
|
|
|
|
// changed the zone_nr
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::CHECKOUT_BRANCH));
|
2023-08-07 13:56:51 +02:00
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
2024-04-11 16:16:34 +02:00
|
|
|
if (m_clone == false) {
|
|
|
|
if (m_gc.branchExistsRemotely()) {
|
2024-04-29 14:59:10 +02:00
|
|
|
QString msg;
|
|
|
|
QStringList lst;
|
2024-04-11 16:16:34 +02:00
|
|
|
if (!m_gc.branchExistsLocally()) {
|
2024-04-29 14:59:10 +02:00
|
|
|
lst.clear();
|
2024-04-11 16:16:34 +02:00
|
|
|
msg = QString("PULLING OF NEW BRANCH " + m_branchName + " DOES NOT EXIST LOCALLY");
|
2024-04-29 14:59:10 +02:00
|
|
|
lst << msg;
|
2024-04-11 16:16:34 +02:00
|
|
|
CONSOLE(lst) << UPDATE_STEP::PULL_NEW_BRANCH;
|
|
|
|
if (!m_gc.gitPullNewBranches()) {
|
2024-04-29 14:59:10 +02:00
|
|
|
lst.clear();
|
|
|
|
msg = QString("PULLING OF NEW BRANCH " + m_branchName + " FAILED");
|
|
|
|
lst << msg;
|
2024-04-11 16:16:34 +02:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::PULL_NEW_BRANCH_FAILURE)));
|
|
|
|
return false;
|
|
|
|
} else {
|
2024-04-29 14:59:10 +02:00
|
|
|
lst.clear();
|
|
|
|
msg = QString("PULLING OF NEW BRANCH " + m_branchName + " SUCCESS");
|
|
|
|
lst << msg;
|
2024-04-11 16:16:34 +02:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::PULL_NEW_BRANCH_SUCCESS)));
|
|
|
|
m_pulledNewBranch = true;
|
|
|
|
}
|
|
|
|
} else {
|
2024-04-29 14:59:10 +02:00
|
|
|
m_pulledNewBranch = false;
|
2024-04-11 16:16:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
if (m_gc.gitCheckoutBranch()) {
|
2023-08-02 15:50:04 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2023-10-30 15:28:25 +01:00
|
|
|
QStringList lst(QString("CHECKOUT OF " + m_customerRepository + "FAILED"));
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECKOUT_BRANCH_FAILURE)));
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
} else {// cannot happen
|
|
|
|
QStringList lst(QString(m_customerRepository + " DOES NOT EXIST"));
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::CHECKOUT_BRANCH_FAILURE)));
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-07 13:56:51 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
bool Worker::filesToUpdate() {
|
|
|
|
// determine which files has to be updated: either sent to the hardware or
|
|
|
|
// rsynced with the filesystem in case of tariff-files
|
2023-10-20 13:55:18 +02:00
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_REPOSITORY));
|
2023-09-28 11:57:17 +02:00
|
|
|
|
|
|
|
// always execute contents of opkg_commands-file
|
|
|
|
m_filesToUpdate << "etc/psa_update/opkg_commands";
|
|
|
|
|
2024-04-11 16:20:46 +02:00
|
|
|
if ((m_clone || m_pulledNewBranch) && m_alwaysDownloadConfig) {
|
2023-11-21 09:54:57 +01:00
|
|
|
// always download all json-config files, even if none of them have been
|
|
|
|
// changed in the git repository. useful for first installation.
|
|
|
|
QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_config"));
|
|
|
|
if (dir.exists()) {
|
|
|
|
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
|
|
|
|
if (!jsons.isEmpty()) {
|
2023-12-15 09:39:46 +01:00
|
|
|
for (QStringList::size_type i=0; i<jsons.size(); ++i) {
|
|
|
|
m_filesToUpdate << QDir::cleanPath(QString("etc/psa_config/") + jsons.at(i));
|
|
|
|
}
|
2023-11-21 09:54:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 16:20:46 +02:00
|
|
|
if ((m_clone || m_pulledNewBranch) && m_alwaysDownloadConfig) {
|
2023-11-21 09:54:57 +01:00
|
|
|
// always download the last dc-binary, even if not changed in the
|
|
|
|
// git repository. useful for first installation.
|
2023-12-13 13:49:22 +01:00
|
|
|
QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/dc"));
|
2023-11-21 09:54:57 +01:00
|
|
|
if (dir.exists()) {
|
2023-12-13 13:49:22 +01:00
|
|
|
QStringList dc = dir.entryList(QStringList() << "dc2c.bin", QDir::Files,
|
2023-11-21 09:54:57 +01:00
|
|
|
QDir::SortFlag::Time | QDir::SortFlag::Reversed);
|
|
|
|
if (!dc.isEmpty()) {
|
2023-12-15 09:39:46 +01:00
|
|
|
m_filesToUpdate << QDir::cleanPath(QString("etc/dc/") + dc.first());
|
2023-11-21 09:54:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-18 11:40:04 +02:00
|
|
|
if (std::optional<QString> changes = m_gc.gitPull()) {
|
2023-10-30 15:28:25 +01:00
|
|
|
if (!changes.value().contains("Already up to date")) {
|
|
|
|
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) {
|
2023-09-28 11:57:17 +02:00
|
|
|
m_filesToUpdate << changedFileNames.value();
|
2023-08-02 16:53:19 +02:00
|
|
|
}
|
2023-09-28 11:57:17 +02:00
|
|
|
}
|
2023-10-31 09:16:24 +01:00
|
|
|
m_filesToUpdate.removeDuplicates();
|
2023-11-29 12:06:17 +01:00
|
|
|
|
2024-02-05 16:26:53 +01:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") FILES-TO-UPDATE" << m_filesToUpdate;
|
2023-11-29 12:06:17 +01:00
|
|
|
|
2023-10-31 09:16:24 +01:00
|
|
|
GUI(m_filesToUpdate) << (CONSOLE(m_filesToUpdate) << UPDATE_STEP::FILES_TO_UPDATE);
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_FILES_TO_UPDATE);
|
2023-10-30 15:28:25 +01:00
|
|
|
} else {
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << (m_lastFailedUpdateStep = UPDATE_STEP::UPDATE_REPOSITORY_FAILURE)));
|
2023-10-31 09:14:02 +01:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
2023-08-07 13:56:51 +02:00
|
|
|
|
2023-09-28 11:57:17 +02:00
|
|
|
return true;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
|
2023-11-07 09:10:45 +01:00
|
|
|
bool Worker::computeFilesToDownload() {
|
2023-10-20 13:55:18 +02:00
|
|
|
m_filesToDownload.clear();
|
2023-11-07 09:10:45 +01:00
|
|
|
for (int i = 0; i < m_filesToUpdate.size(); ++i) {
|
|
|
|
QString const fName = m_filesToUpdate.at(i);
|
|
|
|
if (fName.contains("DC2C_print", Qt::CaseInsensitive) ||
|
|
|
|
fName.contains("DC2C_device", Qt::CaseInsensitive) ||
|
|
|
|
fName.contains("DC2C_conf", Qt::CaseInsensitive) ||
|
|
|
|
fName.contains("DC2C_cash", Qt::CaseInsensitive)) {
|
|
|
|
m_filesToDownload << fName; // download printer-config-files
|
|
|
|
} else {
|
2023-12-13 13:49:22 +01:00
|
|
|
if (fName.contains("dc2c.bin")) {
|
2023-11-07 09:10:45 +01:00
|
|
|
m_filesToDownload << fName; // download device controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
|
2023-11-07 09:10:45 +01:00
|
|
|
return (m_filesToDownload.size() > 0);
|
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
|
2023-11-07 09:10:45 +01:00
|
|
|
bool Worker::execOpkgCommands() {
|
2023-08-02 15:50:04 +02:00
|
|
|
for (int i = 0; i < m_filesToUpdate.size(); ++i) {
|
2023-08-11 10:52:31 +02:00
|
|
|
QString const fName = m_filesToUpdate.at(i);
|
2023-08-02 15:50:04 +02:00
|
|
|
if (fName.contains("opkg_commands", Qt::CaseInsensitive)) {
|
2023-10-30 15:28:25 +01:00
|
|
|
GUI() << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMANDS);
|
2023-08-02 15:50:04 +02:00
|
|
|
// execute opkg commands
|
|
|
|
if (QDir::setCurrent(m_customerRepository)) {
|
|
|
|
QFile f(fName);
|
|
|
|
if (f.exists()) {
|
|
|
|
if (f.open(QIODevice::ReadOnly)) {
|
|
|
|
QTextStream in(&f);
|
2023-10-30 15:28:25 +01:00
|
|
|
m_opkgCommands.clear();
|
2023-12-13 10:04:38 +01:00
|
|
|
QStringList opkgErrorLst;
|
2023-08-02 15:50:04 +02:00
|
|
|
while (!in.atEnd()) {
|
|
|
|
QString line = in.readLine();
|
|
|
|
static const QRegularExpression comment("^\\s*#.*$");
|
|
|
|
if (line.indexOf(comment, 0) == -1) {
|
|
|
|
// found opkg command
|
|
|
|
QString opkgCommand = line.trimmed();
|
2023-10-10 16:01:45 +02:00
|
|
|
if (!executeOpkgCommand(opkgCommand)) {
|
2023-12-13 10:04:38 +01:00
|
|
|
opkgErrorLst << opkgCommand;
|
2023-10-10 16:01:45 +02:00
|
|
|
} else {
|
|
|
|
QString cmd = "\n " + opkgCommand;
|
|
|
|
emit appendText(cmd);
|
2023-10-30 15:28:25 +01:00
|
|
|
m_opkgCommands << cmd;
|
|
|
|
|
|
|
|
QStringList const opkgLst(opkgCommand);
|
|
|
|
QStringList const cmdLst(cmd);
|
|
|
|
|
|
|
|
switch(m_opkgCommands.size()) {
|
|
|
|
case 1:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_1));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_1);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_2));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_2);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_3));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_3);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_4));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_4);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_5));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_5);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_6));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_6);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_7));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_7);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_8));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_8);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_9));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_9);
|
2023-10-30 15:28:25 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_LAST));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_LAST);
|
2023-10-30 15:28:25 +01:00
|
|
|
}
|
2023-10-10 16:01:45 +02:00
|
|
|
}
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
f.close();
|
2023-12-13 10:04:38 +01:00
|
|
|
if (opkgErrorLst.size() == 0) {
|
2023-10-30 15:28:25 +01:00
|
|
|
if (m_opkgCommands.size() > 0) {
|
2023-10-10 16:01:45 +02:00
|
|
|
m_displayIndex = 1;
|
2023-12-13 10:04:38 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_SUCCESS);
|
2023-10-10 16:01:45 +02:00
|
|
|
}
|
2023-08-09 16:17:28 +02:00
|
|
|
} else {
|
|
|
|
m_displayIndex = 1;
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS(opkgErrorLst) << (GUI(opkgErrorLst) << (CONSOLE() << (m_lastFailedUpdateStep = UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE)));
|
2023-10-30 15:28:25 +01:00
|
|
|
GUI() << UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE;
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_EXEC_OPKG_COMMAND_FAILURE);
|
2023-10-10 16:01:45 +02:00
|
|
|
return false;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-07 09:10:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Worker::downloadFilesToPSAHardware() {
|
|
|
|
m_displayIndex = 0;
|
|
|
|
|
2023-11-29 12:07:25 +01:00
|
|
|
GUI(m_filesToDownload) << (CONSOLE(m_filesToDownload) << UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE);
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE);
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-11-07 09:10:45 +01:00
|
|
|
if (m_noUpdatePsaHardware == false) {
|
2024-01-23 15:31:12 +01:00
|
|
|
if (computeFilesToDownload() > 0) {
|
|
|
|
QStringList lst = m_filesToDownload;
|
|
|
|
ISMAS(lst) << (CONSOLE(lst) << UPDATE_STEP::FILES_TO_DOWNLOAD);
|
2023-09-06 09:04:43 +02:00
|
|
|
|
2024-02-06 11:25:46 +01:00
|
|
|
if (m_update && m_update->doUpdate(m_displayIndex, m_filesToDownload)) {
|
2023-12-15 09:39:46 +01:00
|
|
|
// prepared for use: at the moment, the dc-library does not work
|
|
|
|
// as expected.
|
|
|
|
|
|
|
|
// static const QRegularExpression re("^.*\\.json$");
|
|
|
|
// return update.checkDownloadedJsonVersions(m_filesToDownload.filter(re));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-23 15:31:12 +01:00
|
|
|
|
2024-04-09 14:56:25 +02:00
|
|
|
CONSOLE(lst) << (m_lastFailedUpdateStep = UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE);
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE);
|
2024-01-23 15:31:12 +01:00
|
|
|
|
|
|
|
return false;
|
2023-09-09 14:40:43 +02:00
|
|
|
}
|
2023-08-03 09:06:50 +02:00
|
|
|
}
|
2023-08-02 15:50:04 +02:00
|
|
|
|
2023-09-09 14:40:43 +02:00
|
|
|
return true;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
bool Worker::syncCustomerRepositoryAndFS() {
|
|
|
|
ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY));
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
if (QDir::setCurrent(m_customerRepository)) {
|
2023-08-14 14:33:12 +02:00
|
|
|
Command md("bash");
|
|
|
|
if (!md.execute(m_customerRepository,
|
2023-10-06 10:42:35 +02:00
|
|
|
QStringList() << "-c" << "mkdir -p /etc/psa_config /etc/dc /etc/psa_tariff")) {
|
2023-08-14 14:33:12 +02:00
|
|
|
qCritical() << "COULD NOT EXECUTE '" << md.command() << "' exitCode=(" << md.exitCode() << ")";
|
|
|
|
}
|
2023-12-13 13:48:23 +01:00
|
|
|
QString const params("-v "
|
2023-08-04 13:52:57 +02:00
|
|
|
"--recursive "
|
2023-08-02 15:50:04 +02:00
|
|
|
"--progress "
|
|
|
|
"--checksum "
|
|
|
|
"--exclude=.* "
|
|
|
|
"--include=*.bin "
|
|
|
|
"--include=*.json "
|
|
|
|
"--include=*.ini");
|
|
|
|
QStringList cmds;
|
2023-10-06 13:00:25 +02:00
|
|
|
|
|
|
|
if (QDir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/")).exists()) {
|
|
|
|
cmds << QString("rsync ") + params.simplified() + " etc/ /etc";
|
|
|
|
Utils::printInfoMsg(QString("CONFIGURED SYNCING TO /ETC"));
|
|
|
|
}
|
|
|
|
if (QDir(QDir::cleanPath(m_customerRepository + QDir::separator() + "opt/")).exists()) {
|
|
|
|
cmds << QString("rsync ") + params.simplified() + " opt/ /opt";
|
|
|
|
Utils::printInfoMsg(QString("CONFIGURED SYNCING TO /OPT"));
|
|
|
|
}
|
2023-08-02 15:50:04 +02:00
|
|
|
|
|
|
|
QString cmd;
|
|
|
|
bool error = false;
|
|
|
|
foreach (cmd, cmds) {
|
|
|
|
if (!error) {
|
|
|
|
Command c("bash");
|
|
|
|
qInfo() << "EXECUTING CMD..." << cmd;
|
2023-10-06 13:00:00 +02:00
|
|
|
Utils::printInfoMsg(QString("EXECUTING CMD %1...").arg(cmd));
|
2023-08-02 15:50:04 +02:00
|
|
|
if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) {
|
2023-08-04 13:49:32 +02:00
|
|
|
QStringList result = c.getCommandResult().split('\n');
|
2023-08-23 16:26:55 +02:00
|
|
|
QString const &p1 = "send_files mapped ";
|
|
|
|
QString const &p2 = "of size";
|
2023-10-30 15:28:25 +01:00
|
|
|
|
2023-08-04 13:49:32 +02:00
|
|
|
for (int i = 0; i < result.size(); ++i) {
|
2023-08-23 16:26:55 +02:00
|
|
|
QString line = result.at(i);
|
|
|
|
qInfo() << line;
|
|
|
|
|
|
|
|
// "send_files mapped etc/psa_tariff/tariff01.json of size 19339"
|
|
|
|
int sendFilesAtPos = line.indexOf(p1);
|
|
|
|
int ofSizeAtPos = line.indexOf(p2);
|
|
|
|
if (sendFilesAtPos != -1 && ofSizeAtPos != -1) {
|
|
|
|
sendFilesAtPos += p1.length();
|
|
|
|
QString const &s = line.mid(sendFilesAtPos, ofSizeAtPos - sendFilesAtPos).trimmed();
|
2023-10-30 15:28:25 +01:00
|
|
|
|
|
|
|
//m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_FILE_SUCCESS,
|
|
|
|
// QString("RSYNC FILE ") + s.split("/").last() +
|
|
|
|
// " LAST-COMMIT: " + m_gc.gitLastCommit(s));
|
|
|
|
//IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
|
|
|
// QString("#M=APISM#C=CMD_EVENT#J=") +
|
|
|
|
// m_ismasClient.rsyncFile(m_updateStatus.m_statusDescription, ""));
|
2023-08-23 16:26:55 +02:00
|
|
|
}
|
2023-08-04 13:49:32 +02:00
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
} else {
|
2023-08-11 10:52:31 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("CMD ") + cmd + " FAILED: "
|
2023-08-14 14:33:12 +02:00
|
|
|
+ c.getCommandResult() + QString(" EXIT_CODE=(%1)").arg(c.exitCode()));
|
2023-08-02 15:50:04 +02:00
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!error) {
|
2023-08-22 12:31:15 +02:00
|
|
|
// now check tariff-files in etc and /etc/psa_tariff
|
|
|
|
QDir dir1(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_tariff"));
|
|
|
|
QDir dir2("/etc/psa_tariff");
|
|
|
|
if (Utils::sameFilesInDirs(dir1, dir2)) {
|
2024-03-08 08:44:39 +01:00
|
|
|
CONSOLE() << QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_tariff")
|
|
|
|
<< "AND /etc/psa_tariff ARE DIFFERENT: CHANGED CUSTOMER-NUMBER?";
|
2023-08-22 12:31:15 +02:00
|
|
|
}
|
2024-03-08 08:44:39 +01:00
|
|
|
CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS;
|
|
|
|
setProgress(_SYNC_CUSTOMER_REPOSITORY_SUCCESS);
|
|
|
|
return true;
|
2023-08-02 15:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 08:27:07 +01:00
|
|
|
ISMAS() << (GUI() << (CONSOLE() << (m_lastFailedUpdateStep = UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE)));
|
2023-11-07 11:43:26 +01:00
|
|
|
setProgress(_SYNC_CUSTOMER_REPOSITORY_FAILURE);
|
2023-08-02 15:50:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
bool Worker::saveLogFile() {
|
|
|
|
// ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS));
|
|
|
|
// ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS_FAILURE));
|
2023-08-02 15:50:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-30 15:28:25 +01:00
|
|
|
|
2023-07-17 16:43:05 +02:00
|
|
|
QString Worker::getOsVersion() const {
|
|
|
|
QString const cmd = QString("echo -n $(cat /etc/os-release | head -n 1 | cut -d'\"' -f2 | tr -d '\"')");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-18 11:31:15 +02:00
|
|
|
QString Worker::getATBUpdateToolYoctoVersion() {
|
|
|
|
if (QFile::exists("/var/lib/opkg/status")) {
|
|
|
|
QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A1 atbupdatetool | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute("/tmp", QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:22:59 +01:00
|
|
|
QString Worker::getAPISMYoctoVersion() {
|
|
|
|
if (QFile::exists("/var/lib/opkg/status")) {
|
2024-02-02 08:18:13 +01:00
|
|
|
QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A1 -e apism[[:space:]]*$ | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2)");
|
2023-10-30 15:22:59 +01:00
|
|
|
Command c("bash");
|
|
|
|
if (c.execute("/tmp", QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult(); // 1.4.1.0-r4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-18 11:31:15 +02:00
|
|
|
QString Worker::getATBUpdateToolYoctoInstallationStatus() {
|
|
|
|
if (QFile::exists("/var/lib/opkg/status")) {
|
|
|
|
QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A3 atbupdatetool | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2,3,4)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute("/tmp", QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-30 15:22:59 +01:00
|
|
|
QString Worker::getAPISMYoctoInstallationStatus() {
|
|
|
|
if (QFile::exists("/var/lib/opkg/status")) {
|
|
|
|
QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A3 apism | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2,3,4)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute("/tmp", QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
2023-10-18 11:31:15 +02:00
|
|
|
|
2024-02-09 13:02:11 +01:00
|
|
|
QString Worker::getDCVersionPreparedForDownload(QString const &filename) {
|
|
|
|
if (QFile::exists(filename)) { // <customer-repo/etc/dc/dc2c.bin>
|
|
|
|
QString const cmd = QString("strings %1 | grep -e DC2[Cc]\\. | head -n1").arg(filename);
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute("/tmp", QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult(); // DC2c.04.42 14.09.2023
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-18 11:31:15 +02:00
|
|
|
|
2023-07-19 16:42:18 +02:00
|
|
|
QString Worker::getATBQTVersion() const {
|
|
|
|
QString const cmd = QString("echo -n $(/opt/app/ATBAPP/ATBQT -v | head -n 2 | cut -d':' -f2)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2023-10-12 12:09:19 +02:00
|
|
|
QString Worker::getATBUpdateToolVersion() const {
|
|
|
|
return APP_EXTENDED_VERSION;
|
|
|
|
}
|
|
|
|
|
2023-07-19 16:42:18 +02:00
|
|
|
QString Worker::getCPUSerial() const {
|
|
|
|
QString const cmd = QString("echo -n $(cat /proc/cpuinfo | grep -i Serial | cut -d':' -f2)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Worker::getRaucVersion() const {
|
|
|
|
QString const cmd = QString("echo -n $(rauc --version)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Worker::getOpkgVersion() const {
|
|
|
|
QString const cmd = QString("echo -n $(opkg --version)");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Worker::getPluginVersion(QString const &pluginFileName) const {
|
|
|
|
QString const cmd = QString("echo -n $(strings %1 | grep \\\"Version\\\" | cut -d':' -f2 | tr -d '\"' | tr -d ',')").arg(pluginFileName);
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_workingDirectory, QStringList() << "-c" << cmd)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Worker::getDCVersion() const {
|
|
|
|
QStringList lst = (QStringList() << "N/A" << "N/A");
|
2023-11-07 09:12:17 +01:00
|
|
|
Update const *up = update();
|
|
|
|
if (up) {
|
|
|
|
hwinf const *caPlugin = up->hw();
|
|
|
|
if (caPlugin) {
|
|
|
|
caPlugin->dc_autoRequest(true); // turn auto-request setting on
|
|
|
|
|
|
|
|
QByteArray const cmp(8, char(0));
|
|
|
|
QByteArray hw(""), sw("");
|
|
|
|
for (int i=0; i<5; ++i) {
|
|
|
|
hw = caPlugin->dc_getHWversion().toUtf8();
|
|
|
|
sw = caPlugin->dc_getSWversion().toUtf8();
|
|
|
|
if (!hw.startsWith(cmp)) {
|
|
|
|
lst.clear();
|
|
|
|
qInfo() << hw << sw;
|
|
|
|
lst << hw << sw;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QThread::sleep(1);
|
2023-07-19 16:42:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 Worker::getFileSize(QString const &fileName) const {
|
|
|
|
// fileName has to be an absolute path
|
|
|
|
QFileInfo fInfo(fileName);
|
|
|
|
return fInfo.exists() ? fInfo.size() : -1;
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
bool Worker::executeOpkgCommand(QString opkgCommand) {
|
2023-07-14 13:32:00 +02:00
|
|
|
Command c(opkgCommand);
|
|
|
|
if (c.execute(m_workingDirectory)) {
|
|
|
|
QString const r = c.getCommandResult();
|
2023-08-11 10:52:31 +02:00
|
|
|
Utils::printInfoMsg(QString("EXECUTE OPKG COMMAND %1 OK: %2")
|
2023-07-19 16:42:18 +02:00
|
|
|
.arg(opkgCommand)
|
|
|
|
.arg(c.getCommandResult()));
|
2023-08-02 15:50:04 +02:00
|
|
|
return true;
|
2023-07-17 16:43:05 +02:00
|
|
|
} else {
|
2023-08-11 10:52:31 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("EXECUTE OPKG COMMAND %1 FAILED")
|
|
|
|
.arg(opkgCommand));
|
2023-07-14 13:32:00 +02:00
|
|
|
}
|
2023-08-02 15:50:04 +02:00
|
|
|
return false;
|
2023-06-16 16:47:13 +02:00
|
|
|
}
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
PSAInstalled Worker::getPSAInstalled() {
|
|
|
|
QStringList const dcVersion = getDCVersion();
|
|
|
|
QString const deviceControllerVersionHW = dcVersion.first();
|
|
|
|
QString const deviceControllerVersionSW = dcVersion.last();
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
qInfo() << "CURRENT DC-HW-VERSION: " << deviceControllerVersionHW;
|
|
|
|
qInfo() << "CURRENT DC-SW-VERSION: " << deviceControllerVersionSW;
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
QString const deviceControllerGitBlob = "N/A";
|
|
|
|
QString const deviceControllerGitLastCommit = "N/A";
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
PSAInstalled psaInstalled;
|
|
|
|
QString printSysDir("/etc/psa_config");
|
|
|
|
QString tariffSysDir("/etc/psa_tariff");
|
2023-08-11 11:02:15 +02:00
|
|
|
QString tariffRepoDir("etc/psa_tariff");
|
2023-08-22 13:49:09 +02:00
|
|
|
QString opkgRepoDir("etc/psa_update");
|
|
|
|
QString const &absPathNameRepositoryOpkg = QDir::cleanPath(opkgRepoDir + QDir::separator() + "opkg_commands");
|
2023-08-02 15:50:04 +02:00
|
|
|
QString absPathName;
|
2023-08-11 11:02:15 +02:00
|
|
|
QString absPathNameRepository;
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2024-01-17 15:30:34 +01:00
|
|
|
psaInstalled.versionInfo.lastCommit = "N/A";
|
|
|
|
psaInstalled.versionInfo.reason = "N/A";
|
|
|
|
psaInstalled.versionInfo.created = "N/A";
|
|
|
|
|
|
|
|
if (m_versionInfo.size() == 3) {
|
2024-04-29 15:00:52 +02:00
|
|
|
QString const &lastCommit = m_versionInfo.at(0);
|
|
|
|
QString reason = m_versionInfo.at(1);
|
|
|
|
QDateTime const dt = QDateTime::fromString(m_versionInfo.at(2), Qt::ISODate);
|
|
|
|
QString version{""};
|
|
|
|
QString date{""};
|
|
|
|
if (dt.isValid()) {
|
|
|
|
date += " ";
|
|
|
|
date += dt.date().toString(Qt::ISODate);
|
|
|
|
}
|
|
|
|
static const QRegularExpression re("^\\s*(\\d+)\\.(\\d+)\\.(\\d+)(.*$)");
|
|
|
|
QRegularExpressionMatch match = re.match(reason);
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
int const lastCapturedIndex = match.lastCapturedIndex();
|
|
|
|
if (lastCapturedIndex >= 1) {
|
|
|
|
version += " v";
|
|
|
|
version += match.captured(1); // major
|
|
|
|
}
|
|
|
|
if (lastCapturedIndex >= 2) {
|
|
|
|
version += ".";
|
|
|
|
version += match.captured(2); // minor
|
|
|
|
}
|
|
|
|
if (lastCapturedIndex >= 3) {
|
|
|
|
version += ".";
|
|
|
|
version += match.captured(3); // patch
|
|
|
|
}
|
|
|
|
if (lastCapturedIndex >= 4) { // rest after version
|
|
|
|
reason = match.captured(4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
psaInstalled.versionInfo.lastCommit = QString("%1%2").arg(lastCommit).arg(version);
|
|
|
|
psaInstalled.versionInfo.reason = reason;
|
2024-01-17 15:30:34 +01:00
|
|
|
psaInstalled.versionInfo.created = m_versionInfo.at(2);
|
2023-08-16 10:38:36 +02:00
|
|
|
}
|
|
|
|
|
2024-04-29 15:00:52 +02:00
|
|
|
//qCritical() << "";
|
|
|
|
//qCritical() << "VERSION-INFO";
|
|
|
|
//qCritical() << "LAST-COMMIT" << psaInstalled.versionInfo.lastCommit;
|
|
|
|
//qCritical() << "REASON" << psaInstalled.versionInfo.reason;
|
|
|
|
//qCritical() << "CREATED" << psaInstalled.versionInfo.created;
|
|
|
|
//qCritical() << "";
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
if (m_zoneNr != 0) {
|
|
|
|
QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0');
|
|
|
|
psaInstalled.tariff.name = QString("tariff%1.json").arg(n);
|
|
|
|
absPathName = QDir::cleanPath(tariffSysDir + QDir::separator() + psaInstalled.tariff.name);
|
|
|
|
psaInstalled.tariff.blob = m_gc.gitBlob(absPathName);
|
2023-08-11 11:02:15 +02:00
|
|
|
absPathNameRepository = QDir::cleanPath(tariffRepoDir + QDir::separator() + psaInstalled.tariff.name);
|
|
|
|
psaInstalled.tariff.lastCommit = m_gc.gitLastCommit(absPathNameRepository);
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.tariff.size = getFileSize(absPathName);
|
|
|
|
psaInstalled.tariff.zone = m_zoneNr;
|
2023-08-11 11:02:15 +02:00
|
|
|
psaInstalled.tariff.loadTime = Utils::getTariffLoadTime(absPathName);
|
2024-01-17 15:30:34 +01:00
|
|
|
psaInstalled.tariff.project = Utils::getLocation(absPathName);
|
|
|
|
psaInstalled.tariff.version = Utils::getTariffVersion(absPathName);
|
|
|
|
psaInstalled.tariff.info = Utils::getTariffInfo(absPathName);
|
2023-07-11 16:58:49 +02:00
|
|
|
}
|
|
|
|
|
2023-10-09 15:54:58 +02:00
|
|
|
psaInstalled.hw.linuxVersion = getOsVersion();
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.hw.cpuSerial = m_cpuSerial;
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-10-06 10:42:35 +02:00
|
|
|
psaInstalled.opkg.blob = m_gc.gitBlob(absPathNameRepositoryOpkg);
|
2023-10-19 13:43:53 +02:00
|
|
|
// psaInstalled.opkg.size = getFileSize(absPathNameRepositoryOpkg);
|
|
|
|
// psaInstalled.opkg.loadTime = Utils::getTariffLoadTime(absPathNameRepositoryOpkg);
|
2023-08-22 13:49:09 +02:00
|
|
|
psaInstalled.opkg.lastCommit = m_gc.gitLastCommit(absPathNameRepositoryOpkg);
|
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.dc.versionHW = deviceControllerVersionHW;
|
|
|
|
psaInstalled.dc.versionSW = deviceControllerVersionSW;
|
|
|
|
psaInstalled.dc.gitBlob = "N/A";
|
|
|
|
psaInstalled.dc.gitLastCommit = "N/A";
|
|
|
|
psaInstalled.dc.size = -1;
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-10-30 15:28:25 +01:00
|
|
|
psaInstalled.sw.apismVersion = getAPISMYoctoVersion();
|
2023-10-12 12:07:38 +02:00
|
|
|
psaInstalled.sw.atbQTVersion = getATBQTVersion();
|
|
|
|
psaInstalled.sw.atbUpdateToolVersion = m_atbUpdateToolVersion;
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.pluginVersion.deviceController = m_pluginVersionATBDeciceController;
|
|
|
|
psaInstalled.pluginVersion.ingenicoISelfCC = m_pluginVersionIngenicoISelf;
|
|
|
|
psaInstalled.pluginVersion.mobilisisCalculatePrice = m_pluginVersionMobilisisCalc;
|
|
|
|
psaInstalled.pluginVersion.mobilisisCalculatePriceConfigUi = m_pluginVersionMobilisisCalcConfig;
|
|
|
|
psaInstalled.pluginVersion.prmCalculatePrice = m_pluginVersionPrmCalc;
|
|
|
|
psaInstalled.pluginVersion.prmCalculatePriceConfigUi = m_pluginVersionPrmCalcConfig;
|
|
|
|
psaInstalled.pluginVersion.tcpZVT = m_pluginVersionTcpZvt;
|
2023-07-14 13:32:00 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.cash.name = "DC2C_cash.json";
|
|
|
|
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.cash.name);
|
|
|
|
psaInstalled.cash.blob = m_gc.gitBlob(absPathName);
|
|
|
|
psaInstalled.cash.size = getFileSize(absPathName);
|
2023-07-14 13:32:00 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.conf.name = "DC2C_conf.json";
|
|
|
|
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.conf.name);
|
|
|
|
psaInstalled.conf.blob = m_gc.gitBlob(absPathName);
|
|
|
|
psaInstalled.conf.size = getFileSize(absPathName);
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
psaInstalled.device.name = "DC2C_device.json";
|
|
|
|
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.device.name);
|
|
|
|
psaInstalled.device.blob = m_gc.gitBlob(absPathName);
|
|
|
|
psaInstalled.device.size = getFileSize(absPathName);
|
2023-07-19 16:42:18 +02:00
|
|
|
|
2023-08-02 15:50:04 +02:00
|
|
|
for (int i=0; i < 32; ++i) {
|
|
|
|
QString const &n = QString("%1").arg(i+1).rightJustified(2, '0');
|
|
|
|
psaInstalled.print[i].name = QString("DC2C_print%1.json").arg(n);
|
|
|
|
absPathName = QDir::cleanPath(printSysDir + QDir::separator() + psaInstalled.print[i].name);
|
|
|
|
psaInstalled.print[i].blob = m_gc.gitBlob(absPathName);
|
|
|
|
psaInstalled.print[i].size = getFileSize(absPathName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return psaInstalled;
|
2023-07-11 16:58:49 +02:00
|
|
|
}
|