int Command_install( apr_pool_t *p, const char *url, const char *configure_opts, const char *make_opts, const char *install_opts ) { int rc = 0; // first clean up check(Shell_exec(CLEANUP_SH, NULL) == 0, "Faild to clean up before building."); // next, make sure it isn't already installed rc = DB_find(url); check(rc != -1, "Error checking the installed database"); if (rc == 1) { log_info("Package already installed."); return 0; } // it isn't installed. So, fetch. rc = Command_fetch(p, url, 0); // if fetch worked, build. if (rc == 1) { rc = Command_build(p, url, configure_opts, make_opts, install_opts); } else if (rc == 0) { // no install needed... I haven't read fetch yet so I'm not sure how // this would happen. log_info("Depends successfully installed: %s", url); } else { sentinel("Install failed: %s", url); } // cleanup again. It doesn't matter whether we check errors this time. Shell_exec(CLEANUP_SH, NULL); return 0; error: return -1; }
int main(int argc, const char const *argv[]) { apr_pool_t *p = NULL; apr_pool_initialize(); apr_pool_create(&p, NULL); apr_getopt_t *opt; apr_status_t rv; char ch = '\0'; const char *optarg = NULL; const char *config_opts = NULL; const char *install_opts = NULL; const char *make_opts = NULL; const char *url = NULL; enum CommandType request = COMMAND_NONE; rv = apr_getopt_init(&opt, p, argc, argv); while(apr_getopt(opt, "I:Lc:m:i:d:SF:B:", &ch, &optarg) == APR_SUCCESS) { switch (ch) { case 'I': request = COMMAND_INSTALL; url = optarg; break; case 'L': request = COMMAND_LIST; break; case 'c': config_opts = optarg; break; case 'm': make_opts = optarg; break; case 'i': install_opts = optarg; break; case 'S': request = COMMAND_INIT; break; case 'F': request = COMMAND_FETCH; url = optarg; break; case 'B': request = COMMAND_BUILD; url = optarg; break; } } switch(request) { case COMMAND_INSTALL: check(url, "You must at least give a URL."); Command_install(p, url, config_opts, make_opts, install_opts); break; case COMMAND_LIST: db_list(); break; case COMMAND_FETCH: check(url != NULL, "You must give a URL."); Command_fetch(p, url, 1); log_inf("Downloaded to %s and in /tmp/", BUILD_DIR); break; case COMMAND_BUILD: check(url, "You must at least give a URL."); Command_build(p, url, config_opts, make_opts, install_opts); break; case COMMAND_INIT: rv = db_init(); check(rv == 0, "Failed to make the database."); break; default: sentinel("Invalid command given."); } return 0; error: return 1; }
int main(int argc, const char const* argv[]) { apr_pool_t* p = NULL; apr_initialize(); apr_pool_create(&p, NULL); apr_getopt_t* opt; apr_status_t rv; char ch = '\0'; const char* optarg = NULL; const char* config_opts = NULL; const char* install_opts = NULL; const char* make_opts = NULL; const char* url = NULL; Command request = None; rv = apr_getopt_init(&opt, p, argc, argv); while(apr_getopt(opt, "I:Lc:m:i:d:SF:B:", &ch, &optarg) == APR_SUCCESS) { switch(ch) { case 'I': request = Install; url = optarg; break; case 'L': request = List; break; case 'c': config_opts = optarg; break; case 'm': make_opts = optarg; break; case 'i': install_opts = optarg; break; case 'S': request = Init; break; case 'F': request = Fetch; url = optarg; break; case 'B': request = Build; url = optarg; break; } } switch(request) { case Install: check(url, "You must give a url."); Command_install(p, url, config_opts, make_opts, install_opts); break; case List: DB_list(); break; case Fetch: check(url, "You must give a url."); Command_fetch(p, url, true); log_info("Downloaded to %s and in /tmp", BUILD_DIR); break; case Build: check(url, "You must give a url."); Command_build(p, url, config_opts, make_opts, install_opts); break; case Init: rv = DB_init(); check(rv == 0, "Failed to make the database."); break; default: sentinel("Invalid command given."); } return EXIT_SUCCESS; error: return EXIT_FAILURE; }