pkgtools

morpheus pkg tools
git clone git://git.2f30.org/pkgtools
Log | Files | Refs | README | LICENSE

installpkg.c (1521B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "pkg.h"
      3 
      4 static void
      5 usage(void)
      6 {
      7 	fprintf(stderr, VERSION " (c) 2014 morpheus engineers\n");
      8 	fprintf(stderr, "usage: %s [-v] [-f] [-r path] pkg...\n", argv0);
      9 	fprintf(stderr, "  -v    Enable verbose output\n");
     10 	fprintf(stderr, "  -f    Override filesystem checks and force installation\n");
     11 	fprintf(stderr, "  -r    Set alternative installation root\n");
     12 	exit(EXIT_FAILURE);
     13 }
     14 
     15 int
     16 main(int argc, char *argv[])
     17 {
     18 	struct db *db;
     19 	struct pkg *pkg;
     20 	char path[PATH_MAX];
     21 	char *root = "/";
     22 	int i;
     23 
     24 	ARGBEGIN {
     25 	case 'v':
     26 		vflag = 1;
     27 		break;
     28 	case 'f':
     29 		fflag = 1;
     30 		break;
     31 	case 'r':
     32 		root = ARGF();
     33 		break;
     34 	default:
     35 		usage();
     36 	} ARGEND;
     37 
     38 	if (argc < 1)
     39 		usage();
     40 
     41 	db = db_new(root);
     42 	if (!db)
     43 		exit(EXIT_FAILURE);
     44 	if (db_load(db) < 0) {
     45 		db_free(db);
     46 		exit(EXIT_FAILURE);
     47 	}
     48 
     49 	for (i = 0; i < argc; i++) {
     50 		if (!realpath(argv[i], path)) {
     51 			weprintf("realpath %s:", argv[i]);
     52 			db_free(db);
     53 			exit(EXIT_FAILURE);
     54 		}
     55 		if (vflag == 1)
     56 			printf("installing %s\n", path);
     57 		pkg = pkg_load_file(db, path);
     58 		if (!pkg) {
     59 			db_free(db);
     60 			exit(EXIT_FAILURE);
     61 		}
     62 		if (fflag == 0) {
     63 			if (pkg_collisions(pkg) < 0) {
     64 				printf("not installed %s\n", path);
     65 				db_free(db);
     66 				exit(EXIT_FAILURE);
     67 			}
     68 		}
     69 		if (db_add(db, pkg) < 0) {
     70 			db_free(db);
     71 			exit(EXIT_FAILURE);
     72 		}
     73 		if (pkg_install(db, pkg) < 0) {
     74 			db_free(db);
     75 			exit(EXIT_FAILURE);
     76 		}
     77 		printf("installed %s\n", path);
     78 	}
     79 
     80 	db_free(db);
     81 	return EXIT_SUCCESS;
     82 }