main.c
changeset 151 ae6ceb604f54
parent 137 4722cd3437cb
child 152 1a19aec546fb
     1.1 --- a/main.c	Fri Feb 29 11:53:15 2008 -0500
     1.2 +++ b/main.c	Thu Mar 06 01:33:08 2008 -0500
     1.3 @@ -9,6 +9,7 @@
     1.4  #include <curl/curl.h>
     1.5  #include <fnmatch.h>
     1.6  #include "razor.h"
     1.7 +#include "razor-internal.h"
     1.8  
     1.9  static const char *repo_filename = "system.repo";
    1.10  static const char *rawhide_repo_filename = "rawhide.repo";
    1.11 @@ -451,13 +452,37 @@
    1.12  	return 0;
    1.13  }
    1.14  
    1.15 +const static char razor_root_path[] = "/var/lib/razor";
    1.16 +const static char razor_system_repo[] = "system.repo";
    1.17 +const static char root[] = "install";
    1.18 +
    1.19  static int
    1.20  command_install(int argc, const char *argv[])
    1.21  {
    1.22  	struct razor_rpm *rpm;
    1.23  	const char *filename = argv[0];
    1.24 +
    1.25 +	rpm = razor_rpm_open(filename);
    1.26 +	if (rpm == NULL) {
    1.27 +		fprintf(stderr, "failed to open rpm %s\n", filename);
    1.28 +		return -1;
    1.29 +	}
    1.30 +	if (razor_rpm_install(rpm, root) < 0) {
    1.31 +		fprintf(stderr, "failed to install rpm %s\n", filename);
    1.32 +		return -1;
    1.33 +	}
    1.34 +	
    1.35 +	razor_rpm_close(rpm);
    1.36 +
    1.37 +	return 0;
    1.38 +}
    1.39 +
    1.40 +static int
    1.41 +command_init(int argc, const char *argv[])
    1.42 +{
    1.43  	struct stat buf;
    1.44 -	const char root[] = "install";
    1.45 +	struct razor_set *set;
    1.46 +	char path[PATH_MAX];
    1.47  
    1.48  	if (stat(root, &buf) < 0) {
    1.49  		if (mkdir(root, 0777) < 0) {
    1.50 @@ -474,17 +499,20 @@
    1.51  		return -1;
    1.52  	}
    1.53  
    1.54 -	rpm = razor_rpm_open(filename);
    1.55 -	if (rpm == NULL) {
    1.56 -		fprintf(stderr, "failed to open rpm %s\n", filename);
    1.57 +	if (razor_create_dir(root, razor_root_path) < 0) {
    1.58 +		fprintf(stderr, "could not create %s%s\n",
    1.59 +			root, razor_root_path);
    1.60  		return -1;
    1.61  	}
    1.62 -	if (razor_rpm_install(rpm, root) < 0) {
    1.63 -		fprintf(stderr, "failed to install rpm %s\n", filename);
    1.64 +
    1.65 +	set = razor_set_create();
    1.66 +	snprintf(path, sizeof path, "%s%s/%s",
    1.67 +		 root, razor_root_path, razor_system_repo);
    1.68 +	if (razor_set_write(set, path) < 0) {
    1.69 +		fprintf(stderr, "could not write initial package set\n");
    1.70  		return -1;
    1.71  	}
    1.72 -	
    1.73 -	razor_rpm_close(rpm);
    1.74 +	razor_set_destroy(set);
    1.75  
    1.76  	return 0;
    1.77  }
    1.78 @@ -511,7 +539,8 @@
    1.79  	{ "update", "update all or specified packages", command_update },
    1.80  	{ "remove", "remove specified packages", command_remove },
    1.81  	{ "diff", "show diff between two package sets", command_diff },
    1.82 -	{ "install", "install rpm", command_install }
    1.83 +	{ "install", "install rpm", command_install },
    1.84 +	{ "init", "init razor root", command_init }
    1.85  };
    1.86  
    1.87  static int