diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bfc6597c990ec6cf475528c4256a45e8ff31aacd..31849d76354eebe60f8f3617a98030f3118113dc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,7 +72,6 @@ testDebian: - cd ../test - ./create_users.sh - last -F - - cat /opt/agentC3SL/conf/datasid-conf.json - ./returnTest.bats dependencies: - compileUnix @@ -88,7 +87,6 @@ testUbuntu: - cd test - ./create_users.sh - last -F - - cat /opt/agentC3SL/conf/datasid-conf.json - ./returnTest.bats dependencies: - compileUnix @@ -107,7 +105,6 @@ testOpensuse: - cd test - ./create_users.sh - last -F - - cat /opt/agentC3SL/conf/datasid-conf.json - ./returnTest.bats dependencies: - compileUnix @@ -117,12 +114,9 @@ testWin7: tags: - windows script: - - DIR C:\ - if exist C:\agentC3SL rmdir C:\agentC3SL /s /q - agent-1234.exe /SILENT /VERYSILENT - if not exist C:\agentC3SL exit 1; - - DIR C:\agentC3SL - - DIR C:\agentC3SL\bin - copy C:\jq-win32.exe .\test - cd .\test - C:\agentC3SL\bin\agent-v0.0.exe --once --print > test.json diff --git a/generate_agent.iss b/generate_agent.iss index df7e1e7f8d3e826dabdc056f6d9eb16acc45d810..a8cf5287a8b43b70bad279d0b8e06eabd4ebe997 100644 --- a/generate_agent.iss +++ b/generate_agent.iss @@ -56,7 +56,7 @@ #endif #ifndef prj - #define prj 'simmc-agent' + #define prj 'simmc' #endif #ifndef outputName diff --git a/include/agent/agent.h b/include/agent/agent.h index e370ba638608476d3c5becadc5f8b148a6709e79..91a6bccf43bbfcafb3777a0005897e0db4e57a51 100644 --- a/include/agent/agent.h +++ b/include/agent/agent.h @@ -25,6 +25,8 @@ * <br><br> */ +extern std::string path_to_agent; + class Connection; // forward declarations class Conf; // forward declarations class Proxy; // forward declarations @@ -51,6 +53,7 @@ class Agent{ void setPathLogDir(std::string); void setPathLogFile(std::string); void setPrefix(std::string, int); + void setPrefix(); void setInstallerName(std::string); void setConnection(Connection*); void setConf(Conf*); diff --git a/include/agent/main.h b/include/agent/main.h index 41d4938f0def45887087eaeb3956aa4a34accef1..ac6b3c06596a693cb3a1f36419dc6890d66842a8 100644 --- a/include/agent/main.h +++ b/include/agent/main.h @@ -29,7 +29,7 @@ namespace fs = boost::filesystem; #ifdef __linux__ std::string path_to_agent_tmp = // NOLINT(runtime/string) "/opt/agentC3SL/tmp/"; // NOLINT(runtime/string) - std::string path_to_agent = "/opt/"; // NOLINT(runtime/string) + std::string path_to_agent = "/opt/agentC3SL/"; // NOLINT(runtime/string) //std::string path_to_agent_conf = // NOLINT(runtime/string) //"/opt/agentC3SL/conf/"; // NOLINT(runtime/string) std::string path_to_agent_conf = "/home/teste/Imagens/agent/conf/"; @@ -38,7 +38,7 @@ namespace fs = boost::filesystem; std::string path_to_agent_tmp = "C:\\agentC3SL\\tmp\\"; std::string path_to_agent = "C:\\agentC3SL\\"; std::string path_to_agent_conf = // NOLINT(runtime/string) - "C:\\agentC3SL\\conf\\"; // NOLINT(runtime/string) + "C:\\agentC3SL\\teste\\"; // NOLINT(runtime/string) #endif bool agent_send_inventory = false; @@ -65,7 +65,7 @@ int main(int, char**); * - print - set print JSON to true - show inventory * - uninstall - uninstall agent and all associated files */ -int parse_command_line(int, char*, int*, int*, bool*); +int parse_command_line(int, char*, int*, int*, bool*, bool*); bool read_config_files(Agent*); diff --git a/src/agent/agent.cpp b/src/agent/agent.cpp index 4028ab0a2369657a5aa6f132a60b9816d28f02f3..68ff02d903df38cffabb311526739e81240dd3fb 100644 --- a/src/agent/agent.cpp +++ b/src/agent/agent.cpp @@ -60,6 +60,11 @@ void Agent::setPrefix(std::string p, int tot) { this->prefix = p.substr(0, i); } +/** Set the absolute path from agent */ +void Agent::setPrefix() { + this->prefix = path_to_agent; +} + /** Set the name to agent installer (.run (linux) or .exe (windows)) file */ void Agent::setInstallerName(std::string i) { this->installerName = i; diff --git a/src/agent/main.cpp b/src/agent/main.cpp index bd26082b6cb66cdd389c7be8392777407eed2302..76e0a0bc6432e0e23f8fd0d8b58aab32ed8bd7ae 100644 --- a/src/agent/main.cpp +++ b/src/agent/main.cpp @@ -108,13 +108,14 @@ void config_agent() { * - uninstall - uninstall agent and all associated files */ int parse_command_line(int ac, char* av[], int *increment, int *lim, - bool *print) { + bool *print, bool *dev) { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("once", "run agent only once") ("print", "set print JSON to true") - ("uninstall", "uninstall agent and all associated files"); + ("uninstall", "uninstall agent and all associated files") + ("dev", "development environment"); po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); @@ -132,6 +133,8 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim, } else { *print = false; } + if (vm.count("dev")) + *dev = true; #ifdef __unix__ if (vm.count("uninstall")) { @@ -181,19 +184,25 @@ int main(int argc, char* argv[]) { agent.setConf(&conf); agent.setProxy(&proxy); - /* Set agent prefix (agent folder) */ - agent.setPrefix(__FILE__, 3); - agent.setPathLogFile("/log/datasid-agent.log"); - agent.logFile.open(agent.getPathLogFile().c_str(), std::fstream::app); - int increment = 0; int lim = 1; bool print; + bool dev = false; pt::ptime begin; - if (parse_command_line(argc, argv, &increment, &lim, &print)) { + if (parse_command_line(argc, argv, &increment, &lim, &print, &dev)) { return (1); } + + /* Set agent prefix (agent folder) */ + if (dev) // __FILE__ macro get the path on compiler time + agent.setPrefix(__FILE__, 3); + else + agent.setPrefix(); + + agent.setPathLogFile("/log/datasid-agent.log"); + agent.logFile.open(agent.getPathLogFile().c_str(), std::fstream::app); + config_agent(); set_begin(begin); diff --git a/test/testWin.bat b/test/testWin.bat index 83b70c8531961dca841df9dc3e1a8feb27be19ac..e9cd599ab59b003887fd3639cd52effc2f1da755 100644 --- a/test/testWin.bat +++ b/test/testWin.bat @@ -74,6 +74,7 @@ FOR /f "delims=" %%a IN (test.json) DO ( REM Verificando o data_inventory json ... ECHO Verificando o data_inventory json ... +type result.json REM Check agent version jq-win32.exe ".data_inventory.agent_version==\"1.0.0\"" result.json > result.txt @@ -117,7 +118,7 @@ set /p var=<result.txt if %var%==false ( exit 1 ) else ( echo extra hds ok ) REM Check id point -jq-win32.exe ".data_inventory.id_point==\"1234\"" result.json > result.txt +jq-win32.exe ".data_inventory.id_point==1234" result.json > result.txt set /p var=<result.txt if %var%==false ( exit 1 ) else ( echo id point ok ) @@ -225,4 +226,8 @@ if %var%==false ( exit 1 ) else ( echo packets tranmitted ok ) del result.txt del result.json -del test.json \ No newline at end of file +del test.json + +REM uninstall agent +start C:\agentC3SL\uninstall_agent.exe /SILENT /VERYSILENT +dir /b /a "C:\agentC3SL\*" | >nul findstr "^" && (echo Agent has been uninstalled) || (exit 1); \ No newline at end of file