Compare commits

...

3 Commits

6 changed files with 189 additions and 127 deletions

View File

@ -26,11 +26,69 @@ int main(int argc, char **argv) {
QCoreApplication::setApplicationName("ATBUpdateSync");
QCoreApplication::setApplicationVersion(APP_VERSION);
QDebug debug = qCritical();
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(nullptr);
//atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(LOG_NOTICE);
}
return 0;
if (internal::customerRepoExists() == false) {
qCritical().noquote() << internal::NO_CUSTOMER_REPOSITORY;
return internal::NO_CUSTOMER_REPOSITORY_CODE;
}
QString const crd = internal::customerRepoDir();
QString const etcInRepo = QDir::cleanPath(crd + QDir::separator() + "etc/");
QString const optInRepo = QDir::cleanPath(crd + QDir::separator() + "opt/");
if (!QDir(etcInRepo).exists()) {
qCritical().noquote() << internal::NO_ETC_CUSTOMER_REPOSITORY;
return internal::NO_ETC_CUSTOMER_REPOSITORY_CODE;
}
if (!QDir(optInRepo).exists()) {
qCritical().noquote() << internal::NO_OPT_CUSTOMER_REPOSITORY;
return internal::NO_OPT_CUSTOMER_REPOSITORY_CODE;
}
#if 0
error codes for rsync:
https://stackoverflow.com/questions/20737204/comprehensive-list-of-rsync-error-codes
0 Success
1 Syntax or usage error
2 Protocol incompatibility
3 Errors selecting input/output files, dirs
4 Requested action not supported: an attempt was made to manipulate 64-bit
files on a platform that cannot support them; or an option was specified
that is supported by the client and not by the server.
5 Error starting client-server protocol
6 Daemon unable to append to log-file
10 Error in socket I/O
11 Error in file I/O
12 Error in rsync protocol data stream
13 Errors with program diagnostics
14 Error in IPC code
20 Received SIGUSR1 or SIGINT
21 Some error returned by waitpid()
22 Error allocating core memory buffers
23 Partial transfer due to error
24 Partial transfer due to vanished source files
25 The --max-delete limit stopped deletions
30 Timeout in data send/receive
35 Timeout waiting for daemon connection
#endif
QStringList options({"-v", "--recursive", "--progress", "--checksum",
"--exclude=.*", "--include=*.bin", "--include=*.json",
"--include=*.ini"});
int ret = SyncCommand().exec("rsync", options << etcInRepo << "/etc");
if (ret == 0) {
ret = SyncCommand().exec("rsync", options << optInRepo << "/opt");
}
return ret;
}

View File

