From 62655ebd41d50456afdaf7fa4b2dfdbb20e02fb5 Mon Sep 17 00:00:00 2001 From: q5sys Date: Thu, 2 Nov 2017 10:02:03 -0400 Subject: [PATCH 1/6] backend work for source control api --- src/server/DispatcherParsing.cpp | 27 +++++++++++++++++++++++ src/server/WebBackend.cpp | 38 +++++++++++++++++++++++++++++++- src/server/WebSocket.h | 2 ++ src/server/library/library.pri | 7 ++++-- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/server/DispatcherParsing.cpp b/src/server/DispatcherParsing.cpp index 6413385..77ef1ff 100644 --- a/src/server/DispatcherParsing.cpp +++ b/src/server/DispatcherParsing.cpp @@ -10,6 +10,8 @@ #include "EventWatcher.h" #include "Dispatcher.h" #include "library/sysadm-update.h" +#include "library/sysadm-sourcectl.h" + QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObject log, bool full_log){ //NOTE: full_log = true when the process has finished. If it is false, the process is still running and you are probably getting an incremental update of the process log @@ -79,8 +81,33 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec args.insert("impacts_pkgs",QJsonArray::fromStringList(effects)); } + // == sysadm/sourcecrl == + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::saveSourceLog(cLog); //save this for use later } + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::savePortsLog(cLog); //save this for use later +} +} + +//Now assemble the output as needed +if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event +args.insert("event_system",namesp+"/"+name); +return args; + //Now assemble the output as needed if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event args.insert("event_system",namesp+"/"+name); diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index b711768..4a616f5 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -25,6 +25,7 @@ #include "library/sysadm-firewall.h" #include "library/sysadm-moused.h" #include "library/sysadm-powerd.h" +#include "library/sysadm-sourcectl.h" #define DEBUG 0 //#define SCLISTDELIM QString("::::") //SysCache List Delimiter @@ -45,7 +46,6 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO out->insert("sysadm/beadm", "read/write"); } - // - dispatcher (Internal to server - always available) //"read" is the event notifications, "write" is the ability to queue up jobs out->insert("rpc/dispatcher", allaccess ? "read/write" : "read"); @@ -104,6 +104,10 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO if(QFile::exists("/usr/sbin/powerd")){ out->insert("sysadm/powerd", "read/write"); } + // - sourcectl + if(QFile::exists("/usr/local/bin/git")){ + out->insert("sysadm/sourcectl", "read/write"); + } return RestOutputStruct::OK; } @@ -164,6 +168,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru return EvaluateSysadmMousedRequest(IN.args, out); }else if(namesp=="sysadm" && name=="powerd"){ return EvaluateSysadmPowerdRequest(IN.args, out); + }else if(namesp=="sysadm" && name=="sourcectl"){ + return EvaluateSysadmSourceCTLRequest(IN.args, out); }else{ return RestOutputStruct::BADREQUEST; } @@ -1329,3 +1335,33 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPowerdRequest(const QJsonVal return RestOutputStruct::BADREQUEST; } } + +// ==== SYSADM SOURCECTL API ==== +RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out){ + QString action = in_args.toObject().value("action").toString(); + QJsonObject outobj; + if(action == "downloadports"){ + outobj = sysadm::sourcectl::downloadports(); + }else if(action == "updateports"){ + outobj = sysadm::sourcectl::updateports(); + }else if(action == "deleteports"){ + outobj = sysadm::sourcectl::deleteports(); + }else if(action == "stopports"){ + outobj = sysadm::sourcectl::stopports(); + }else if(action == "downloadsource"){ + outobj = sysadm::sourcectl::downloadsource(); + }else if(action == "updatesource"){ + outobj = sysadm::sourcectl::updatesource(); + }else if(action == "deletesource"){ + outobj = sysadm::sourcectl::deletesource(); + }else if(action == "stopsource"){ + outobj = sysadm::sourcectl::stopsource(); + //check return structure for validity + if(!outobj.keys().isEmpty()){ + out->insert(action, outobj); + return RestOutputStruct::OK; + }else{ + return RestOutputStruct::BADREQUEST; + } + } +} diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index e0f0673..128401e 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -100,6 +100,8 @@ private: RestOutputStruct::ExitCode EvaluateSysadmMousedRequest(const QJsonValue in_args, QJsonObject *out); // -- sysadm powerd API RestOutputStruct::ExitCode EvaluateSysadmPowerdRequest(const QJsonValue in_args, QJsonObject *out); + // -- sysadm sourcectl API + RestOutputStruct::ExitCode EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out); private slots: void sendReply(QString msg); diff --git a/src/server/library/library.pri b/src/server/library/library.pri index ef6042a..5a1d124 100644 --- a/src/server/library/library.pri +++ b/src/server/library/library.pri @@ -17,7 +17,9 @@ HEADERS += $${PWD}/sysadm-global.h \ $${PWD}/sysadm-zfs.h \ $${PWD}/sysadm-pkg.h \ $${PWD}/sysadm-moused.h \ - $${PWD}/sysadm-powerd.h + $${PWD}/sysadm-powerd.h \ + $${PWD}/sysadm-sourcectl.h + SOURCES += $${PWD}/NetDevice.cpp \ $${PWD}/sysadm-general.cpp \ @@ -35,4 +37,5 @@ SOURCES += $${PWD}/NetDevice.cpp \ $${PWD}/sysadm-zfs.cpp \ $${PWD}/sysadm-pkg.cpp \ $${PWD}/sysadm-moused.cpp \ - $${PWD}/sysadm-powerd.cpp + $${PWD}/sysadm-powerd.cpp \ + $${PWD}/sysadm-sourcectl.cpp From 355b47d93a77fb4de77d35dc88272bfcaa193638 Mon Sep 17 00:00:00 2001 From: q5sys Date: Thu, 2 Nov 2017 10:10:56 -0400 Subject: [PATCH 2/6] cut old source source from systemmanager.cpp --- src/server/library/sysadm-systemmanager.cpp | 63 --------------------- 1 file changed, 63 deletions(-) diff --git a/src/server/library/sysadm-systemmanager.cpp b/src/server/library/sysadm-systemmanager.cpp index c93077a..cdb6ffc 100644 --- a/src/server/library/sysadm-systemmanager.cpp +++ b/src/server/library/sysadm-systemmanager.cpp @@ -455,66 +455,3 @@ QJsonObject SysMgmt::systemDevices(){ return pciconf_info; } -// Source Management - -QJsonObject SysMgmt::fetchPortsTree(QString altDir){ -//void SysMgmt::fetchPortsTree(QStringList &cmds, QStringList &dirs){ - QJsonObject out; - if(altDir.isEmpty()){ altDir = "/usr/ports"; } - //Does Ports tree exist? If not create it. - if(!QFile::exists(altDir)){ - QDir dir; - if(!dir.mkpath(altDir) ){ - out.insert("error","Could not create directory: "+altDir); - return out; - } - } - //Does a local git repo exist? If not create it. - QString URL = "https://www.github.com/trueos/freebsd-ports.git"; - if(QFile::exists(altDir+"/.git")){ - //Check if the remote URL is correct - QString origin = General::gitCMD(altDir, "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified(); - if(origin != URL){ - General::gitCMD(altDir,"git",QStringList() << "remote" << "remove" << "origin"); - General::gitCMD(altDir,"git", QStringList() << "remote" << "add" << "origin" << URL); - } - }else{ - //new GIT setup - General::emptyDir(altDir); - General::gitCMD(altDir, "git", QStringList() << "init" << altDir ); - General::gitCMD(altDir, "git", QStringList() << "remote" << "add" << "origin" << URL ); - } - //Now update the tree with git - QString ID = "system_fetch_ports_tree"; - DISPATCHER->queueProcess(ID, "git pull origin", altDir ); - out.insert("result","process_started"); - out.insert("process_id",ID); - return out; -} - -/*void SysMgmt::fetchSourceTree(QString branch, QStringList &cmds, QStringList &dirs, QStringList &info){ - //Clear the output variables - cmds.clear(); dirs.clear(); - //Check if the source directory even exists - if(!QFile::exists("/usr/src")){ - cmds << "mkdir /usr/src"; dirs << ""; //Create the ports tree - } - //Now check if the git directory exists - QString URL = "https://www.github.com/pcbsd/freebsd.git"; - if(QFile::exists("/usr/src/.git")){ - //Check if the remote URL is correct - QString origin = General::gitCMD("/usr/src", "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified(); - if(origin != URL){ - cmds << "git remote remove origin"; dirs <<"/usr/src"; - cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo - } - }else{ - //new GIT setup - General::emptyDir("/usr/src"); - cmds << "git init"; dirs << "/usr/src"; //setup git - cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo - } - //Now update the tree with git - cmds << "git fetch --depth=1"; dirs << "/usr/src/.git"; - cmds << "git checkout "+branch; dirs << "/usr/src"; -}*/ From d07658ee2147b1c3486a12e0f2aa74ca0be73bda Mon Sep 17 00:00:00 2001 From: q5sys Date: Thu, 2 Nov 2017 11:48:25 -0400 Subject: [PATCH 3/6] more api work for sourcectl --- src/server/DispatcherParsing.cpp | 43 +++++++++++++++++++++++++++++--- src/server/WebBackend.cpp | 6 ----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/server/DispatcherParsing.cpp b/src/server/DispatcherParsing.cpp index 77ef1ff..a26842a 100644 --- a/src/server/DispatcherParsing.cpp +++ b/src/server/DispatcherParsing.cpp @@ -90,9 +90,25 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){ //qDebug() << "Got update check process finished"; sysadm::sourcectl::saveSourceLog(cLog); //save this for use later - } - }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_updatesource"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_updatesource"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::saveSourceLog(cLog); //save this for use later + } + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_deleteports"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_deleteports"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::savePortsLog(cLog); //save this for use later + } + }else if(ID.startsWith("sysadm_sourcectl")){ if(ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ namesp = "sysadm"; name="soucectl"; //No special parsing here: the git output should be available as-is @@ -100,8 +116,27 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ //qDebug() << "Got update check process finished"; sysadm::sourcectl::savePortsLog(cLog); //save this for use later -} -} + } + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_updateports"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_updateports"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::savePortsLog(cLog); //save this for use later + } + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_deleteports"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_deleteports"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::savePortsLog(cLog); //save this for use later + } + } + } //Now assemble the output as needed if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 4a616f5..067ff17 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -612,12 +612,6 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemMgmtRequest(const QJso ok = true; out->insert("deviceinfo", sysadm::SysMgmt::systemDevices()); } - else if(act=="fetch_ports"){ - ok = true; - QString altdir; - if(keys.contains("ports_dir")){ altdir = in_args.toObject().value("ports_dir").toString(); } - out->insert("fetch_ports", sysadm::SysMgmt::fetchPortsTree(altdir)); - } } //end of "action" key usage From 2157dbb6c2411e2c89a440f69715c5c3396c8f6d Mon Sep 17 00:00:00 2001 From: q5sys Date: Thu, 2 Nov 2017 11:52:07 -0400 Subject: [PATCH 4/6] add new library files --- src/server/library/sysadm-sourcectl.cpp | 209 ++++++++++++++++++++++++ src/server/library/sysadm-sourcectl.h | 34 ++++ 2 files changed, 243 insertions(+) create mode 100644 src/server/library/sysadm-sourcectl.cpp create mode 100644 src/server/library/sysadm-sourcectl.h diff --git a/src/server/library/sysadm-sourcectl.cpp b/src/server/library/sysadm-sourcectl.cpp new file mode 100644 index 0000000..bb9a323 --- /dev/null +++ b/src/server/library/sysadm-sourcectl.cpp @@ -0,0 +1,209 @@ +//=========================================== +// TrueOS source code +// Copyright (c) 2017, JT (q5sys) +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "sysadm-general.h" +#include "sysadm-sourcectl.h" +#include "sysadm-global.h" +#include "globals.h" + +#include +#include "sysadm-general.h" +#include "sysadm-update.h" +#include "sysadm-global.h" +#include "globals.h" + +using namespace sysadm; + +// ================== +// INLINE FUNCTIONS +// ================== + +// ================= +// MAIN FUNCTIONS +// ================= + +QJsonObject sourcectl::downloadsource(){ + // cmd that will be run = git clone https://github.com/trueos/freebsd.git /usr/src + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QString cmd; + cmd = "git clone https://github.com/trueos/freebsd.git /usr/src"; + DISPATCHER->queueProcess("sysadm_sourcectl_downloadsource::"+ID, cmd); + + // Return some details to user that the action was queued + retObject.insert("command", "Downloading TrueOS Source Tree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + +QJsonObject sourcectl::updatesource(){ + // cmd that will be run = git reset --hard && git pull + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QStringList cmds; + cmds << "git reset --hard" << "git pull"; + DISPATCHER->queueProcess("sysadm_sourcectl_updatesource::"+ID, cmds, "/usr/src/"); + + // Return some details to user that the action was queued + retObject.insert("command", "Updating TrueOS Source Tree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + +QJsonObject sourcectl::deletesource(){ + // cmd that will be run = rm -rf /usr/src/ + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QString cmd; + cmd = "rm -rf /usr/src/"; + DISPATCHER->queueProcess("sysadm_sourcectl_deletesource::"+ID, cmd); + + // Return some details to user that the action was queued + retObject.insert("command", "Deleting TrueOS Source Tree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + +QJsonObject sourcectl::stopsource(){} + +QJsonObject sourcectl::downloadports(){ + // cmd that will be run = git clone https://github.com/trueos/freebsd-ports.git /usr/ports + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QString cmd; + cmd = "git clone https://github.com/trueos/freebsd-ports.git /usr/ports"; + DISPATCHER->queueProcess("sysadm_sourcectl_downloadports::"+ID, cmd); + + // Return some details to user that the action was queued + retObject.insert("command", "Downloading TrueOS PortsTree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} +QJsonObject sourcectl::updateports(){ + // cmd that will be run = git reset --hard && git pull + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QStringList cmds; + cmds << "git reset --hard" << "git pull"; + DISPATCHER->queueProcess("sysadm_sourcectl_updateports::"+ID, cmds, "/usr/ports/"); + + // Return some details to user that the action was queued + retObject.insert("command", "Updating TrueOS PortsTree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + + +QJsonObject sourcectl::deleteports(){ + // cmd that will be run = rm -rf /usr/ports/ + QJsonObject retObject; + QString ID = QUuid::createUuid().toString(); // Create a unique ID for this queued action + // Queue the update action + QString cmd; + cmd = "rm -rf /usr/ports/"; + DISPATCHER->queueProcess("sysadm_sourcectl_deleteports::"+ID, cmd); + + // Return some details to user that the action was queued + retObject.insert("command", "Deleting TrueOS PortsTree"); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + +QJsonObject sourcectl::stopports(){} + + +void sourcectl::saveSourceLog(QString){} +void sourcectl::savePortsLog(QString){} + + + + +/* + +git clone https://github.com/trueos/freebsd.git /usr/src +git clone https://github.com/trueos/freebsd-ports.git /usr/ports + +git reset --hard && git pull + + +rm -rf /usr/src/ +rm -rf /usr/ports/ + + + +QJsonObject SysMgmt::fetchPortsTree(QString altDir){ +//void SysMgmt::fetchPortsTree(QStringList &cmds, QStringList &dirs){ + QJsonObject out; + if(altDir.isEmpty()){ altDir = "/usr/ports"; } + //Does Ports tree exist? If not create it. + if(!QFile::exists(altDir)){ + QDir dir; + if(!dir.mkpath(altDir) ){ + out.insert("error","Could not create directory: "+altDir); + return out; + } + } + //Does a local git repo exist? If not create it. + QString URL = "https://www.github.com/trueos/freebsd-ports.git"; + if(QFile::exists(altDir+"/.git")){ + //Check if the remote URL is correct + QString origin = General::gitCMD(altDir, "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified(); + if(origin != URL){ + General::gitCMD(altDir,"git",QStringList() << "remote" << "remove" << "origin"); + General::gitCMD(altDir,"git", QStringList() << "remote" << "add" << "origin" << URL); + } + }else{ + //new GIT setup + General::emptyDir(altDir); + General::gitCMD(altDir, "git", QStringList() << "init" << altDir ); + General::gitCMD(altDir, "git", QStringList() << "remote" << "add" << "origin" << URL ); + } + //Now update the tree with git + QString ID = "system_fetch_ports_tree"; + DISPATCHER->queueProcess(ID, "git pull origin", altDir ); + out.insert("result","process_started"); + out.insert("process_id",ID); + return out; +} + +/*void SysMgmt::fetchSourceTree(QString branch, QStringList &cmds, QStringList &dirs, QStringList &info){ + //Clear the output variables + cmds.clear(); dirs.clear(); + //Check if the source directory even exists + if(!QFile::exists("/usr/src")){ + cmds << "mkdir /usr/src"; dirs << ""; //Create the ports tree + } + //Now check if the git directory exists + QString URL = "https://www.github.com/pcbsd/freebsd.git"; + if(QFile::exists("/usr/src/.git")){ + //Check if the remote URL is correct + QString origin = General::gitCMD("/usr/src", "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified(); + if(origin != URL){ + cmds << "git remote remove origin"; dirs <<"/usr/src"; + cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo + } + }else{ + //new GIT setup + General::emptyDir("/usr/src"); + cmds << "git init"; dirs << "/usr/src"; //setup git + cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo + } + //Now update the tree with git + cmds << "git fetch --depth=1"; dirs << "/usr/src/.git"; + cmds << "git checkout "+branch; dirs << "/usr/src"; +} +*/ diff --git a/src/server/library/sysadm-sourcectl.h b/src/server/library/sysadm-sourcectl.h new file mode 100644 index 0000000..f0d9b5e --- /dev/null +++ b/src/server/library/sysadm-sourcectl.h @@ -0,0 +1,34 @@ +//=========================================== +// TrueOS source code +// Copyright (c) 2017, JT (q5sys) +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef __PCBSD_LIB_UTILS_SOURCECTL_H +#define __PCBSD_LIB_UTILS_SOURCECTL_H + +#include +#include "sysadm-global.h" + +namespace sysadm{ + +class sourcectl{ +public: + + static QJsonObject downloadports(); + static QJsonObject updateports(); + static QJsonObject deleteports(); + static QJsonObject stopports(); + static QJsonObject downloadsource(); + static QJsonObject updatesource(); + static QJsonObject deletesource(); + static QJsonObject stopsource(); + + static void saveSourceLog(QString); + static void savePortsLog(QString); + +}; + +} //end of sysadm namespace + +#endif From c5bf9440173326783ef1f4eff7aff616ecb660aa Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 17 Nov 2017 15:58:37 -0500 Subject: [PATCH 5/6] [API CHANGE] Add a new API call for sysadm/update: action="applyupdate". This takes no other inputs, and returns the following: { "applyupdate" : { "result" : "rebooting to apply updates" } } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-update.cpp | 6 ++++++ src/server/library/sysadm-update.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 067ff17..fed348d 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -650,6 +650,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal ok = true; out->insert("stopupdate", sysadm::Update::stopUpdate() ); + }else if(act=="applyupdate"){ + ok = true; + out->insert("applyupdate", sysadm::Update::applyUpdates() ); + }else if(act=="listsettings"){ ok = true; out->insert("listsettings", sysadm::Update::readSettings() ); diff --git a/src/server/library/sysadm-update.cpp b/src/server/library/sysadm-update.cpp index 2b5220f..2bd5238 100644 --- a/src/server/library/sysadm-update.cpp +++ b/src/server/library/sysadm-update.cpp @@ -267,6 +267,12 @@ QJsonObject Update::stopUpdate() { return ret; } +QJsonObject Update::applyUpdates(){ + QJsonObject ret; + QProcess::startDetached("pc-updatemanager startupdate"); + ret.insert("result","rebooting to complete updates"); + return ret; +} //SETTINGS OPTIONS QJsonObject Update::readSettings(){ QJsonObject ret; diff --git a/src/server/library/sysadm-update.h b/src/server/library/sysadm-update.h index 183fc7f..07ac009 100644 --- a/src/server/library/sysadm-update.h +++ b/src/server/library/sysadm-update.h @@ -25,6 +25,7 @@ public: //Start/stop update routine static QJsonObject startUpdate(QJsonObject); static QJsonObject stopUpdate(); + static QJsonObject applyUpdates(); //Read/write update settings static QJsonObject readSettings(); static QJsonObject writeSettings(QJsonObject); From f4a24594299f2dc02739ff407c940c2c2a17a0d0 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 17 Nov 2017 16:02:39 -0500 Subject: [PATCH 6/6] Change the internal reboot/update mechanism to use the new "applyUpdates()" function instead of just systemReboot(). --- src/server/EventWatcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/EventWatcher.cpp b/src/server/EventWatcher.cpp index 3770bb6..1134a8f 100644 --- a/src/server/EventWatcher.cpp +++ b/src/server/EventWatcher.cpp @@ -384,7 +384,7 @@ void EventWatcher::CheckSystemState(){ QDateTime finished = sysadm::Update::rebootRequiredSince(); QDateTime cdt = QDateTime::currentDateTime(); if( (finished.addSecs(60*60*24)