// This file is part of JustMotion. // JustMotion 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. // JustMotion 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. #include "common.h" #include "camera.h" #include "services.h" void showHelp(const QString etcDir) { QTextStream(stdout) << APP_NAME << " " << APP_VERSION << Qt::endl << Qt::endl; QTextStream(stdout) << "Usage: " << APP_TARGET << " " << Qt::endl << Qt::endl; QTextStream(stdout) << "-h : display usage information about this application." << Qt::endl; 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 " << etcDir << " 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; QTextStream(stdout) << "-d : this is the same as -i except it will not auto start the services." << Qt::endl; QTextStream(stdout) << "-v : display the current version." << Qt::endl; QTextStream(stdout) << "-u : uninstall the entire app from your system, including all" << Qt::endl; QTextStream(stdout) << " systemd services related to it." << Qt::endl; QTextStream(stdout) << "-f : force an action without pausing for user confirmation." << Qt::endl; QTextStream(stdout) << "-l : list all attached services to this application along with statuses." << Qt::endl; QTextStream(stdout) << "-r : remove all attached services." << Qt::endl; } int main(int argc, char** argv) { QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(APP_NAME); QCoreApplication::setApplicationVersion(APP_VERSION); auto args = QCoreApplication::arguments(); auto etcDir = "/etc/" + QString(APP_TARGET); auto ret = 0; if (args.contains("-h")) { showHelp(etcDir); } else if (args.contains("-v")) { QTextStream(stdout) << APP_VERSION << Qt::endl; } else if (args.contains("-l")) { servStatByDir(etcDir); } else if (args.contains("-i") || args.contains("-d")) { ret = rmServiceByDir(etcDir); if ((ret == 0) && args.contains("-i")) { ret = loadServiceByDir(etcDir, true); } else if (ret == 0) { ret = loadServiceByDir(etcDir, false); } } else if (args.contains("-c")) { auto *cam = new Camera(&app); ret = cam->start(args); if (ret == 0) { ret = QCoreApplication::exec(); } } else if (args.contains("-u")) { if (args.contains("-f")) { ret = rmServiceByDir(etcDir); if (ret == 0) { ret = QProcess::execute("/opt/" + QString(APP_TARGET) + "/uninstall.sh", QStringList()); } } 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') { ret = rmServiceByDir("/etc/mow"); if (ret == 0) { ret = QProcess::execute("/opt/" + QString(APP_TARGET) + "/uninstall.sh", QStringList()); } } } } else if (args.contains("-r")) { ret = rmServiceByDir(etcDir); } else { showHelp(etcDir); } return ret; }