2022-09-22 20:57:46 -04:00
|
|
|
// This file is part of Motion Watch.
|
2022-04-14 09:45:54 -04:00
|
|
|
|
2022-09-22 20:57:46 -04:00
|
|
|
// Motion Watch is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2022-04-14 09:45:54 -04:00
|
|
|
|
2022-09-22 20:57:46 -04:00
|
|
|
// Motion Watch is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2022-04-14 09:45:54 -04:00
|
|
|
|
2023-05-17 15:06:58 -04:00
|
|
|
#include "common.h"
|
2023-05-15 15:29:47 -04:00
|
|
|
#include "camera.h"
|
2023-10-27 15:43:17 -04:00
|
|
|
#include "services.h"
|
2022-08-12 21:46:36 -04:00
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
void showHelp()
|
|
|
|
{
|
|
|
|
QTextStream(stdout) << APP_NAME << " " << APP_VER << Qt::endl << Qt::endl;
|
|
|
|
QTextStream(stdout) << "Usage: mow <argument>" << Qt::endl << Qt::endl;
|
|
|
|
QTextStream(stdout) << "-h : display usage information about this application." << Qt::endl;
|
2023-10-27 15:43:17 -04:00
|
|
|
QTextStream(stdout) << "-c : path to the config file used to run a single main loop instance." << Qt::endl;
|
|
|
|
QTextStream(stdout) << "-i : all valid config files found in /etc/mow will be used to create" << Qt::endl;
|
|
|
|
QTextStream(stdout) << " a full instance; full meaning main and vid loop systemd services" << Qt::endl;
|
|
|
|
QTextStream(stdout) << " will be created for each config file." << Qt::endl;
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stdout) << "-v : display the current version." << Qt::endl;
|
|
|
|
QTextStream(stdout) << "-u : uninstall the entire app from your system, including all" << Qt::endl;
|
2023-10-27 15:43:17 -04:00
|
|
|
QTextStream(stdout) << " systemd services related to it." << Qt::endl;
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stdout) << "-f : force an action without pausing for user confirmation." << Qt::endl;
|
2023-10-27 15:43:17 -04:00
|
|
|
QTextStream(stdout) << "-l : list all mow services along with statuses." << Qt::endl;
|
|
|
|
QTextStream(stdout) << "-r : remove all mow services." << Qt::endl;
|
2023-07-31 11:16:07 -04:00
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
QCoreApplication app(argc, argv);
|
2023-04-20 14:52:59 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QCoreApplication::setApplicationName(APP_NAME);
|
|
|
|
QCoreApplication::setApplicationVersion(APP_VER);
|
2023-04-20 14:52:59 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
auto args = QCoreApplication::arguments();
|
|
|
|
auto ret = 0;
|
2022-12-11 10:25:22 -05:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (args.contains("-h"))
|
2023-02-18 21:20:24 -05:00
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
showHelp();
|
2023-02-07 23:19:41 -05:00
|
|
|
}
|
2023-05-15 15:29:47 -04:00
|
|
|
else if (args.contains("-v"))
|
2022-08-12 21:46:36 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
QTextStream(stdout) << APP_VER << Qt::endl;
|
2023-03-05 16:07:07 -05:00
|
|
|
}
|
2023-07-31 11:16:07 -04:00
|
|
|
else if (args.contains("-l"))
|
|
|
|
{
|
2023-10-27 15:43:17 -04:00
|
|
|
servStatByDir("/etc/mow");
|
2023-07-31 11:16:07 -04:00
|
|
|
}
|
2023-10-27 15:43:17 -04:00
|
|
|
else if (args.contains("-i") || args.contains("-d"))
|
|
|
|
{
|
|
|
|
ret = rmServiceByDir("/etc/mow");
|
|
|
|
|
|
|
|
if ((ret == 0) && args.contains("-i"))
|
|
|
|
{
|
|
|
|
ret = loadServiceByDir("/etc/mow", true);
|
|
|
|
}
|
|
|
|
else if (ret == 0)
|
|
|
|
{
|
|
|
|
ret = loadServiceByDir("/etc/mow", false);
|
|
|
|
}
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
2023-05-15 15:29:47 -04:00
|
|
|
else if (args.contains("-c"))
|
2023-03-05 16:07:07 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
auto *cam = new Camera(&app);
|
2022-12-13 20:27:32 -05:00
|
|
|
|
2023-05-17 15:06:58 -04:00
|
|
|
ret = cam->start(args);
|
|
|
|
|
|
|
|
if (ret == 0)
|
2022-12-11 10:25:22 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
ret = QCoreApplication::exec();
|
2022-12-11 10:25:22 -05:00
|
|
|
}
|
2022-04-14 09:45:54 -04:00
|
|
|
}
|
2023-07-31 11:16:07 -04:00
|
|
|
else if (args.contains("-u"))
|
|
|
|
{
|
|
|
|
if (args.contains("-f"))
|
|
|
|
{
|
2023-10-27 15:43:17 -04:00
|
|
|
ret = rmServiceByDir("/etc/mow");
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
ret = QProcess::execute("/opt/mow/uninst", QStringList());
|
|
|
|
}
|
2023-07-31 11:16:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char ans;
|
|
|
|
|
|
|
|
std::cout << "This will completely uninstall " << APP_NAME << " from your system. continue y/n? ";
|
|
|
|
std::cin >> ans;
|
|
|
|
|
|
|
|
if (ans == 'y' || ans == 'Y')
|
|
|
|
{
|
2023-10-27 15:43:17 -04:00
|
|
|
ret = rmServiceByDir("/etc/mow");
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
ret = QProcess::execute("/opt/mow/uninst", QStringList());
|
|
|
|
}
|
2023-07-31 11:16:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (args.contains("-r"))
|
|
|
|
{
|
2023-10-27 15:43:17 -04:00
|
|
|
ret = rmServiceByDir("/etc/mow");
|
2023-07-31 11:16:07 -04:00
|
|
|
}
|
2022-04-14 09:45:54 -04:00
|
|
|
else
|
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
showHelp();
|
2022-04-14 09:45:54 -04:00
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
return ret;
|
2022-04-14 09:45:54 -04:00
|
|
|
}
|