@ -12,7 +12,10 @@ using namespace internal;
SyncCommand::SyncCommand() {
}
bool SyncCommand::exec(QString const &cmd, QStringList const &options,
int SyncCommand::exec(QString const &cmd, QStringList const &options,
int start_timeout, int finish_timeout) {
return false;
Command c(cmd, options, internal::customerRepoDir(),
start_timeout, finish_timeout);
c.exec();
return c.exitCode();
}

View File

@ -7,7 +7,7 @@ class SyncCommand {
public:
SyncCommand();
bool exec(QString const &cmd, QStringList const &options,
int exec(QString const &cmd, QStringList const &options,
int start_timeout = 100000, int finish_timeout = 100000);
};

View File

@ -16,6 +16,15 @@
#include <QColor>
#include <QColorDialog>
#define CHECK_BACKEND_CONNECTION 0
#define CHECK_UPDATE_REQUEST 1
#define UPDATE_CUSTOMER_REPOSITORY 2
#define INSTALL_SW_PACKETS_DRY_RUN 3
#define INSTALL_SW_PACKETS 4
#define INSTALL_DC_CONFIGURATION 5
#define SYNCHRONIZE_REPOSITORY 6
#define UPDATE_DC 7
MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent)
@ -27,6 +36,25 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
ui->setupUi(this);
m_updateSteps.resize(8);
m_updateSteps[CHECK_BACKEND_CONNECTION] = "Check backend connection (ISMAS) ";
m_updateSteps[CHECK_UPDATE_REQUEST] = "Check update request ";
m_updateSteps[UPDATE_CUSTOMER_REPOSITORY] = "Update customer repository ";
m_updateSteps[INSTALL_SW_PACKETS_DRY_RUN] = "Install SW packets (dry run) ";
m_updateSteps[INSTALL_SW_PACKETS] = "Install SW packets ";
m_updateSteps[INSTALL_DC_CONFIGURATION] = "Install DC configuration ";
m_updateSteps[SYNCHRONIZE_REPOSITORY] = "Synchronize repository/filesystem ";
m_updateSteps[UPDATE_DC] = "Update DC";
for (int i = 0; i < m_updateSteps.size(); ++i) {
QString &tmp = m_updateSteps[i];
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
ui->stepLabel->setText(tmp + "\n");
}
this->setStatusBar(new QStatusBar(this));
QFont f;
f.setStyleHint(QFont::Monospace);
@ -149,81 +177,68 @@ void MainWindow::onShowTariffUpdate(QString) {
}
void MainWindow::onShowISMASConnectivity(QString status) {
// ausgabe: connected, not connected, connecting
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
m_stepLabelChopCount = 0;
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
QString tmp("Check backend connection (ISMAS) ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[CHECK_BACKEND_CONNECTION].trimmed();
bool const custRepoExists = internal::customerRepoExists();
if (status.contains(UpdateCommand::ISMAS_CONNECTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += QString("%1 <font color='Green'>connected</font><br />").arg(tmp);
s += " <font color='Green'>connected</font>";
} else {
s += QString("%1 <font color='Green'>connected&nbsp;(initial configuration)</font><br />").arg(tmp);
s += " <font color='Green'>connected&nbsp;(initial configuration)</font>";
}
} else
if (status.contains(UpdateCommand::NO_CUSTOMER_REPOSITORY, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Blue'>NOT CONNECTED</font><br />").arg(tmp);
s += " <font color='Blue'>NOT CONNECTED</font>";
} else
if (status.contains(UpdateCommand::ISMAS_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>connecting</font><br />").arg(tmp);
s += " <font color='Green'>connecting</font>";
} else
if (status.contains(UpdateCommand::ISMAS_NOT_CONNECTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += QString( "%1 <font color='Red'>NOT CONNECTED. STOP</font><br />").arg(tmp);
s += " <font color='Red'>NOT CONNECTED. STOP</font>";
} else {
s += QString( "%1 <font color='Red'>not connected.&nbsp;(initial configuration)</font><br />").arg(tmp);
s += " <font color='Red'>not connected.&nbsp;(initial configuration)</font>";
}
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
m_stepLabelChopCount = -s.length();
s += "Check update request";
m_stepLabelChopCount += s.length();
m_updateSteps[CHECK_BACKEND_CONNECTION] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowCustRepoStatus(QString status) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp("Update customer repository ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[UPDATE_CUSTOMER_REPOSITORY].trimmed();
if (status.contains(internal::GIT_CUSTOMER_REPO_UP_TO_DATE, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>%2</font><br />").arg(tmp).arg(internal::GIT_CUSTOMER_REPO_UP_TO_DATE);
s += QString(" <font color='Green'>%1</font>").arg(internal::GIT_CUSTOMER_REPO_UP_TO_DATE);
} else
if (status.contains(internal::GIT_CUSTOMER_REPO_NOT_NECESSARY, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>%2</font><br />").arg(tmp).arg(internal::GIT_CUSTOMER_REPO_NOT_NECESSARY);
s += QString(" <font color='Green'>%1</font>").arg(internal::GIT_CUSTOMER_REPO_NOT_NECESSARY);
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
m_stepLabelChopCount = -s.length();
s += "Install SW packets (dry run)";
m_stepLabelChopCount += s.length();
m_updateSteps[UPDATE_CUSTOMER_REPOSITORY] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowExecOpkgStatus(QString status) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
return;
QString s = ui->stepLabel->text();
@ -245,6 +260,7 @@ void MainWindow::onShowExecOpkgStatus(QString status) {
void MainWindow::onShowExecOpkgCommand(QString cmd) {
qCritical() << __func__ << ":" << __LINE__ << "cmd" << cmd;
return;
if (cmd.back() != QChar('\n')) {
cmd += "\n";
@ -253,158 +269,132 @@ void MainWindow::onShowExecOpkgCommand(QString cmd) {
}
void MainWindow::onShowExecOpkgOverallResult(QString status, bool noaction) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
//qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp = noaction ? "Install SW packets (dry run) " : "Install SW packets ";
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = noaction ?
m_updateSteps[INSTALL_SW_PACKETS_DRY_RUN].trimmed() :
m_updateSteps[INSTALL_SW_PACKETS].trimmed();
if (status.contains(internal::EXEC_OPKG_COMMANDS_SUCCESS, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>success</font><br />").arg(tmp);
s += " <font color='Green'>success</font>";
} else
if (status.contains(internal::EXEC_OPKG_COMMANDS_FAIL, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Red'>%2</font><br />").arg(tmp).arg(internal::EXEC_OPKG_COMMANDS_FAIL);
s += QString(" <font color='Red'>%1</font>").arg(internal::EXEC_OPKG_COMMANDS_FAIL);
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
if (noaction) {
m_stepLabelChopCount = -s.length();
s += "Install SW packets";
m_stepLabelChopCount += s.length();
m_updateSteps[INSTALL_SW_PACKETS_DRY_RUN] = s;
} else {
m_stepLabelChopCount = -s.length();
s += "Install DC configuration";
m_stepLabelChopCount += s.length();
m_updateSteps[INSTALL_SW_PACKETS] = s;
}
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowDownloadDCJsonFilesStatus(QString status) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
//qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp = "Install DC configuration ";
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[INSTALL_DC_CONFIGURATION].trimmed();
if (status.contains(UpdateCommand::UPDATE_DC_JSON_FILES_SUCCESS, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>success</font><br />").arg(tmp);
s += " <font color='Green'>success</font>";
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
m_stepLabelChopCount = -s.length();
s += "Synchronize repository/filesystem";
m_stepLabelChopCount += s.length();
m_updateSteps[INSTALL_DC_CONFIGURATION] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowSyncCustRepoStatus(QString status) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
//qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp = "Synchronize repository/filesystem ";
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[SYNCHRONIZE_REPOSITORY].trimmed();
if (status.contains(UpdateCommand::SYNC_CUSTOMER_REPO_FILES_SUCCESS, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>success</font><br />").arg(tmp);
s += " <font color='Green'>success</font>";
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
m_stepLabelChopCount = -s.length();
s += "Update DC";
m_stepLabelChopCount += s.length();
m_updateSteps[SYNCHRONIZE_REPOSITORY] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowUpdateDCFirmware(QString status) {
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp = "Update DC ";
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[UPDATE_DC].trimmed();
if (status.contains(UpdateCommand::UPDATE_DC_FIRMARE_SUCCESS, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>success</font><br />").arg(tmp);
s += " <font color='Green'>success</font>";
} else {
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN STATUS</font>";
}
m_updateSteps[UPDATE_DC] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
if (i != UPDATE_DC) {
s += m_updateSteps[i] + "<br />";
} else {
s += m_updateSteps[i];
}
}
ui->stepLabel->setText(s);
}
void MainWindow::onShowUpdateRequest(QString status) {
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString s = ui->stepLabel->text();
s.chop(m_stepLabelChopCount);
QString tmp = "Check update request ";
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
QString s = m_updateSteps[CHECK_UPDATE_REQUEST].trimmed();
bool const custRepoExists = internal::customerRepoExists();
if (status.contains(UpdateCommand::UPDATE_NOT_REQUESTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += QString( "%1 <font color='Red'>NOT REQUESTED. STOP.</font><br />").arg(tmp);
s += " <font color='Red'>NOT REQUESTED. STOP.</font>";
} else {
s += QString("%1 <font color='Blue'>not requested&nbsp;(initial configuration)</font><br />").arg(tmp);
s += " <font color='Blue'>not requested&nbsp;(initial configuration)</font>";
}
} else
if (status.contains(UpdateCommand::UPDATE_REQUESTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += QString("%1 <font color='Green'>requested</font><br />").arg(tmp);
s += " <font color='Green'>requested</font>";
} else {
s += QString("%1 <font color='Blue'>requested&nbsp;(initial configuration)</font><br />").arg(tmp);
s += " <font color='Blue'>requested&nbsp;(initial configuration)</font>";
}
} else
if (status.contains(UpdateCommand::UPDATE_NOT_NECESSARY, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Green'>not necessary</font><br />").arg(tmp);
s += " <font color='Green'>not necessary</font>";
} else
if (status.contains(UpdateCommand::NO_CUSTOMER_REPOSITORY, Qt::CaseInsensitive)) {
s += QString("%1 <font color='Blue'>UNKNOWN (ISMAS not connected)</font><br />").arg(tmp);
s += " <font color='Blue'>UNKNOWN (ISMAS not connected)</font>";
} else {
s += QString( "%1 <font color='Red'>UNKNOWN</font><br />").arg(tmp);
s += " <font color='Red'>UNKNOWN</font>";
}
m_stepLabelChopCount = -s.length();
s += "Update customer repository";
m_stepLabelChopCount += s.length();
m_updateSteps[CHECK_UPDATE_REQUEST] = s;
s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
}
@ -412,6 +402,7 @@ void MainWindow::onShowISMASChecks(QString) {
// deprecated
QString s = ui->stepLabel->text();
return;
QString tmp("Check ISMAS connectivity ");
int len = m_showLineLength - tmp.length();

View File

@ -4,6 +4,8 @@
#include <QMainWindow>
#include <QTimer>
#include <QStatusBar>
#include <QVector>
#include <QString>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -97,5 +99,8 @@ private:
QTimer *m_statusTimer;
QString m_targetDcVersion;
int m_stepLabelChopCount{};
QVector<QString> m_updateSteps{};
};
#endif // MAINWINDOW_H

View File

@ -10,6 +10,11 @@ namespace internal {
static constexpr const char *UPDATE_REQUESTED{"requested"};
static constexpr const char *NO_CUSTOMER_REPOSITORY{"no customer repository"};
static constexpr const int NO_CUSTOMER_REPOSITORY_CODE{-8};
static constexpr const char *NO_ETC_CUSTOMER_REPOSITORY{"no etc/ in customer repository"};
static constexpr const int NO_ETC_CUSTOMER_REPOSITORY_CODE{-9};
static constexpr const char *NO_OPT_CUSTOMER_REPOSITORY{"no opt/ in customer repository"};
static constexpr const int NO_OPT_CUSTOMER_REPOSITORY_CODE{-10};
static constexpr const char *ISMAS_CONNECTED{"connected"};
static constexpr const char *ISMAS_DISCONNECTED{"disconnected"};