1999-03-22 08:02:39 +03:00
|
|
|
/* $NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#ifndef lint
|
1997-06-05 16:59:18 +04:00
|
|
|
#if 0
|
1997-10-16 04:31:32 +04:00
|
|
|
static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp";
|
1997-06-05 16:59:18 +04:00
|
|
|
#else
|
1999-03-22 08:02:39 +03:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $");
|
1997-06-05 16:59:18 +04:00
|
|
|
#endif
|
1997-06-05 12:54:23 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* This is the delete module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-16 04:31:32 +04:00
|
|
|
#include <err.h>
|
1999-03-03 20:29:58 +03:00
|
|
|
#include <errno.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include "lib.h"
|
|
|
|
#include "delete.h"
|
|
|
|
|
1999-03-08 03:20:21 +03:00
|
|
|
static char Options[] = "hvDdnfFp:OrR";
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
char *Prefix = NULL;
|
1999-02-26 13:49:30 +03:00
|
|
|
char *ProgramPath = NULL;
|
1997-06-05 12:54:23 +04:00
|
|
|
Boolean NoDeInstall = FALSE;
|
|
|
|
Boolean CleanDirs = FALSE;
|
1999-01-19 20:01:56 +03:00
|
|
|
Boolean File2Pkg = FALSE;
|
1999-03-08 03:20:21 +03:00
|
|
|
Boolean Recurse_up = FALSE;
|
|
|
|
Boolean Recurse_down = FALSE;
|
1999-03-03 20:29:58 +03:00
|
|
|
Boolean OnlyDeleteFromPkgDB = FALSE;
|
1999-03-22 08:02:39 +03:00
|
|
|
lpkg_head_t pkgs;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-12 16:03:24 +04:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
1999-03-08 03:20:21 +03:00
|
|
|
fprintf(stderr, "usage: pkg_delete [-vDdnFfOrR] [-p prefix] pkg-name ...\n");
|
1998-10-12 16:03:24 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-10-16 04:31:32 +04:00
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
static int
|
|
|
|
find_fn(const char *pkg, char *data)
|
|
|
|
{
|
|
|
|
lpkg_t *lpp;
|
|
|
|
|
|
|
|
lpp=alloc_lpkg(pkg);
|
|
|
|
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ch, error;
|
1999-03-22 08:02:39 +03:00
|
|
|
lpkg_t *lpp;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-02-26 13:49:30 +03:00
|
|
|
ProgramPath = argv[0];
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
while ((ch = getopt(argc, argv, Options)) != -1)
|
|
|
|
switch(ch) {
|
|
|
|
case 'v':
|
|
|
|
Verbose = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
Force = TRUE;
|
|
|
|
break;
|
|
|
|
|
1999-01-19 20:01:56 +03:00
|
|
|
case 'F':
|
|
|
|
File2Pkg = TRUE;
|
|
|
|
break;
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
case 'p':
|
|
|
|
Prefix = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
NoDeInstall = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
CleanDirs = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
Fake = TRUE;
|
|
|
|
Verbose = TRUE;
|
|
|
|
break;
|
|
|
|
|
1999-02-26 13:49:30 +03:00
|
|
|
case 'r':
|
1999-03-08 03:20:21 +03:00
|
|
|
Recurse_up = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
Recurse_down = TRUE;
|
1999-02-26 13:49:30 +03:00
|
|
|
break;
|
|
|
|
|
1999-03-03 20:29:58 +03:00
|
|
|
case 'O':
|
|
|
|
OnlyDeleteFromPkgDB = TRUE;
|
|
|
|
break;
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
default:
|
1997-10-16 04:31:32 +04:00
|
|
|
usage();
|
1997-06-05 12:54:23 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
TAILQ_INIT(&pkgs);
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
/* Get all the remaining package names, if any */
|
1999-01-19 20:01:56 +03:00
|
|
|
if (File2Pkg)
|
|
|
|
if (pkgdb_open(1)==-1) {
|
|
|
|
err(1, "cannot open pkgdb");
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
/* Get all the remaining package names, if any */
|
1999-01-19 20:01:56 +03:00
|
|
|
while (*argv) {
|
1999-03-22 08:02:39 +03:00
|
|
|
/* pkgdb: if -F flag given, don't add pkgnames to pkgs but
|
1999-01-19 20:01:56 +03:00
|
|
|
* rather resolve the given filenames to pkgnames using
|
|
|
|
* pkgdb_retrieve, then add them.
|
|
|
|
*/
|
|
|
|
if (File2Pkg) {
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = pkgdb_retrieve(*argv);
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
if (s) {
|
|
|
|
lpp = alloc_lpkg(s);
|
|
|
|
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
|
|
|
|
} else
|
|
|
|
errx(1, "No matching pkg for %s in pkgdb.", *argv);
|
1999-01-19 20:01:56 +03:00
|
|
|
} else {
|
1999-03-22 08:02:39 +03:00
|
|
|
if (ispkgpattern(*argv)) {
|
|
|
|
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
|
|
|
|
errx(1, "No matching pkg for %s.", *argv);
|
|
|
|
}else {
|
|
|
|
lpp = alloc_lpkg(*argv);
|
|
|
|
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
|
|
|
|
}
|
1999-01-19 20:01:56 +03:00
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (File2Pkg)
|
|
|
|
pkgdb_close();
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/* If no packages, yelp */
|
1999-03-22 08:02:39 +03:00
|
|
|
if (TAILQ_FIRST(&pkgs) == NULL)
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("missing package name(s)"), usage();
|
1997-06-05 12:54:23 +04:00
|
|
|
if (!Fake && getuid() != 0)
|
1997-10-16 04:31:32 +04:00
|
|
|
errx(1, "you must be root to delete packages");
|
1999-03-03 20:29:58 +03:00
|
|
|
if (OnlyDeleteFromPkgDB) {
|
|
|
|
/* Only delete the given packages' files from pkgdb, do not touch
|
|
|
|
* the pkg itself. Used by "make reinstall" in bsd.pkg.mk
|
|
|
|
*/
|
|
|
|
char *key, *val;
|
|
|
|
|
|
|
|
if (pkgdb_open(0)==-1) {
|
|
|
|
err(1, "cannot open %s", _pkgdb_getPKGDB_FILE());
|
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
while ((key=pkgdb_iter())) {
|
|
|
|
val=pkgdb_retrieve(key);
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
lpp = TAILQ_FIRST(&pkgs);
|
|
|
|
if (lpp != NULL) {
|
|
|
|
do {
|
|
|
|
if (strcmp(val, lpp->lp_name) == 0) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Removing file %s from pkgdb\n", key);
|
|
|
|
|
|
|
|
errno=0;
|
|
|
|
if (pkgdb_remove(key)) {
|
|
|
|
if (errno)
|
|
|
|
printf("Error removing %s from pkgdb: %s\n", key, strerror(errno));
|
|
|
|
else
|
|
|
|
printf("Key %s not present in pkgdb?!\n", key);
|
|
|
|
error = 1;
|
|
|
|
}
|
1999-03-03 20:29:58 +03:00
|
|
|
}
|
1999-03-22 08:02:39 +03:00
|
|
|
|
|
|
|
lpp = TAILQ_NEXT(lpp, lp_link);
|
|
|
|
} while(lpp != NULL);
|
1999-03-03 20:29:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pkgdb_close();
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
} else if ((error = pkg_perform(&pkgs)) != 0) {
|
1997-06-05 12:54:23 +04:00
|
|
|
if (Verbose)
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("%d package deletion(s) failed", error);
|
1997-06-05 12:54:23 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|