Compare commits
14 Commits
70d0ffb38d
...
e95f034538
Author | SHA1 | Date | |
---|---|---|---|
e95f034538 | |||
72fbd9089a | |||
3bdc117c01 | |||
12eafc2878 | |||
9abe718010 | |||
3b6f22e93b | |||
34cc077937 | |||
ba1b2263d2 | |||
1f99618ba5 | |||
df4e384d9d | |||
ede8a9519f | |||
903977bdd1 | |||
775e9b7b8a | |||
a8fdd29666 |
@@ -77,7 +77,7 @@ contains( CONFIG, DesktopLinux ) {
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
../common/src/message_handler.cpp \
|
||||
../UpdatePTUDevCtrl/commandline_parser.cpp \
|
||||
../common/src/commandline_parser.cpp \
|
||||
update.cpp \
|
||||
../common/src/System.cpp \
|
||||
../common/src/utils_internal.cpp \
|
||||
@@ -86,7 +86,7 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
../common/include/message_handler.h \
|
||||
../UpdatePTUDevCtrl/commandline_parser.h \
|
||||
../common/src/commandline_parser.h \
|
||||
update.h \
|
||||
../common/include/System.h \
|
||||
../common/include/utils_internal.h \
|
||||
|
@@ -79,13 +79,13 @@ contains( CONFIG, DesktopLinux ) {
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
../UpdatePTUDevCtrl/message_handler.cpp \
|
||||
../UpdatePTUDevCtrl/commandline_parser.cpp \
|
||||
../common/src/commandline_parser.cpp \
|
||||
update.cpp \
|
||||
../common/src/System.cpp
|
||||
|
||||
HEADERS += \
|
||||
../UpdatePTUDevCtrl/message_handler.h \
|
||||
../UpdatePTUDevCtrl/commandline_parser.h \
|
||||
../common/include/commandline_parser.h \
|
||||
update.h \
|
||||
../common/include/System.h
|
||||
|
||||
|
@@ -16,11 +16,12 @@ GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
|
||||
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
|
||||
|
||||
|
||||
INCLUDEPATH += \
|
||||
plugins \
|
||||
$${INCLUDEINTERFACES} \
|
||||
INCLUDEPATH += plugins \
|
||||
$${INCLUDEINTERFACES}/ \
|
||||
$${_PRO_FILE_PWD_}/../common/ \
|
||||
$${_PRO_FILE_PWD_}/../common/include
|
||||
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
|
||||
@@ -67,12 +68,14 @@ SOURCES += \
|
||||
message_handler.cpp \
|
||||
../common/src/utils_internal.cpp \
|
||||
../common/src/command.cpp \
|
||||
../common/src/commandline_parser.cpp \
|
||||
git_command.cpp
|
||||
|
||||
HEADERS += \
|
||||
message_handler.h \
|
||||
../common/include/utils_internal.h \
|
||||
../common/include/command.h \
|
||||
../common/include/commandline_parser.h \
|
||||
git_command.h
|
||||
|
||||
##########################################################################################
|
||||
|
@@ -64,11 +64,13 @@ bool GitCommand::exec(QStringList const &options, int start_timeout, int finish_
|
||||
}
|
||||
|
||||
bool GitCommand::check(int start_timeout, int finish_timeout) {
|
||||
m_workingDirectory = customerRepoDir();
|
||||
QStringList const lst{"fsck"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
||||
bool GitCommand::checkout(int start_timeout, int finish_timeout) {
|
||||
m_workingDirectory = customerRepoDir();
|
||||
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||
if (zoneNr != -1) {
|
||||
QStringList const lst{"checkout", QString("zg1/zone%1").arg(zoneNr)};
|
||||
@@ -91,11 +93,13 @@ bool GitCommand::clone(int start_timeout, int finish_timeout) {
|
||||
}
|
||||
|
||||
bool GitCommand::pull(int start_timeout, int finish_timeout) {
|
||||
m_workingDirectory = customerRepoDir();
|
||||
QStringList const lst{"pull"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
||||
bool GitCommand::status(int start_timeout, int finish_timeout) {
|
||||
m_workingDirectory = customerRepoDir();
|
||||
QStringList const lst{"status"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
61
Git/main.cpp
61
Git/main.cpp
@@ -8,6 +8,7 @@
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@@ -22,6 +23,7 @@
|
||||
#include "message_handler.h"
|
||||
#include "utils_internal.h"
|
||||
#include "git_command.h"
|
||||
#include "commandline_parser.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QByteArray const value = qgetenv("LC_ALL");
|
||||
@@ -41,7 +43,7 @@ int main(int argc, char **argv) {
|
||||
setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
QCommandLineParser parser;
|
||||
CommandLineParser parser;
|
||||
parser.setApplicationDescription("git-commands for the update-system");
|
||||
|
||||
QCommandLineOption const checkCustomerRepositoryOption{"check"};
|
||||
@@ -56,6 +58,54 @@ int main(int argc, char **argv) {
|
||||
|
||||
QCommandLineOption verboseOption{parser.addVersionOption()};
|
||||
parser.process(a);
|
||||
parser.readSettings();
|
||||
|
||||
#if 0
|
||||
// note: also used in initEnv().
|
||||
|
||||
QString repositoryUrl = parser.repositoryUrl();
|
||||
|
||||
if (repositoryUrl.endsWith('/')) {
|
||||
repositoryUrl.chop(1);
|
||||
}
|
||||
|
||||
if (!repositoryUrl.isEmpty()) {
|
||||
qInfo() << "customer repository url" << repositoryUrl;
|
||||
} else {
|
||||
qCritical() << "ERROR customer repository url empty. git commands might fail.";
|
||||
}
|
||||
|
||||
if (repositoryUrl.contains("ptu-config.atb-comm.de")) {
|
||||
QString gitSSHCommand("");
|
||||
QByteArray const v = qgetenv("GIT_SSH_COMMAND");
|
||||
if (v.isEmpty()) {
|
||||
QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig");
|
||||
if (QFileInfo(sshKeyFile).exists()) {
|
||||
if (qgetenv("GIT_SSH_COMMAND").isNull()) {
|
||||
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
|
||||
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
|
||||
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting...";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
gitSSHCommand = QString(v.toStdString().c_str());
|
||||
qInfo() << "GIT_SSH_COMMAND already set in enviroment:" << gitSSHCommand;
|
||||
if (gitSSHCommand != "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig") {
|
||||
qCritical() << "ERROR" << gitSSHCommand << "wrong. Exiting...";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gitSSHCommand.isEmpty()) {
|
||||
qInfo() << "GIT_SSH_COMMAND .........." << gitSSHCommand;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser.isSet(verboseOption)) {
|
||||
parser.showVersion();
|
||||
@@ -108,12 +158,13 @@ int main(int argc, char **argv) {
|
||||
if (!gitCmd.clone()) {
|
||||
return -3;
|
||||
}
|
||||
if (!gitCmd.checkout()) {
|
||||
return -2;
|
||||
}
|
||||
qCritical() << internal::GIT_CUSTOMER_REPO_CLONED;
|
||||
return internal::GIT_CLONED_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
//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");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -294,9 +294,9 @@ SOURCES += \
|
||||
process/show_software_status_command.cpp \
|
||||
message_handler.cpp \
|
||||
worker.cpp \
|
||||
commandline_parser.cpp \
|
||||
work_process_list.cpp \
|
||||
$${_PRO_FILE_PWD_}/../common/src/utils_internal.cpp \
|
||||
$${_PRO_FILE_PWD_}/../common/src/commandline_parser.cpp \
|
||||
$${_PRO_FILE_PWD_}/../common/ismas/ApismClient.cpp \
|
||||
$${_PRO_FILE_PWD_}/../common/ismas/ApismTcpClient.cpp \
|
||||
$${_PRO_FILE_PWD_}/../common/ismas/ApismClientForUpdate.cpp
|
||||
@@ -323,9 +323,9 @@ HEADERS += \
|
||||
process/show_software_status_command.h \
|
||||
message_handler.h \
|
||||
worker.h \
|
||||
commandline_parser.h \
|
||||
work_process_list.h \
|
||||
$${_PRO_FILE_PWD_}/../common/include/utils_internal.h \
|
||||
$${_PRO_FILE_PWD_}/../common/include/commandline_parser.h \
|
||||
$${_PRO_FILE_PWD_}/../common/include/log_line_entry.h \
|
||||
$${_PRO_FILE_PWD_}/../common/ismas/ApismClient.h \
|
||||
$${_PRO_FILE_PWD_}/../common/ismas/ApismTcpClient.h \
|
||||
|
1107
UpdatePTUDevCtrl/ismas/ismas_client.cpp.master
Normal file
1107
UpdatePTUDevCtrl/ismas/ismas_client.cpp.master
Normal file
File diff suppressed because it is too large
Load Diff
@@ -49,6 +49,28 @@
|
||||
#define SERIAL_PORT "ttyUSB0"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @mainpage ATBUpdateTool Documentation
|
||||
* @section intro_sec Introduction
|
||||
* TODO.
|
||||
* @section atbupdate_tool ATBUpdateTool
|
||||
* TODO.
|
||||
* @section atbupdate_check ATBUpdateCheck
|
||||
* TODO
|
||||
* @section atbupdate_git ATBUpdateGit
|
||||
* TODO
|
||||
* @section atbupdate_sync ATBUpdateSync
|
||||
* TODO
|
||||
* @section atbupdate_opkg ATBUpdateOpkg
|
||||
* TODO
|
||||
* @section atbupdate_dc ATBUpdateDC
|
||||
* TODO
|
||||
* @section atbupdate_json_files ATBUpdateJsonFiles
|
||||
* TODO
|
||||
* @section atbupdate_show ATBUpdateShow
|
||||
* TODO
|
||||
*/
|
||||
|
||||
// argv[1]: file to send to dc
|
||||
int main(int argc, char *argv[]) {
|
||||
QByteArray const value = qgetenv("LC_ALL");
|
||||
|
@@ -49,6 +49,9 @@ void CheckAndFetchCustomerRepositoryCommand::readyReadStandardOutput() {
|
||||
} else
|
||||
if (m_commandResult.contains(internal::GIT_CUSTOMER_REPO_UPDATED)) {
|
||||
//emit w->showCustRepoStatus(internal::GIT_CUSTOMER_REPO_UPDATED);
|
||||
} else
|
||||
if (m_commandResult.contains(internal::GIT_CUSTOMER_REPO_CLONED)) {
|
||||
//emit w->showCustRepoStatus(internal::GIT_CUSTOMER_REPO_CLONED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -429,11 +429,11 @@ void Worker::stopProgressLoop() {
|
||||
displayProgressInMainWindow(MainWindow::STOP_PROGRESS_LOOP);
|
||||
}
|
||||
|
||||
static std::once_flag once;
|
||||
void Worker::run() {
|
||||
//static std::once_flag once;
|
||||
//void Worker::run() {
|
||||
// user should not start the update process several times
|
||||
std::call_once(once, &Worker::privateUpdate, this);
|
||||
}
|
||||
// std::call_once(once, &Worker::privateUpdate, this);
|
||||
//}
|
||||
|
||||
bool Worker::isRepositoryCorrupted() {
|
||||
QDir customerRepository(m_customerRepository);
|
||||
@@ -480,6 +480,7 @@ bool Worker::repairCorruptedRepository() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void Worker::privateUpdate() {
|
||||
if (!m_mainWindow) {
|
||||
Utils::printCriticalErrorMsg("m_mainWindow NOT SET");
|
||||
@@ -757,6 +758,7 @@ void Worker::privateUpdate() {
|
||||
// final messages: see destructor of UpdateProcessRunning subclass
|
||||
m_lastFailedUpdateStep = UPDATE_STEP::NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Worker::updateTriggerSet() {
|
||||
// repository is existent and not corrupted. check now if the ISMAS-trigger
|
||||
|
@@ -143,7 +143,21 @@ class Command;
|
||||
class Update;
|
||||
class MainWindow;
|
||||
class hwinf;
|
||||
class Worker : public QThread{
|
||||
|
||||
/*!
|
||||
\class Worker
|
||||
\brief The worker class ties together the parts the update tool consists of:
|
||||
* ATBUpdateTool
|
||||
* ATBUpdateCheck
|
||||
* ATBUpdateGit
|
||||
* ATBUpdateSync
|
||||
* ATBUpdateOpkg
|
||||
* ATBUpdateDC
|
||||
* ATBUpdateJsonFiles
|
||||
* ATBUpdateShow
|
||||
*
|
||||
*/
|
||||
class Worker : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
int const m_customerNr;
|
||||
@@ -438,6 +452,29 @@ public:
|
||||
static const QString UPDATE_STEP_WRONG;
|
||||
static const QString UPDATE_STEP_SUCCESS;
|
||||
|
||||
/**
|
||||
* Create a new Worker object to be used as the controlling instance of the
|
||||
* update process.
|
||||
*
|
||||
* @brief Constructor
|
||||
* @param customerNr
|
||||
* @param machineNr
|
||||
* @param zoneNr
|
||||
* @param repositoryUrl
|
||||
* @param branchName
|
||||
* @param pluginDir
|
||||
* @param pluginName
|
||||
* @param workingDir
|
||||
* @param noUpdatePsaHardware
|
||||
* @param alwaysDownloadConfig
|
||||
* @param alwaysDownloadDC
|
||||
* @param dryRun
|
||||
* @param parent
|
||||
* @param serialInterface
|
||||
* @param baudrate
|
||||
*
|
||||
* @todo einige parameter werden wohl ueberfluessig
|
||||
*/
|
||||
explicit Worker(int customerNr, // 281
|
||||
int machineNr,
|
||||
int zoneNr,
|
||||
@@ -1650,8 +1687,12 @@ private:
|
||||
smap[UPDATE_STEP::UPDATE_FINALIZE],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
// send ACTIVATE message 3x -> reorder should be impossible now
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
QThread::msleep(1000);
|
||||
}
|
||||
} break;
|
||||
case UPDATE_STEP::UPDATE_NOT_NECESSARY: {
|
||||
ismasClient.setProgressInPercent(_UPDATE_NOT_NECESSARY + _UPDATE_NOT_NECESSARY_CORRECTION);
|
||||
|
@@ -56,6 +56,9 @@ public:
|
||||
QCommandLineParser &parser() { return m_parser; }
|
||||
QCommandLineParser const &parser() const { return m_parser; }
|
||||
void process(const QCoreApplication &app) { m_parser.process(app); }
|
||||
bool isSet(QCommandLineOption const &o) { return m_parser.isSet(o); }
|
||||
bool isSet(QString const& s) {return m_parser.isSet(s); }
|
||||
bool addOption(QCommandLineOption const &o) { return m_parser.addOption(o); }
|
||||
QString const &iniFileName() const { return m_iniFileName; }
|
||||
void readSettings();
|
||||
QString repositoryUrl();
|
@@ -35,6 +35,7 @@ namespace internal {
|
||||
static constexpr const int GIT_PULL_ERROR_CODE{-4};
|
||||
static constexpr const int GIT_NOT_NECESSARY_CODE{1};
|
||||
static constexpr const int GIT_UPDATED_CODE{2};
|
||||
static constexpr const int GIT_CLONED_CODE{3};
|
||||
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_CHECKOUT_ERROR{"checkout error"};
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_PULL_ERROR{"pull error"};
|
||||
@@ -42,6 +43,7 @@ namespace internal {
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_NO_UPDATE_NECESSARY{"no repository update necessary"};
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_NOT_NECESSARY{"not necessary"};
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_UPDATED{"repository updated"};
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_CLONED{"repository cloned"};
|
||||
static constexpr const char *GIT_UPDATED{"updated"};
|
||||
|
||||
static constexpr const char *EXEC_OPKG_COMMANDS_SUCCESS{"success"};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include <QFile>
|
||||
|
||||
CommandLineParser::CommandLineParser()
|
||||
: m_repositoryUrl("https://git.mimbach49.de/GerhardHoffmann")
|
||||
: m_repositoryUrl("gitea@ptu-config.atb-comm.de:ATB")
|
||||
, m_plugInDir("/usr/lib/")
|
||||
, m_plugInName("libCAslave.so")
|
||||
, m_workingDir("/opt/app/tools/atbupdate/")
|
19
misc/atbupdatetool.service
Normal file
19
misc/atbupdatetool.service
Normal file
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=ATB update tool
|
||||
|
||||
[Service]
|
||||
Environment=XDG_RUNTIME_DIR=/var/run/user/0
|
||||
# get START_DATE of service. Use '-' to ensure that file exists
|
||||
EnvironmentFile=-/tmp/start_date.env
|
||||
# EnvironmentFile=-/tmp/stop_date.env
|
||||
ExecStartPre=/bin/bash -c 'printf "%%s\n" START_DATE=$(date +"%%Y-%%m-%%d%%H:%%M:%%S") > /tmp/start_date.env'
|
||||
|
||||
ExecStart=/opt/app/tools/atbupdate/ATBUpdateTool --platform wayland
|
||||
|
||||
ExecStartPre=dbus-send --system --type=method_call --dest='eu.atb.ptu.systemcontrol' '/systemcontrol' eu.atb.ptu.systemcontrol.startBackgroundTask string:UPDATE_TOOL
|
||||
ExecStopPost=dbus-send --system --type=method_call --dest='eu.atb.ptu.systemcontrol' '/systemcontrol' eu.atb.ptu.systemcontrol.finishedBackgroundTask string:UPDATE_TOOL
|
||||
# execute script to check if update-tool contains errors not sent to ISMAS.
|
||||
# ExecStopPost=/bin/bash -c 'printf "%%s\n" STOP_DATE=$(date +"%%Y-%%m-%%d%%H:%%M:%%S") > /tmp/stop_date.env'
|
||||
ExecStopPost=/bin/bash -c '[ -f /opt/app/tools/atbupdate/on_update_failure.sh ] && /opt/app/tools/atbupdate/on_update_failure.sh ${START_DATE}'
|
||||
|
||||
#StandardOutput=????
|
Reference in New Issue
Block a user