diff --git a/installer/sashimono-install.sh b/installer/sashimono-install.sh index 2994082..f041a10 100755 --- a/installer/sashimono-install.sh +++ b/installer/sashimono-install.sh @@ -4,6 +4,7 @@ sashimono_bin=/usr/bin/sashimono-agent docker_bin=/usr/bin/sashimono-agent/dockerbin +sashimono_data=/etc/sashimono echo "Installing Sashimono..." @@ -12,6 +13,8 @@ mkdir -p $sashimono_bin [ "$?" == "1" ] && echo "Could not create '$sashimono_bin'. Make sure you are running as sudo." && exit 1 mkdir -p $docker_bin [ "$?" == "1" ] && echo "Could not create '$docker_bin'. Make sure you are running as sudo." && exit 1 +mkdir -p $sashimono_data +[ "$?" == "1" ] && echo "Could not create '$sashimono_data'. Make sure you are running as sudo." && exit 1 # Install curl if not exists (required to download installation artifacts). if ! command -v curl &> /dev/null @@ -22,6 +25,18 @@ fi # Install Sashimono agent binaries into sashimono bin dir. # TODO. +# Copy necessary files into sashimono data folder. +cp -r ../dependencies/default_contract $sashimono_data +if ! cp ../bootstrap-contract/script.sh $sashimono_data/default_contract/contract_fs/seed/state/script.sh; then + echo "script.sh file not found." + exit 1 +fi + +if ! cp ../build/bootstrap_contract $sashimono_data/default_contract/contract_fs/seed/state/bootstrap_contract; then + echo "bootstrap_contract file not found." + exit 1 +fi + # Download docker packages into a tmp dir and extract into docker bin. echo "Installing rootless docker packages into $docker_bin" tmp=$(mktemp -d) diff --git a/installer/sashimono-uninstall.sh b/installer/sashimono-uninstall.sh index 9389d50..3be866f 100755 --- a/installer/sashimono-uninstall.sh +++ b/installer/sashimono-uninstall.sh @@ -2,6 +2,7 @@ # Sashimono agent uninstall script. sashimono_bin=/usr/bin/sashimono-agent +sashimono_data=/etc/sashimono # Uninstall all contract instance users prefix="sashi" @@ -40,5 +41,8 @@ fi echo "Deleting binaries..." rm -r $sashimono_bin +echo "Deleting data folder..." +rm -r $sashimono_data + echo "Done." exit 0 \ No newline at end of file diff --git a/src/conf.cpp b/src/conf.cpp index 62b8172..b3fd313 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -108,11 +108,13 @@ namespace conf ctx.hpfs_exe_path = ctx.exe_dir + "/hpfs"; ctx.user_install_sh = ctx.exe_dir + "/user-install.sh"; ctx.user_uninstall_sh = ctx.exe_dir + "/user-uninstall.sh"; - ctx.default_contract_path = ctx.exe_dir + "/default_contract"; - ctx.config_dir = ctx.exe_dir + "/cfg"; + + const std::string sashimono_folder = conf::ctx.environment == conf::ENVIRONMENT::DEVELOPMENT ? ctx.exe_dir : "/etc/sashimono"; + ctx.default_contract_path = sashimono_folder + "/default_contract"; + ctx.config_dir = sashimono_folder + "/cfg"; ctx.config_file = ctx.config_dir + "/sa.cfg"; - ctx.log_dir = ctx.exe_dir + "/log"; - ctx.data_dir = ctx.exe_dir + "/data"; + ctx.log_dir = sashimono_folder + "/log"; + ctx.data_dir = sashimono_folder + "/data"; } /** diff --git a/src/conf.hpp b/src/conf.hpp index a9cef20..d280e4f 100644 --- a/src/conf.hpp +++ b/src/conf.hpp @@ -78,17 +78,24 @@ namespace conf log_config log; }; + enum ENVIRONMENT + { + DEVELOPMENT, + PRODUCTION + }; + struct sa_context { - std::string command; // The CLI command issued to launch Sashimono agent - std::string exe_dir; // Hot Pocket executable dir. - std::string hpws_exe_path; // hpws executable file path. - std::string hpfs_exe_path; // hpfs executable file path. - std::string default_contract_path; // Path to default contract. + std::string command; // The CLI command issued to launch Sashimono agent + ENVIRONMENT environment = ENVIRONMENT::DEVELOPMENT; // Running environment mode. (dev | prod) + std::string exe_dir; // Hot Pocket executable dir. + std::string hpws_exe_path; // hpws executable file path. + std::string hpfs_exe_path; // hpfs executable file path. + std::string default_contract_path; // Path to default contract. std::string user_install_sh; std::string user_uninstall_sh; - + std::string config_dir; // Config dir full path. std::string config_file; // Full path to the config file. std::string log_dir; // Log directory full path. diff --git a/src/main.cpp b/src/main.cpp index 3d03764..8777ef2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,16 @@ #include "crypto.hpp" #include "hp_manager.hpp" +#define PARSE_ERROR \ + { \ + std::cerr << "Arguments mismatch.\n"; \ + std::cout << "Usage:\n"; \ + std::cout << "sagent version\n"; \ + std::cout << "sagent [command = run | new | rekey][env(optional) = dev | prod]\n"; \ + std::cout << "Example: sagent run\n"; \ + return -1; \ + } + /** * Parses CLI args and extracts sashimono agent command and parameters given. * @param argc Argument count. @@ -21,8 +31,17 @@ int parse_cmd(int argc, char **argv) if (argc > 1) { conf::ctx.command = argv[1]; - if (argc == 2 && //We get working dir as an arg anyway. So we need to check for ==2 args. - (conf::ctx.command == "new" || conf::ctx.command == "run" || conf::ctx.command == "version")) + + if (argc == 3) + { + const std::string env(argv[2]); + if (env != "dev" && env != "prod") + PARSE_ERROR + + conf::ctx.environment = (env == "dev") ? conf::ENVIRONMENT::DEVELOPMENT : conf::ENVIRONMENT::PRODUCTION; + } + + if (conf::ctx.command == "new" || conf::ctx.command == "run" || conf::ctx.command == "version") { // We populate the global contract ctx with the detected command. conf::set_dir_paths(argv[0]); @@ -30,14 +49,8 @@ int parse_cmd(int argc, char **argv) } } - // If all extractions fail display help message. - std::cerr << "Arguments mismatch.\n"; - std::cout << "Usage:\n"; - std::cout << "sagent version\n"; - std::cout << "sagent (command = run | new | rekey)\n"; - std::cout << "Example: sagent run\n"; - - return -1; + // If all extractions fail display help message and return -1. + PARSE_ERROR } /** @@ -136,7 +149,10 @@ int main(int argc, char **argv) if (conf::ctx.command == "run") { - LOG_INFO << "Sashimono agent started. Version : " << conf::cfg.version << " Log level : " << conf::cfg.log.log_level; + LOG_INFO << "Sashimono agent started." + << " Version: " << conf::cfg.version + << " | Log level: " << conf::cfg.log.log_level + << " | Env: " << (conf::ctx.environment == conf::ENVIRONMENT::DEVELOPMENT ? "development" : "production"); if (comm::init() == -1 || hp::init() == -1) {