2024-02-29 11:36:24 +01:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QByteArray>
|
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2024-02-29 11:36:24 +01:00
|
|
|
#include "message_handler.h"
|
2024-04-23 16:23:58 +02:00
|
|
|
#include "commandline_parser.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "update.h"
|
2024-05-14 12:33:40 +02:00
|
|
|
#include "System.h"
|
2024-04-23 16:23:58 +02:00
|
|
|
|
2024-03-19 09:28:37 +01:00
|
|
|
#include <DeviceController/interfaces.h>
|
2024-02-29 11:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
//#include <unistd.h>
|
|
|
|
//#include <errno.h>
|
|
|
|
|
|
|
|
#ifdef PTU5
|
|
|
|
#define SERIAL_PORT "ttymxc2"
|
|
|
|
#else
|
|
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
|
|
#endif
|
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
int read1stLineOfFile(QString fileName) {
|
|
|
|
QFile f(fileName);
|
|
|
|
if (f.exists()) {
|
|
|
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
QTextStream in(&f);
|
|
|
|
in.setCodec("UTF-8");
|
|
|
|
while(!in.atEnd()) {
|
|
|
|
return in.readLine().toInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-02-29 11:36:24 +01:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
QByteArray const value = qgetenv("LC_ALL");
|
|
|
|
if (value != "C") {
|
|
|
|
qputenv("LC_ALL", "C");
|
|
|
|
}
|
|
|
|
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
|
|
|
|
|
|
|
openlog("ATB-DL-JSON", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
|
|
|
|
|
|
|
QCoreApplication a(argc, argv);
|
|
|
|
QCoreApplication::setApplicationName("ATBDownloadDCJsonFiles");
|
|
|
|
QCoreApplication::setApplicationVersion(APP_VERSION);
|
|
|
|
|
|
|
|
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
|
|
|
atbInstallMessageHandler(atbDebugOutput);
|
|
|
|
setDebugLevel(LOG_NOTICE);
|
|
|
|
}
|
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
CommandLineParser parser;
|
|
|
|
parser.process(a);
|
|
|
|
parser.readSettings();
|
|
|
|
|
|
|
|
QString repositoryUrl = parser.repositoryUrl();
|
|
|
|
QString plugInDir = parser.plugInDir();
|
|
|
|
QString plugInName = parser.plugInName();
|
|
|
|
QString workingDir = parser.workingDir();
|
2024-05-14 12:33:40 +02:00
|
|
|
QString psaConfigDir = parser.psaConfigDir();
|
|
|
|
QString psaTariffDir = parser.psaTariffDir();
|
2024-04-23 16:23:58 +02:00
|
|
|
QString iniFileName = parser.iniFileName();
|
|
|
|
bool const dryRun = parser.dryRun();
|
|
|
|
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
|
|
|
|
bool const showYoctoVersion = parser.yoctoVersion();
|
|
|
|
bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
|
|
|
|
bool const showExtendedVersion = parser.extendedVersion();
|
|
|
|
bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
|
|
|
|
bool const alwaysDownloadDC = parser.alwaysDownloadDC();
|
|
|
|
|
|
|
|
QString const rtPath = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
|
|
int const machineNr = read1stLineOfFile("/mnt/system_data/machine_nr");
|
|
|
|
int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
|
|
|
|
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
|
|
|
QString const branchName = (zoneNr != 0)
|
|
|
|
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
qInfo() << "pwd ......................" << rtPath;
|
|
|
|
qInfo() << "repositoryUrl ............" << repositoryUrl;
|
|
|
|
qInfo() << "plugInDir ................" << plugInDir;
|
|
|
|
qInfo() << "plugInName ..............." << plugInName;
|
|
|
|
qInfo() << "workingDir ..............." << workingDir;
|
2024-05-14 12:33:40 +02:00
|
|
|
qInfo() << "psaConfigDir ............." << psaConfigDir;
|
|
|
|
qInfo() << "psaTariffDir ............." << psaTariffDir;
|
2024-04-23 16:23:58 +02:00
|
|
|
qInfo() << "dryRun ..................." << dryRun;
|
|
|
|
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
|
|
|
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
|
|
|
|
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
|
|
|
|
qInfo() << "showYoctoVersion ........." << showYoctoVersion;
|
|
|
|
qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
|
|
|
|
qInfo() << "showExtendedVersion ......" << showExtendedVersion;
|
|
|
|
qInfo() << "iniFileName .............." << iniFileName;
|
|
|
|
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
|
|
|
qInfo() << "machineNr ................" << machineNr;
|
|
|
|
qInfo() << "customerNr ..............." << customerNr;
|
|
|
|
qInfo() << "zoneNr ..................." << zoneNr;
|
|
|
|
|
|
|
|
if (showExtendedVersion) {
|
|
|
|
printf(APP_EXTENDED_VERSION"\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-14 12:35:18 +02:00
|
|
|
QString const &customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
|
2024-04-23 16:23:58 +02:00
|
|
|
QStringList filesToUpdate;
|
|
|
|
|
2024-05-14 12:35:18 +02:00
|
|
|
// etc/psa_config: located under mount-path
|
|
|
|
std::optional<QString> mountPath = System::checkForUSBStick(psaConfigDir);
|
|
|
|
if (mountPath.has_value()) {
|
|
|
|
filesToUpdate = System::getJsonFilesOnUsbStick(mountPath.value());
|
|
|
|
} else {
|
|
|
|
qCritical() << "Using customer repository" << customerRepo;
|
|
|
|
|
|
|
|
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
|
|
|
|
if (dir.exists()) {
|
|
|
|
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
|
|
|
|
if (!jsons.isEmpty()) {
|
|
|
|
for (QStringList::size_type i=0; i<jsons.size(); ++i) {
|
|
|
|
filesToUpdate << QDir::cleanPath(QString("etc/psa_config/") + jsons.at(i));
|
|
|
|
}
|
2024-04-23 16:23:58 +02:00
|
|
|
}
|
2024-05-14 12:35:18 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
|
|
|
|
return -1;
|
2024-04-23 16:23:58 +02:00
|
|
|
}
|
|
|
|
}
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-05-14 12:35:18 +02:00
|
|
|
// qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
Update update(customerRepo,
|
|
|
|
QString::number(customerNr),
|
|
|
|
branchName,
|
|
|
|
plugInDir,
|
|
|
|
plugInName,
|
|
|
|
workingDir);
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-05-14 12:35:18 +02:00
|
|
|
update.doUpdate(filesToUpdate, mountPath.has_value());
|
|
|
|
update.checkJsonVersions();
|
|
|
|
//update.checkJsonVersions(filesToUpdate);
|
|
|
|
|
|
|
|
if (mountPath.has_value()) {
|
|
|
|
System::umountUSBStick();
|
|
|
|
}
|
2024-02-29 11:36:24 +01:00
|
|
|
|
2024-04-23 16:23:58 +02:00
|
|
|
return 0;
|
2024-02-29 11:36:24 +01:00
|
|
|
}
|