1993-08-25 21:19:55 -04:00
|
|
|
#ifndef lint
|
1997-10-08 03:48:21 -04:00
|
|
|
static const char rcsid[] =
|
1999-08-27 21:35:59 -04:00
|
|
|
"$FreeBSD$";
|
1993-08-25 21:19:55 -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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2000-05-13 08:58:18 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
1997-10-08 03:48:21 -04:00
|
|
|
#include <err.h>
|
1993-08-25 21:19:55 -04:00
|
|
|
#include "lib.h"
|
|
|
|
|
#include "delete.h"
|
|
|
|
|
|
1999-06-24 02:33:24 -04:00
|
|
|
static char Options[] = "hvDdnfp:";
|
1993-08-25 21:19:55 -04:00
|
|
|
|
|
|
|
|
char *Prefix = NULL;
|
|
|
|
|
Boolean NoDeInstall = FALSE;
|
1994-12-05 19:51:50 -05:00
|
|
|
Boolean CleanDirs = FALSE;
|
1993-08-25 21:19:55 -04:00
|
|
|
|
1997-10-08 03:48:21 -04:00
|
|
|
static void usage __P((void));
|
|
|
|
|
|
1993-08-25 21:19:55 -04:00
|
|
|
int
|
|
|
|
|
main(int argc, char **argv)
|
|
|
|
|
{
|
1994-12-05 19:51:50 -05:00
|
|
|
int ch, error;
|
1993-08-25 21:19:55 -04:00
|
|
|
char **pkgs, **start;
|
2000-01-14 20:15:37 -05:00
|
|
|
char *pkgs_split;
|
2000-05-13 08:58:18 -04:00
|
|
|
char *tmp;
|
|
|
|
|
struct stat stat_s;
|
1993-08-25 21:19:55 -04:00
|
|
|
|
|
|
|
|
pkgs = start = argv;
|
1997-03-31 00:11:47 -05:00
|
|
|
while ((ch = getopt(argc, argv, Options)) != -1)
|
1993-08-25 21:19:55 -04:00
|
|
|
switch(ch) {
|
|
|
|
|
case 'v':
|
|
|
|
|
Verbose = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
1994-12-05 19:51:50 -05:00
|
|
|
case 'f':
|
|
|
|
|
Force = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
1993-08-25 21:19:55 -04:00
|
|
|
case 'p':
|
|
|
|
|
Prefix = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
|
NoDeInstall = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
1994-12-05 19:51:50 -05:00
|
|
|
case 'd':
|
|
|
|
|
CleanDirs = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
1993-08-25 21:19:55 -04:00
|
|
|
case 'n':
|
|
|
|
|
Fake = TRUE;
|
|
|
|
|
Verbose = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
|
case '?':
|
|
|
|
|
default:
|
1997-10-08 03:48:21 -04:00
|
|
|
usage();
|
1993-08-25 21:19:55 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1995-05-29 23:57:47 -04:00
|
|
|
argc -= optind;
|
1993-08-25 21:19:55 -04:00
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
|
|
/* Get all the remaining package names, if any */
|
2000-02-18 02:00:01 -05:00
|
|
|
while (*argv) {
|
2000-10-22 05:53:27 -04:00
|
|
|
while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
|
2000-05-14 15:54:04 -04:00
|
|
|
*pkgs_split++ = '\0';
|
|
|
|
|
/*
|
|
|
|
|
* If character after the '/' is alphanumeric, then we've found the
|
|
|
|
|
* package name. Otherwise we've come across a trailing '/' and
|
|
|
|
|
* need to continue our quest.
|
|
|
|
|
*/
|
|
|
|
|
if (isalpha(*pkgs_split)) {
|
|
|
|
|
*argv = pkgs_split;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*pkgs++ = *argv++;
|
2000-01-14 20:15:37 -05:00
|
|
|
}
|
1993-08-25 21:19:55 -04:00
|
|
|
|
|
|
|
|
/* If no packages, yelp */
|
|
|
|
|
if (pkgs == start)
|
1997-10-08 03:48:21 -04:00
|
|
|
warnx("missing package name(s)"), usage();
|
1993-08-25 21:19:55 -04:00
|
|
|
*pkgs = NULL;
|
2000-05-13 08:58:18 -04:00
|
|
|
tmp = getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR;
|
|
|
|
|
(void) stat(tmp, &stat_s);
|
|
|
|
|
if (!Fake && getuid() && geteuid() != stat_s.st_uid) {
|
|
|
|
|
if (!Force)
|
|
|
|
|
errx(1, "you do not own %s, use -f to force", tmp);
|
|
|
|
|
else
|
|
|
|
|
warnx("you do not own %s (proceeding anyways)", tmp);
|
|
|
|
|
}
|
1997-09-18 10:08:40 -04:00
|
|
|
if ((error = pkg_perform(start)) != 0) {
|
1993-08-25 21:19:55 -04:00
|
|
|
if (Verbose)
|
1997-10-08 03:48:21 -04:00
|
|
|
warnx("%d package deletion(s) failed", error);
|
1994-12-05 19:51:50 -05:00
|
|
|
return error;
|
1993-08-25 21:19:55 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1997-10-08 03:48:21 -04:00
|
|
|
static void
|
|
|
|
|
usage()
|
1993-08-25 21:19:55 -04:00
|
|
|
{
|
1997-10-08 03:48:21 -04:00
|
|
|
fprintf(stderr, "usage: pkg_delete [-vDdnf] [-p prefix] pkg-name ...\n");
|
1993-08-25 21:19:55 -04:00
|
|
|
exit(1);
|
|
|
|
|
}
|