Example #1
0
int Command_depends(apr_pool_t *p, const char *path)
{
  FILE *in = NULL;
  bstring line = NULL;

  in = fopen(path, "r");
  check(in != NULL, "Failed to open downloaded depends: %s", path);

  for(line = bgets((bNgetc)fgetc, in, '\n'); line != NULL;
      line = bgets((bNgetc)fgetc, in, '\n'))
  {
    btrimws(line);
    log_info("Processing depends: %s", bdata(line));
    int rc = Command_install(p, bdata(line), NULL, NULL, NULL);
    check(rc == 0, "Failed to install: %s", bdata(line));
    bdestroy(line);
  }
  fclose(in);
  return 0;

error:
  if(line) bdestroy(line);
  if(in) fclose(in);
  return -1;
}
Example #2
0
int Command_depends(apr_pool_t *p , const char* path){
/* read from the depend file of some package line by line(which is downloaded from
 * network or be a local file generated by teh command_fetch
 * for each depends , install it ,  use the apr functions in command_install
 * to install
 */
	FILE *in = NULL;
	bstring line = NULL;

	in = fopen(path , "r");
	check(in != NULL , "faled to open download depends: %s" , path);

	for( line = bgets((bNgetc)fgetc , in , '\n');line != NULL;
		line = bgets((bNgetc)fgetc , in , '\n'))
	{
		btrimws(line);
	log_info("process depends: %s" , bdata(line));
	int rc = Command_install(p , bdata(line),NULL ,NULL ,NULL);
	check(rc == 0 , "failed to install: %s" , bdata(line));
	bdestroy(line);
	}

	fclose(in);
	return 0;

error:
	if(line) bdestroy(line);
	if(in) fclose(in);
	return -1;
}
Example #3
0
/* Accepts a filepath, and installs all dependencies.
 *    does not fetch the file, that's done by Command_fetch. */
int Command_depends(apr_pool_t *p, const char *path) {
    FILE *in = NULL;
    bstring line = NULL;

    in = fopen(path, "r");
    check(in != NULL, "Failed to open downloaded depends: %s", path);

    // bgets is like fgets. See db.c for a deeper discussion of what's
    // going on with the cast -- we are casting fgetc to a type bstringlib
    // likes, then using it to do a gets op. The cast is probably illegal in
    // ANSI C, in which case we would need to define a wrapper, but gcc
    // apparently lets us get away with it.
    for (line = bgets((bNgetc)fgetc, in, '\n');
         line != NULL;
         line = bgets((bNgetc)fgetc, in, '\n')) {
        // trim whitewspace, the bstrlib equiv of python's strip
        btrimws(line);
        log_info("Processing depends: %s", bdata(line));
        // note tha dependencies are assumed not to need options
        int rc = Command_install(p, bdata(line), NULL, NULL, NULL);
        check(rc == 0, "Failed to install: %s", bdata(line));
        bdestroy(line);
    }
    fclose(in);
    return 0;
error:
    if (line) bdestroy(line);
    if (in) fclose(in);
    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;
}
Example #5
0
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;
}
Example #6
0
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;

			default:
				log_info("Unknown command");}}

	switch (request) {
		case COMMAND_INSTALL:
			check(url != NULL, "You must specify an 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 specify an URL.");
			Command_fetch(p, url, 1);
			log_info("Downloaded target to %s",BUILD_DIR);
			break;

		case COMMAND_BUILD:
			check(url != NULL, "You must specify an URL.");
			Command_install(p, url, config_opts, make_opts, install_opts);
			break;

		case COMMAND_INIT:
			rv = DB_init();
			check(rv == 0, "Failed to create database.");
			break;

		case COMMAND_NONE:
			printf("Usage: give one of the flags -S -I -L -F -B with apropriate arguments\n");
			break;

		default:
			sentinel("Invalid command given");}

	apr_pool_terminate();
	return 0;

error:

	apr_pool_terminate();
	return 1;
}