diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
| commit | 6d946b2e52275a56dd775436f4c6b6a4c65915c8 (patch) | |
| tree | b3cb91ab036ba2deccf4af07caf09c2bf6b4b88e /usr.sbin/pkg_install/delete | |
| parent | 24a82630a20b64577bcc7454bec7288b1dbdb37a (diff) | |
Notes
Diffstat (limited to 'usr.sbin/pkg_install/delete')
| -rw-r--r-- | usr.sbin/pkg_install/delete/Makefile | 8 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/delete.h | 31 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 108 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 119 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/pkg_delete.1 | 107 |
5 files changed, 373 insertions, 0 deletions
diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile new file mode 100644 index 000000000000..16a110f92a26 --- /dev/null +++ b/usr.sbin/pkg_install/delete/Makefile @@ -0,0 +1,8 @@ +PROG= pkg_delete + +CFLAGS+= -I${.CURDIR}/../lib +LDADD+= -L${.CURDIR}/../lib -linstall + +SRCS= main.c perform.c + +.include <bsd.prog.mk> diff --git a/usr.sbin/pkg_install/delete/delete.h b/usr.sbin/pkg_install/delete/delete.h new file mode 100644 index 000000000000..2828cdf3d327 --- /dev/null +++ b/usr.sbin/pkg_install/delete/delete.h @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* + * 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 + * + * Include and define various things wanted by the delete command. + * + */ + +#ifndef _INST_DELETE_H_INCLUDE +#define _INST_DELETE_H_INCLUDE + +extern char *Prefix; +extern Boolean NoDeInstall; +extern char *Directory; +extern char *PkgName; + +#endif /* _INST_DELETE_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c new file mode 100644 index 000000000000..63bc65da0128 --- /dev/null +++ b/usr.sbin/pkg_install/delete/main.c @@ -0,0 +1,108 @@ +#ifndef lint +static char *rcsid = "$Id: main.c,v 1.4 1993/08/26 08:47:02 jkh Exp $"; +#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. + * + */ + +#include "lib.h" +#include "delete.h" + +static char Options[] = "hvDnp:"; + +char *Prefix = NULL; +Boolean NoDeInstall = FALSE; + +int +main(int argc, char **argv) +{ + int ch, err; + char **pkgs, **start; + char *prog_name = argv[0]; + + pkgs = start = argv; + while ((ch = getopt(argc, argv, Options)) != EOF) + switch(ch) { + case 'v': + Verbose = TRUE; + break; + + case 'p': + Prefix = optarg; + break; + + case 'D': + NoDeInstall = TRUE; + break; + + case 'n': + Fake = TRUE; + Verbose = TRUE; + break; + + case 'h': + case '?': + default: + usage(prog_name, NULL); + break; + } + + argc -= optind; + argv += optind; + + /* Get all the remaining package names, if any */ + /* Get all the remaining package names, if any */ + while (*argv) + *pkgs++ = *argv++; + + /* If no packages, yelp */ + if (pkgs == start) + usage(prog_name, "Missing package name(s)"); + *pkgs = NULL; + if ((err = pkg_perform(start)) != NULL) { + if (Verbose) + fprintf(stderr, "%d package deletion(s) failed.\n", err); + return err; + } + else + return 0; +} + +void +usage(const char *name, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (fmt) { + fprintf(stderr, "%s: ", name); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n\n"); + } + va_end(args); + fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name); + fprintf(stderr, "Where args are one or more of:\n\n"); + fprintf(stderr, "-v verbose\n"); + fprintf(stderr, "-p arg override prefix with arg\n"); + fprintf(stderr, "-D don't execute pkg de-install script, if any\n"); + fprintf(stderr, "-n don't actually de-install, just show steps\n"); + exit(1); +} diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c new file mode 100644 index 000000000000..2694a0ac125f --- /dev/null +++ b/usr.sbin/pkg_install/delete/perform.c @@ -0,0 +1,119 @@ +#ifndef lint +static const char *rcsid = "$Id: perform.c,v 1.1 1993/08/20 08:53:36 jkh Exp $"; +#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 main body of the delete module. + * + */ + +#include "lib.h" +#include "delete.h" + +static int pkg_do(char *); +static void sanity_check(char *); +static char LogDir[FILENAME_MAX]; + + +int +pkg_perform(char **pkgs) +{ + int i, err_cnt = 0; + + for (i = 0; pkgs[i]; i++) + err_cnt += pkg_do(pkgs[i]); + return err_cnt; +} + +static Package Plist; + +/* This is seriously ugly code following. Written very fast! */ +static int +pkg_do(char *pkg) +{ + FILE *cfile; + char home[FILENAME_MAX]; + + /* Reset some state */ + if (Plist.head) + free_plist(&Plist); + + sprintf(LogDir, "%s/%s", LOG_DIR, pkg); + if (!fexists(LogDir)) { + whinge("No such package '%s' installed.", pkg); + return 1; + } + if (!getcwd(home, FILENAME_MAX)) + barf("Unable to get current working directory!"); + if (chdir(LogDir) == FAIL) { + whinge("Unable to change directory to %s! Deinstall failed.", LogDir); + return 1; + } + sanity_check(LogDir); + if (fexists(REQUIRE_FNAME)) { + if (Verbose) + printf("Executing 'require' script.\n"); + vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */ + if (vsystem("%s %s DEINSTALL", REQUIRE_FNAME, pkg)) { + whinge("Package %s fails requirements - not deleted.", pkg); + return 1; + } + } + cfile = fopen(CONTENTS_FNAME, "r"); + if (!cfile) { + whinge("Unable to open '%s' file.", CONTENTS_FNAME); + return 1; + } + /* If we have a prefix, add it now */ + if (Prefix) + add_plist(&Plist, PLIST_CWD, Prefix); + read_plist(&Plist, cfile); + fclose(cfile); + if (!NoDeInstall && fexists(DEINSTALL_FNAME)) { + if (Fake) + printf("Would execute de-install script at this point.\n"); + else { + vsystem("chmod +x %s", DEINSTALL_FNAME); /* make sure */ + if (vsystem("%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) { + whinge("De-Install script returned error status."); + return 1; + } + } + } + if (chdir(home) == FAIL) + barf("Toto! This doesn't look like Kansas anymore!"); + delete_package(FALSE, &Plist); + if (!Fake && vsystem("%s -r %s", REMOVE_CMD, LogDir)) { + whinge("Couldn't remove log entry in %s, de-install failed.", LogDir); + return 1; + } + return 0; +} + +static void +sanity_check(char *pkg) +{ + if (!fexists(CONTENTS_FNAME)) + barf("Installed package %s has no %s file!", pkg, CONTENTS_FNAME); +} + +void +cleanup(int sig) +{ + /* Nothing to do */ +} diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 new file mode 100644 index 000000000000..d9da7f1f9866 --- /dev/null +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -0,0 +1,107 @@ +.\" +.\" 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 +.\" +.\" +.\" @(#)pkg_delete.1 +.\" +.TH pkg_delete 1 "July 18, 1993" "" "FreeBSD" + +.SH NAME +pkg_delete - a utility for deleting previously installed software package distributions. +.SH SYNOPSIS +.na +.B pkg_delete +.RB [options] +.RB "pkg-name\ [.. pkg-name]" + +.SH DESCRIPTION +The +.B pkg_delete +command is used to delete packages that have been previously installed +with the +.B pkg_add +command. + +.SH OPTIONS +.TP +The following command line options are supported. +.TP +.B \-v +Turns on verbose output. +.B "Optional." +.TP +.B \-D +If an de-installation script exists for a given package, do not execute it. +.B "Optional." +.TP +.B \-n +Don't actually de-install a package, just report the steps that +would be taken if it was. +.B "Optional." +.TP +.BI "\-p\ " prefix +Sets +.I prefix +as the directory in which to delete files from any installed packages +which do not explicitly set theirs. +.B "Optional." +.PP +.SH "TECHNICAL DETAILS" +.B +pkg_delete +does pretty much what it says. It looks for a package in /var/db/pkg +and sets about deleting the files that make up the package and, finally, +the record of the package itself. +.PP +If the package contains a +.B require +file (see +.B pkg_create +), then this is executed first with the flag +.B DEINSTALL +to see whether or not de-installation should continue (a non-zero exit +status means no). +.PP +If a +.B de-install +script exists for the package, it is executed before any files are removed. +It is this script's responsibility to clean up any additional messy details +around the package's installation, since all +.B pkg_delete +knows how to do is delete the files created in the original distribution. +The +.B de-install +script is called with the flags +.PP +.B <script> +.I pkg-name DEINSTALL +.PP +Where +.I pkg-name +is the name of the package in question and +.I DEINSTALL +is a keyword denoting that this is a deinstallation. Passing the keyword +lets you potentially write only one program/script that handles all +aspects of installation and deletion. +.PP +.SH BUGS +Sure to be some. +.SH "SEE ALSO" +.BR pkg_create "(" 1 ")," +.BR pkg_info "(" 1 ")," +.BR pkg_add "(" 1 ")," +.SH AUTHORS +Jordan Hubbard + |
