2024-07-27 11:27:52 +00:00
|
|
|
#include <engine_engine_number_9/baza_throw.h>
|
2024-08-15 10:39:42 +00:00
|
|
|
#include <engine_engine_number_9/os_utils.h>
|
2024-07-27 11:27:52 +00:00
|
|
|
#include <assert.h>
|
2024-08-11 21:12:30 +00:00
|
|
|
#include <jsonincpp/string_representation.h>
|
2024-08-15 10:39:42 +00:00
|
|
|
#include "actions.h"
|
2024-08-15 21:06:35 +00:00
|
|
|
#include <stdexcept>
|
2024-07-27 11:27:52 +00:00
|
|
|
|
2024-08-05 00:37:56 +00:00
|
|
|
void usage(char** argv) {
|
2024-08-16 19:10:04 +00:00
|
|
|
printf("Usage: %s <file with settings> <run|initialize>\n", argv[0]);
|
2024-08-05 00:37:56 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv){
|
|
|
|
try {
|
|
|
|
een9_ASSERT_pl(argc > 0);
|
2024-08-15 10:39:42 +00:00
|
|
|
if (argc != 1 + 2)
|
2024-08-05 00:37:56 +00:00
|
|
|
usage(argv);
|
2024-08-15 10:39:42 +00:00
|
|
|
std::string config_file = argv[1];
|
2024-08-19 16:25:21 +00:00
|
|
|
if (!een9::isRegularFile(config_file) || !een9::endsWith(config_file, ".json")) {
|
2024-08-05 00:37:56 +00:00
|
|
|
printf("\"%s\" is not a json file\n", argv[1]);
|
|
|
|
usage(argv);
|
2024-07-27 11:27:52 +00:00
|
|
|
}
|
2024-08-15 10:39:42 +00:00
|
|
|
std::string cmd = argv[2];
|
2024-08-05 00:37:56 +00:00
|
|
|
std::string config_text;
|
|
|
|
een9::readFile(config_file, config_text);
|
2024-08-15 10:39:42 +00:00
|
|
|
const json::JSON config = json::parse_str_flawless(config_text);
|
|
|
|
|
|
|
|
if (cmd == "initialize") {
|
|
|
|
const char* ROOT_PW = getenv("ROOT_PW");
|
|
|
|
een9_ASSERT(ROOT_PW, "No root password specified."
|
|
|
|
"Assign desired root password value to environment variable ROOT_PW");
|
|
|
|
std::string root_pw = ROOT_PW;
|
|
|
|
initialize_website(config, root_pw);
|
|
|
|
} else if (cmd == "run") {
|
|
|
|
run_website(config);
|
|
|
|
} else
|
|
|
|
een9_THROW("unknown action (known are 'run', 'initialize')");
|
2024-08-05 00:37:56 +00:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
printf("System failure\n%s\n", e.what());
|
|
|
|
}
|
2024-07-27 11:27:52 +00:00
|
|
|
return 0;
|
2024-08-05 00:37:56 +00:00
|
|
|
}
|