Index: head/usr.sbin/pkg_install/add/perform.c =================================================================== --- head/usr.sbin/pkg_install/add/perform.c (revision 113593) +++ head/usr.sbin/pkg_install/add/perform.c (revision 113594) @@ -1,567 +1,597 @@ /* * 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 add module. * */ #include __FBSDID("$FreeBSD$"); #include #include #include "lib.h" #include "add.h" #include #include #include static int pkg_do(char *); static int sanity_check(char *); static char LogDir[FILENAME_MAX]; static int zapLogDir; /* Should we delete LogDir? */ int pkg_perform(char **pkgs) { int i, err_cnt = 0; signal(SIGINT, cleanup); signal(SIGHUP, cleanup); if (AddMode == SLAVE) err_cnt = pkg_do(NULL); else { for (i = 0; pkgs[i]; i++) err_cnt += pkg_do(pkgs[i]); } return err_cnt; } static Package Plist; static char *Home; /* * This is seriously ugly code following. Written very fast! * [And subsequently made even worse.. Sigh! This code was just born * to be hacked, I guess.. :) -jkh] */ static int pkg_do(char *pkg) { char pkg_fullname[FILENAME_MAX]; char playpen[FILENAME_MAX]; char extract_contents[FILENAME_MAX]; char *where_to, *extract; FILE *cfile; int code; PackingList p; struct stat sb; - int inPlace; + int inPlace, conflictsfound, i, errcode; /* support for separate pre/post install scripts */ int new_m = 0; char pre_script[FILENAME_MAX] = INSTALL_FNAME; char post_script[FILENAME_MAX]; char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; + char *conflict[2]; + char **matched; + conflictsfound = 0; code = 0; zapLogDir = 0; LogDir[0] = '\0'; strcpy(playpen, FirstPen); inPlace = 0; /* Are we coming in for a second pass, everything already extracted? */ if (!pkg) { fgets(playpen, FILENAME_MAX, stdin); playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */ if (chdir(playpen) == FAIL) { warnx("pkg_add in SLAVE mode can't chdir to %s", playpen); return 1; } read_plist(&Plist, stdin); where_to = playpen; } /* Nope - do it now */ else { /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ if (isURL(pkg)) { if (!(Home = fileGetURL(NULL, pkg))) { warnx("unable to fetch '%s' by URL", pkg); return 1; } where_to = Home; strcpy(pkg_fullname, pkg); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); } else { strcpy(pkg_fullname, pkg); /* * Copy for sanity's sake, * could remove pkg_fullname */ if (strcmp(pkg, "-")) { if (stat(pkg_fullname, &sb) == FAIL) { warnx("can't stat package file '%s'", pkg_fullname); goto bomb; } sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); extract = extract_contents; } else { extract = NULL; sb.st_size = 100000; /* Make up a plausible average size */ } Home = make_playpen(playpen, sb.st_size * 4); if (!Home) errx(1, "unable to make playpen for %qd bytes", (long long)sb.st_size * 4); where_to = Home; /* Since we can call ourselves recursively, keep notes on where we came from */ if (!getenv("_TOP")) setenv("_TOP", Home, 1); if (unpack(pkg_fullname, extract)) { warnx( "unable to extract table of contents file from '%s' - not a package?", pkg_fullname); goto bomb; } cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); /* Extract directly rather than moving? Oh goodie! */ if (find_plist_option(&Plist, "extract-in-place")) { if (Verbose) printf("Doing in-place extraction for %s\n", pkg_fullname); p = find_plist(&Plist, PLIST_CWD); if (p) { if (!isdir(p->name) && !Fake) { if (Verbose) printf("Desired prefix of %s does not exist, creating..\n", p->name); vsystem("mkdir -p %s", p->name); if (chdir(p->name) == -1) { warn("unable to change directory to '%s'", p->name); goto bomb; } } where_to = p->name; inPlace = 1; } else { warnx( "no prefix specified in '%s' - this is a bad package!", pkg_fullname); goto bomb; } } /* * Apply a crude heuristic to see how much space the package will * take up once it's unpacked. I've noticed that most packages * compress an average of 75%, so multiply by 4 for good measure. */ if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) { warnx("projected size of %qd exceeds available free space.\n" "Please set your PKG_TMPDIR variable to point to a location with more\n" "free space and try again", (long long)sb.st_size * 4); warnx("not extracting %s\ninto %s, sorry!", pkg_fullname, where_to); goto bomb; } /* If this is a direct extract and we didn't want it, stop now */ if (inPlace && Fake) goto success; /* Finally unpack the whole mess. If extract is null we already + did so so don't bother doing it again. */ if (extract && unpack(pkg_fullname, NULL)) { warnx("unable to extract '%s'!", pkg_fullname); goto bomb; } } /* Check for sanity and dependencies */ if (sanity_check(pkg)) goto bomb; /* If we're running in MASTER mode, just output the plist and return */ if (AddMode == MASTER) { printf("%s\n", where_playpen()); write_plist(&Plist, stdout); return 0; } } /* * If we have a prefix, delete the first one we see and add this * one in place of it. */ if (Prefix) { delete_plist(&Plist, FALSE, PLIST_CWD, NULL); add_plist_top(&Plist, PLIST_CWD, Prefix); } setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1); /* Protect against old packages with bogus @name and origin fields */ if (Plist.name == NULL) Plist.name = "anonymous"; if (Plist.origin == NULL) Plist.origin = "anonymous/anonymous"; /* * See if we're already registered either with the same name (the same * version) or some other version with the same origin. */ if ((isinstalledpkg(Plist.name) || matchbyorigin(Plist.origin, NULL) != NULL) && !Force) { warnx("package '%s' or its older version already installed", Plist.name); code = 1; goto success; /* close enough for government work */ + } + + /* Now check the packing list for conflicts */ + for (p = Plist.head; p != NULL; p = p->next) { + if (p->type == PLIST_CONFLICTS) { + conflict[0] = strdup(p->name); + conflict[1] = NULL; + matched = matchinstalled(MATCH_GLOB, conflict, &errcode); + free(conflict[0]); + if (errcode == 0 && matched != NULL) + for (i = 0; matched[i] != NULL; i++) + if (isinstalledpkg(matched[i])) { + warnx("package '%s' conflicts with %s", Plist.name, + matched[i]); + conflictsfound = 1; + } + + continue; + } + } + if(conflictsfound) { + if(!Force) { + warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation"); + code = 1; + goto bomb; + } else + warnx("-f specified; proceeding anyway"); } /* Now check the packing list for dependencies */ for (p = Plist.head; p ; p = p->next) { char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Package '%s' depends on '%s'", Plist.name, p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } if (!isinstalledpkg(p->name) && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char path[FILENAME_MAX], *cp = NULL; if (!Fake) { if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) { const char *ext; ext = strrchr(pkg_fullname, '.'); if (ext == NULL) ext = ".tbz"; snprintf(path, FILENAME_MAX, "%s/%s%s", getenv("_TOP"), p->name, ext); if (fexists(path)) cp = path; else cp = fileFindByPath(pkg, p->name); if (cp) { if (Verbose) printf("Loading it from %s.\n", cp); if (vsystem("pkg_add %s'%s'", Verbose ? "-v " : "", cp)) { warnx("autoload of dependency '%s' failed%s", cp, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else { warnx("could not find package %s %s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if ((cp = fileGetURL(pkg, p->name)) != NULL) { if (Verbose) printf("Finished loading %s over FTP.\n", p->name); if (!fexists("+CONTENTS")) { warnx("autoloaded package %s has no +CONTENTS file?", p->name); if (!Force) ++code; } else if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S", Verbose ? "-v " : "")) { warnx("pkg_add of dependency '%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } else if (Verbose) printf("\t'%s' loaded successfully.\n", p->name); /* Nuke the temporary playpen */ leave_playpen(); } } else { if (Verbose) printf("and was not found%s.\n", Force ? " (proceeding anyway)" : ""); else printf("Package dependency %s for %s not found%s\n", p->name, pkg, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if (Verbose) printf(" - already installed.\n"); } if (code != 0) goto bomb; /* Look for the requirements file */ if (fexists(REQUIRE_FNAME)) { vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */ if (Verbose) printf("Running requirements file first for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) { warnx("package %s fails requirements %s", pkg_fullname, Force ? "installing anyway" : "- not installed"); if (!Force) { code = 1; goto success; /* close enough for government work */ } } } /* * Test whether to use the old method of passing tokens to installation * scripts, and set appropriate variables.. */ if (fexists(POST_INSTALL_FNAME)) { new_m = 1; sprintf(post_script, "%s", POST_INSTALL_FNAME); pre_arg[0] = '\0'; post_arg[0] = '\0'; } else { if (fexists(INSTALL_FNAME)) { sprintf(post_script, "%s", INSTALL_FNAME); sprintf(pre_arg, "PRE-INSTALL"); sprintf(post_arg, "POST-INSTALL"); } } /* If we're really installing, and have an installation file, run it */ if (!NoInstall && fexists(pre_script)) { vsystem("chmod +x %s", pre_script); /* make sure */ if (Verbose) printf("Running pre-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) { warnx("install script returned error status"); unlink(pre_script); code = 1; goto success; /* nothing to uninstall yet */ } } /* Now finally extract the entire show if we're not going direct */ if (!inPlace && !Fake) extract_plist(".", &Plist); if (!Fake && fexists(MTREE_FNAME)) { if (Verbose) printf("Running mtree for %s..\n", Plist.name); p = find_plist(&Plist, PLIST_CWD); if (Verbose) printf("mtree -U -f %s -d -e -p %s >%s\n", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL); if (!Fake) { if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL)) warnx("mtree returned a non-zero status - continuing"); } } /* Run the installation script one last time? */ if (!NoInstall && fexists(post_script)) { vsystem("chmod +x %s", post_script); /* make sure */ if (Verbose) printf("Running post-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) { warnx("install script returned error status"); unlink(post_script); code = 1; goto fail; } } /* Time to record the deed? */ if (!NoRecord && !Fake) { char contents[FILENAME_MAX]; FILE *contfile; if (getuid() != 0) warnx("not running as root - trying to record install anyway"); sprintf(LogDir, "%s/%s", LOG_DIR, Plist.name); zapLogDir = 1; if (Verbose) printf("Attempting to record package into %s..\n", LogDir); if (make_hierarchy(LogDir)) { warnx("can't record package into '%s', you're on your own!", LogDir); bzero(LogDir, FILENAME_MAX); code = 1; goto success; /* close enough for government work */ } /* Make sure pkg_info can read the entry */ vsystem("chmod a+rx %s", LogDir); move_file(".", DESC_FNAME, LogDir); move_file(".", COMMENT_FNAME, LogDir); if (fexists(INSTALL_FNAME)) move_file(".", INSTALL_FNAME, LogDir); if (fexists(POST_INSTALL_FNAME)) move_file(".", POST_INSTALL_FNAME, LogDir); if (fexists(DEINSTALL_FNAME)) move_file(".", DEINSTALL_FNAME, LogDir); if (fexists(POST_DEINSTALL_FNAME)) move_file(".", POST_DEINSTALL_FNAME, LogDir); if (fexists(REQUIRE_FNAME)) move_file(".", REQUIRE_FNAME, LogDir); if (fexists(DISPLAY_FNAME)) move_file(".", DISPLAY_FNAME, LogDir); if (fexists(MTREE_FNAME)) move_file(".", MTREE_FNAME, LogDir); sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME); contfile = fopen(contents, "w"); if (!contfile) { warnx("can't open new contents file '%s'! can't register pkg", contents); goto success; /* can't log, but still keep pkg */ } write_plist(&Plist, contfile); fclose(contfile); for (p = Plist.head; p ; p = p->next) { char *deporigin, **depnames; int i; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Trying to record dependency on package '%s'", p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) : NULL; if (depnames == NULL) { depnames = alloca(sizeof(*depnames) * 2); depnames[0] = p->name; depnames[1] = NULL; } for (i = 0; depnames[i] != NULL; i++) { sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i], REQUIRED_BY_FNAME); if (strcmp(p->name, depnames[i]) != 0) warnx("warning: package '%s' requires '%s', but '%s' " "is installed", Plist.name, p->name, depnames[i]); contfile = fopen(contents, "a"); if (!contfile) warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) warnx("cannot properly close file %s", contents); } } } if (Verbose) printf("Package %s registered in %s\n", Plist.name, LogDir); } if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) { FILE *fp; char buf[BUFSIZ]; snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name); fp = fopen(buf, "r"); if (fp) { putc('\n', stdout); while (fgets(buf, sizeof(buf), fp)) fputs(buf, stdout); putc('\n', stdout); (void) fclose(fp); } else warnx("cannot open %s as display file", buf); } goto success; bomb: code = 1; goto success; fail: /* Nuke the whole (installed) show, XXX but don't clean directories */ if (!Fake) delete_package(FALSE, FALSE, &Plist); success: /* delete the packing list contents */ free_plist(&Plist); leave_playpen(); return code; } static int sanity_check(char *pkg) { int code = 0; if (!fexists(CONTENTS_FNAME)) { warnx("package %s has no CONTENTS file!", pkg); code = 1; } else if (!fexists(COMMENT_FNAME)) { warnx("package %s has no COMMENT file!", pkg); code = 1; } else if (!fexists(DESC_FNAME)) { warnx("package %s has no DESC file!", pkg); code = 1; } return code; } void cleanup(int sig) { static int in_cleanup = 0; if (!in_cleanup) { in_cleanup = 1; if (sig) printf("Signal %d received, cleaning up..\n", sig); if (!Fake && zapLogDir && LogDir[0]) vsystem("%s -rf %s", REMOVE_CMD, LogDir); leave_playpen(); } if (sig) exit(1); } Index: head/usr.sbin/pkg_install/add/pkg_add.1 =================================================================== --- head/usr.sbin/pkg_install/add/pkg_add.1 (revision 113593) +++ head/usr.sbin/pkg_install/add/pkg_add.1 (revision 113594) @@ -1,483 +1,494 @@ .\" .\" 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_add.1 .\" $FreeBSD$ .\" .Dd November 25, 1994 .Dt PKG_ADD 1 .Os .Sh NAME .Nm pkg_add .Nd a utility for installing software package distributions .Sh SYNOPSIS .Nm .Op Fl vInfrRMS .Op Fl t Ar template .Op Fl p Ar prefix .Ar pkg-name Op Ar pkg-name ... .Sh DESCRIPTION The .Nm command is used to extract packages that have been previously created with the .Xr pkg_create 1 command. .Sh WARNING .Bf -emphasis Since the .Nm command may execute scripts or programs contained within a package file, your system may be susceptible to .Dq Em trojan horses or other subtle attacks from miscreants who create dangerous package files. .Pp You are advised to verify the competence and identity of those who provide installable package files. For extra protection, use the .Fl M flag to extract the package file, and inspect its contents and scripts to ensure it poses no danger to your system's integrity. Pay particular attention to any +INSTALL, +POST-INSTALL, +DEINSTALL, +POST-DEINSTALL, +REQUIRE or +MTREE_DIRS files, and inspect the +CONTENTS file for .Cm @cwd , .Cm @mode (check for setuid), .Cm @dirrm , .Cm @exec , and .Cm @unexec directives, and/or use the .Xr pkg_info 1 command to examine the package file. .Ef .Sh OPTIONS The following command line arguments are supported: .Bl -tag -width indent .It Ar pkg-name Op Ar pkg-name ... The named packages are installed. A package name of - will cause .Nm to read from stdin. If the packages are not found in the current working directory, .Nm will search them in each directory named by .Ev PKG_PATH . .It Fl v Turn on verbose output. .It Fl I If an installation scripts (pre-install or post-install) exist for a given package, do not execute them. .It Fl n Don't actually install a package, just report the steps that would be taken if it was. .It Fl R Do not record the installation of a package. This means that you cannot deinstall it later, so only use this option if you know what you are doing! .It Fl r Use the remote fetching feature. This will determine the appropriate objformat and release and then fetch and install the package. .It Fl f Force installation to proceed even if prerequisite packages are not installed or the requirements script fails. Although .Nm will still try to find and auto-install missing prerequisite packages, a failure to find one will not be fatal. .It Fl p Ar prefix Set .Ar prefix as the directory in which to extract files from a package. If a package has set its default directory, it will be overridden by this flag. Note that only the first .Cm @cwd directive will be replaced, since .Nm has no way of knowing which directory settings are relative and which are absolute. It is rare in any case to see more than one directory transition made, but when such does happen and you wish to have control over *all* directory transitions, then you may then wish to look into the use of .Cm MASTER and .Cm SLAVE modes (see the .Fl M and .Fl S options). .It Fl t Ar template Use .Ar template as the input to .Xr mktemp 3 when creating a .Dq staging area . By default, this is the string .Pa /var/tmp/instmp.XXXXXX , but it may be necessary to override it in the situation where space in your .Pa /var/tmp directory is limited. Be sure to leave some number of `X' characters for .Xr mktemp 3 to fill in with a unique ID. .Pp You can get a performance boost by setting the staging area .Ar template to reside on the same disk partition as target directories for package file installation; often this is .Pa /usr . .It Fl M Run in .Cm MASTER mode. This is a very specialized mode for running .Nm and is meant to be run in conjunction with .Cm SLAVE mode. When run in this mode, .Nm does no work beyond extracting the package into a temporary staging area (see the .Fl t option), reading in the packing list, and then dumping it (prefaced by the current staging area) to stdout where it may be filtered by a program such as .Xr sed 1 . When used in conjunction with .Cm SLAVE mode, it allows you to make radical changes to the package structure before acting on its contents. .It Fl S Run in .Cm SLAVE mode. This is a very specialized mode for running .Nm and is meant to be run in conjunction with .Cm MASTER mode. When run in this mode, .Nm expects the release contents to be already extracted and waiting in the staging area, the location of which is read as a string from stdin. The complete packing list is also read from stdin, and the contents then acted on as normal. .El .Pp One or more .Ar pkg-name arguments may be specified, each being either a file containing the package (these usually end with a .Dq .tbz suffix) or a URL pointing at a file available on an ftp site. Thus you may extract files directly from their anonymous ftp locations (e.g.\& .Nm .Li ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/packages/shells/bash-1.14.7.tbz ) . Note: If you wish to use .Bf -emphasis passive mode .Ef ftp in such transfers, set the variable .Bf -emphasis FTP_PASSIVE_MODE .Ef to some value in your environment. Otherwise, the more standard ACTIVE mode may be used. If .Nm consistently fails to fetch a package from a site known to work, it may be because you have a firewall that demands the usage of .Bf -emphasis passive mode .Ef ftp. .Sh TECHNICAL DETAILS The .Nm -utility is fairly simple. It extracts each package's "packing list" -into a special staging directory, parses it, -and then runs through the following sequence to fully extract the contents: +utility extracts each package's "packing list" into a special staging +directory in /tmp (or $PKG_TMPDIR if set), parses it, and then runs +through the following sequence to fully extract the contents of the package: .Bl -enum .It -Check if the package is already recorded as installed. If so, -terminate installation. +A check is made to determine if the package is already recorded as installed. +If it is, installation is terminated. .It +A check is made to determine if the package conflicts (from +.Cm @conflicts +directives, see +.Xr pkg_create 1 ) +with an already-installed package. +If it is, installation is terminated. +.It Scan all the package dependencies (from .Cm @pkgdep directives, see .Xr pkg_create 1 ) -and make sure each one is met. If not, try and find the missing -dependencies' packages and auto-install them; if they can't be found +are read from the packing list. +If any of these required packages is not currently installed, +an attempt is made to find and install it; +if the missing package cannot be found or installed, the installation is terminated. .It Search for any .Cm @option directives which control how the package is added to the system. At the time of this writing, the only currently implemented option is .Cm @option extract-in-place which will cause the package to be extracted directly into its prefix directory without moving through a staging area in .Pa /tmp . .It If .Cm @option extract-in-place is enabled, the package is now extracted directly into its final location, otherwise it is extracted into the staging area. .It If the package contains a .Ar require file (see .Xr pkg_create 1 ) , then execute it with the following arguments: .Bd -ragged -offset indent -compact .Ar pkg-name .Ar INSTALL .Ed where .Ar pkg-name is the name of the package in question and the .Ar INSTALL keyword denotes this as an installation requirements check (useful if you want to have one script serving multiple functions). .It If a .Ar pre-install script exists for the package, it is then executed with the following arguments: .Bd -ragged -offset indent -compact .Cm script .Ar pkg-name .Ar PRE-INSTALL .Ed .Pp where .Ar pkg-name is the name of the package in question and .Ar PRE-INSTALL is a keyword denoting this as the preinstallation phase. .Pp .Sy Note : The .Ar PRE-INSTALL keyword will not appear if separate scripts for pre-install and post-install are given during package creation time (using the .Fl i and .Fl I flags to .Xr pkg_create 1 ) . .It If .Cm @option extract-in-place is not used, then the packing list (this is the .Pa +CONTENTS file) is now used as a guide for moving (or copying, as necessary) files from the staging area into their final locations. .It If the package contains an .Ar mtreefile file (see .Xr pkg_create 1 ) , then mtree is invoked as: .Bd -ragged -offset indent -compact .Cm mtree .Fl u .Fl f .Ar mtreefile .Fl d .Fl e .Fl p .Pa prefix .Ed where .Pa prefix is either the prefix specified with the .Fl p flag or, if no .Fl p flag was specified, the name of the first directory named by a .Cm @cwd directive within this package. .It If a .Ar post-install script exists for the package, it is then executed as .Bd -ragged -offset indent -compact .Cm script .Ar pkg-name .Ar POST-INSTALL .Ed where .Ar pkg-name is the name of the package in question and .Ar POST-INSTALL is a keyword denoting this as the post-installation phase. .Pp .Sy Note : The .Ar POST-INSTALL keyword will not appear if separate scripts for pre-install and post-install are given during package creation time (using the .Fl i and .Fl I flags to .Xr pkg_create 1 ) . .Pp Reasoning behind passing keywords such as .Ar POST-INSTALL and .Ar PRE-INSTALL is that this allows you to write a single .Ar install script that does both .Dq before and after actions. But, separating the functionality is more advantageous and easier from a maintenance viewpoint. .It After installation is complete, a copy of the packing list, .Ar deinstall script, description, and display files are copied into .Pa /var/db/pkg/ for subsequent possible use by .Xr pkg_delete 1 . Any package dependencies are recorded in the other packages' .Pa /var/db/pkg//+REQUIRED_BY file (if the environment variable PKG_DBDIR is set, this overrides the .Pa /var/db/pkg/ path shown above). .It Finally, the staging area is deleted and the program terminates. .El .Pp All the scripts are called with the environment variable .Ev PKG_PREFIX set to the installation prefix (see the .Fl p option above). This allows a package author to write a script that reliably performs some action on the directory where the package is installed, even if the user might change it with the .Fl p flag to .Cm pkg_add . .Sh ENVIRONMENT The value of the .Ev PKG_PATH is used if a given package can't be found. The environment variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. .Pp The environment variable .Ev PKG_DBDIR -specifies an alternative location for the installed package database. +specifies an alternative location for the installed package database, +default location is +.Pa /var/db/pkg . .Pp The environment variables .Ev PKG_TMPDIR and .Ev TMPDIR , in that order, are taken to name temporary directories where .Nm will attempt to create its staging area in. If these variables are not present or if the directories named lack sufficient space, then .Nm will use the first of .Pa /var/tmp , .Pa /tmp or .Pa /usr/tmp with sufficient space. .Pp The environment variable .Ev PACKAGEROOT specifies an alternate location for .Nm to fetch from. The fetch URL is built using this environment variable and the automatic directory logic that .Nm uses when the .Fl r option is invoked. An example setting would be .Qq Li ftp://ftp3.FreeBSD.org . .Pp The environment variable .Ev PACKAGESITE specifies an alternate location for .Nm to fetch from. This variable subverts the automatic directory logic that .Nm uses when the .Fl r option is invoked. Thus it should be a complete URL to the remote package file(s). .Sh FILES .Bl -tag -width /var/db/pkg -compact .It Pa /var/tmp Temporary directory for creating the staging area, if environmental variables .Ev PKG_TMPDIR or .Ev TMPDIR do not point to a suitable directory. .It Pa /tmp Next choice if .Pa /var/tmp does not exist or has insufficient space. .It Pa /usr/tmp Last choice if .Pa /var/tmp and .Pa /tmp are not suitable for creating the staging area. .It Pa /var/db/pkg Default location of the installed package database. .El .Sh SEE ALSO .Xr pkg_create 1 , .Xr pkg_delete 1 , .Xr pkg_info 1 , .Xr pkg_version 1 , .Xr mktemp 3 , .Xr sysconf 3 , .Xr mtree 8 .Sh AUTHORS .An Jordan Hubbard .Sh CONTRIBUTORS .An John Kohl Aq jtk@rational.com .Sh BUGS Hard links between files in a distribution are only preserved if either (1) the staging area is on the same file system as the target directory of all the links to the file, or (2) all the links to the file are bracketed by .Cm @cwd directives in the contents file, .Em and the link names are extracted with a single .Cm tar command (not split between invocations due to exec argument-space limitations--this depends on the value returned by .Fn sysconf _SC_ARG_MAX ) . .Pp Sure to be others. Index: head/usr.sbin/pkg_install/create/create.h =================================================================== --- head/usr.sbin/pkg_install/create/create.h (revision 113593) +++ head/usr.sbin/pkg_install/create/create.h (revision 113594) @@ -1,53 +1,54 @@ /* $FreeBSD$ */ /* * 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 create command. * */ #ifndef _INST_CREATE_H_INCLUDE #define _INST_CREATE_H_INCLUDE extern char *Prefix; extern char *Comment; extern char *Desc; extern char *Display; extern char *Install; extern char *PostInstall; extern char *DeInstall; extern char *PostDeInstall; extern char *Contents; extern char *Require; extern char *SrcDir; extern char *ExcludeFrom; extern char *Mtree; extern char *Pkgdeps; +extern char *Conflicts; extern char *Origin; extern char *InstalledPkg; extern char PlayPen[]; extern int Dereference; extern int PlistOnly; enum zipper {NONE, GZIP, BZIP, BZIP2 }; extern enum zipper Zipper; void check_list(const char *, Package *); int pkg_perform(char **); void copy_plist(const char *, Package *); #endif /* _INST_CREATE_H_INCLUDE */ Index: head/usr.sbin/pkg_install/create/main.c =================================================================== --- head/usr.sbin/pkg_install/create/main.c (revision 113593) +++ head/usr.sbin/pkg_install/create/main.c (revision 113594) @@ -1,205 +1,210 @@ /* * FreeBSD install - a package for the installation and maintainance * of non-core utilities. * * Jordan K. Hubbard * 18 July 1993 * * This is the create module. * */ #include __FBSDID("$FreeBSD$"); #include #include "lib.h" #include "create.h" -static char Options[] = "YNOhjvyzf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:"; +static char Options[] = "YNOhjvyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:o:b:"; char *Prefix = NULL; char *Comment = NULL; char *Desc = NULL; char *SrcDir = NULL; char *Display = NULL; char *Install = NULL; char *PostInstall = NULL; char *DeInstall = NULL; char *PostDeInstall = NULL; char *Contents = NULL; char *Require = NULL; char *ExcludeFrom = NULL; char *Mtree = NULL; char *Pkgdeps = NULL; +char *Conflicts = NULL; char *Origin = NULL; char *InstalledPkg = NULL; char PlayPen[FILENAME_MAX]; int Dereference = FALSE; int PlistOnly = FALSE; enum zipper Zipper = GZIP; static void usage __P((void)); int main(int argc, char **argv) { int ch; char **pkgs, **start, *tmp; pkgs = start = argv; while ((ch = getopt(argc, argv, Options)) != -1) switch(ch) { case 'v': Verbose = TRUE; break; case 'N': AutoAnswer = NO; break; case 'Y': AutoAnswer = YES; break; case 'O': PlistOnly = TRUE; break; case 'p': Prefix = optarg; break; case 's': SrcDir = optarg; break; case 'f': Contents = optarg; break; + case 'C': + Conflicts = optarg; + break; + case 'c': Comment = optarg; break; case 'd': Desc = optarg; break; case 'i': Install = optarg; break; case 'I': PostInstall = optarg; break; case 'k': DeInstall = optarg; break; case 'K': PostDeInstall = optarg; break; case 'r': Require = optarg; break; case 't': strlcpy(PlayPen, optarg, sizeof(PlayPen)); break; case 'X': ExcludeFrom = optarg; break; case 'h': Dereference = TRUE; break; case 'D': Display = optarg; break; case 'm': Mtree = optarg; break; case 'P': Pkgdeps = optarg; break; case 'o': Origin = optarg; break; case 'y': case 'j': Zipper = BZIP2; break; case 'z': Zipper = GZIP; break; case 'b': InstalledPkg = optarg; while ((tmp = strrchr(optarg, (int)'/')) != NULL) { *tmp++ = '\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(*tmp)) { InstalledPkg = tmp; break; } } break; case '?': default: usage(); break; } argc -= optind; argv += optind; /* Get all the remaining package names, if any */ while (*argv) *pkgs++ = *argv++; /* If no packages, yelp */ if ((pkgs == start) && (InstalledPkg == NULL)) warnx("missing package name"), usage(); *pkgs = NULL; if ((start[0] != NULL) && (start[1] != NULL)) { warnx("only one package name allowed ('%s' extraneous)", start[1]); usage(); } if (start[0] == NULL) start[0] = InstalledPkg; if (!pkg_perform(start)) { if (Verbose) warnx("package creation failed"); return 1; } else return 0; } static void usage() { fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", -"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]", -" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ", -" [-t template] [-X excludefile] [-D displayfile] ", -" [-m mtreefile] [-o origin] -c comment -d description ", -" -f packlist pkg-filename", +"usage: pkg_create [-YNOhvy] [-P pkgs] [-C conflicts] [-p prefix] [-f contents] ", +" [-i iscript] [-I piscript] [-k dscript] [-K pdscript] ", +" [-r rscript] [-t template] [-X excludefile] ", +" [-D displayfile] [-m mtreefile] [-o origin] ", +" -c comment -d description -f packlist pkg-filename", " pkg_create [-YNhvy] -b pkg-name [pkg-filename]"); exit(1); } Index: head/usr.sbin/pkg_install/create/perform.c =================================================================== --- head/usr.sbin/pkg_install/create/perform.c (revision 113593) +++ head/usr.sbin/pkg_install/create/perform.c (revision 113594) @@ -1,460 +1,476 @@ /* * 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 create module. * */ #include __FBSDID("$FreeBSD$"); #include "lib.h" #include "create.h" #include #include #include #include #include #include #include static void sanity_check(void); static void make_dist(const char *, const char *, const char *, Package *); static int create_from_installed(const char *, const char *); static char *home; int pkg_perform(char **pkgs) { char *pkg = *pkgs; /* Only one arg to create */ char *cp; FILE *pkg_in, *fp; Package plist; int len; const char *suf; /* Preliminary setup */ if (InstalledPkg == NULL) sanity_check(); if (Verbose && !PlistOnly) printf("Creating package %s\n", pkg); /* chop suffix off if already specified, remembering if we want to compress */ len = strlen(pkg); if (len > 4) { if (!strcmp(&pkg[len - 4], ".tbz")) { Zipper = BZIP2; pkg[len - 4] = '\0'; } else if (!strcmp(&pkg[len - 4], ".tgz")) { Zipper = GZIP; pkg[len - 4] = '\0'; } else if (!strcmp(&pkg[len - 4], ".tar")) { Zipper = NONE; pkg[len - 4] = '\0'; } } if (Zipper == BZIP2) { suf = "tbz"; setenv("BZIP2", "--best", 0); } else if (Zipper == GZIP) { suf = "tgz"; setenv("GZIP", "-9", 0); } else suf = "tar"; if (InstalledPkg != NULL) return (create_from_installed(pkg, suf)); get_dash_string(&Comment); get_dash_string(&Desc); if (!strcmp(Contents, "-")) pkg_in = stdin; else { pkg_in = fopen(Contents, "r"); if (!pkg_in) { cleanup(0); errx(2, "%s: unable to open contents file '%s' for input", __func__, Contents); } } plist.head = plist.tail = NULL; /* Stick the dependencies, if any, at the top */ if (Pkgdeps) { char **deps, *deporigin; int i; int ndeps = 0; if (Verbose && !PlistOnly) printf("Registering depends:"); /* Count number of dependencies */ for (cp = Pkgdeps; cp != NULL && *cp != '\0'; cp = strpbrk(++cp, " \t\n")) { ndeps++; } if (ndeps != 0) { /* Create easy to use NULL-terminated list */ deps = alloca(sizeof(*deps) * ndeps + 1); if (deps == NULL) { errx(2, "%s: alloca() failed", __func__); /* Not reached */ } for (i = 0; Pkgdeps;) { cp = strsep(&Pkgdeps, " \t\n"); if (*cp) { deps[i] = cp; i++; } } ndeps = i; deps[ndeps] = NULL; sortdeps(deps); for (i = 0; i < ndeps; i++) { deporigin = strchr(deps[i], ':'); if (deporigin != NULL) { *deporigin = '\0'; add_plist_top(&plist, PLIST_DEPORIGIN, ++deporigin); } add_plist_top(&plist, PLIST_PKGDEP, deps[i]); if (Verbose && !PlistOnly) printf(" %s", deps[i]); } } if (Verbose && !PlistOnly) printf(".\n"); } + /* Put the conflicts directly after the dependencies, if any */ + if (Conflicts) { + if (Verbose && !PlistOnly) + printf("Registering conflicts:"); + while (Conflicts) { + cp = strsep(&Conflicts, " \t\n"); + if (*cp) { + add_plist(&plist, PLIST_CONFLICTS, cp); + if (Verbose && !PlistOnly) + printf(" %s", cp); + } + } + if (Verbose && !PlistOnly) + printf(".\n"); + } + /* If a SrcDir override is set, add it now */ if (SrcDir) { if (Verbose && !PlistOnly) printf("Using SrcDir value of %s\n", SrcDir); add_plist(&plist, PLIST_SRC, SrcDir); } /* Slurp in the packing list */ read_plist(&plist, pkg_in); /* Prefix should add an @cwd to the packing list */ if (Prefix) add_plist_top(&plist, PLIST_CWD, Prefix); /* Add the origin if asked, at the top */ if (Origin) add_plist_top(&plist, PLIST_ORIGIN, Origin); /* * Run down the list and see if we've named it, if not stick in a name * at the top. */ if (find_plist(&plist, PLIST_NAME) == NULL) add_plist_top(&plist, PLIST_NAME, basename(pkg)); if (asprintf(&cp, "PKG_FORMAT_REVISION:%d.%d", PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR) == -1) { errx(2, "%s: asprintf() failed", __func__); } add_plist_top(&plist, PLIST_COMMENT, cp); free(cp); /* * We're just here for to dump out a revised plist for the FreeBSD ports * hack. It's not a real create in progress. */ if (PlistOnly) { check_list(home, &plist); write_plist(&plist, stdout); exit(0); } /* Make a directory to stomp around in */ home = make_playpen(PlayPen, 0); signal(SIGINT, cleanup); signal(SIGHUP, cleanup); /* Make first "real contents" pass over it */ check_list(home, &plist); (void) umask(022); /* * Make sure gen'ed directories, files don't have * group or other write bits. */ /* copy_plist(home, &plist); */ /* mark_plist(&plist); */ /* Now put the release specific items in */ add_plist(&plist, PLIST_CWD, "."); write_file(COMMENT_FNAME, Comment); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, COMMENT_FNAME); write_file(DESC_FNAME, Desc); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, DESC_FNAME); if (Install) { copy_file(home, Install, INSTALL_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, INSTALL_FNAME); } if (PostInstall) { copy_file(home, PostInstall, POST_INSTALL_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, POST_INSTALL_FNAME); } if (DeInstall) { copy_file(home, DeInstall, DEINSTALL_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME); } if (PostDeInstall) { copy_file(home, PostDeInstall, POST_DEINSTALL_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, POST_DEINSTALL_FNAME); } if (Require) { copy_file(home, Require, REQUIRE_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, REQUIRE_FNAME); } if (Display) { copy_file(home, Display, DISPLAY_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, DISPLAY_FNAME); add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME); } if (Mtree) { copy_file(home, Mtree, MTREE_FNAME); add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, MTREE_FNAME); add_plist(&plist, PLIST_MTREE, MTREE_FNAME); } /* Finally, write out the packing list */ fp = fopen(CONTENTS_FNAME, "w"); if (!fp) { cleanup(0); errx(2, "%s: can't open file %s for writing", __func__, CONTENTS_FNAME); } write_plist(&plist, fp); if (fclose(fp)) { cleanup(0); errx(2, "%s: error while closing %s", __func__, CONTENTS_FNAME); } /* And stick it into a tar ball */ make_dist(home, pkg, suf, &plist); /* Cleanup */ free(Comment); free(Desc); free_plist(&plist); leave_playpen(); return TRUE; /* Success */ } static void make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist) { char tball[FILENAME_MAX]; PackingList p; int ret; const char *args[50]; /* Much more than enough. */ int nargs = 0; int pipefds[2]; FILE *totar; pid_t pid; const char *cname; args[nargs++] = "tar"; /* argv[0] */ if (*pkg == '/') snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suff); else snprintf(tball, FILENAME_MAX, "%s/%s.%s", homedir, pkg, suff); args[nargs++] = "-c"; args[nargs++] = "-f"; args[nargs++] = tball; if (strchr(suff, 'z')) { /* Compress/gzip/bzip2? */ if (Zipper == BZIP2) { args[nargs++] = "-j"; cname = "bzip'd "; } else { args[nargs++] = "-z"; cname = "gzip'd "; } } else { cname = ""; } if (Dereference) args[nargs++] = "-h"; if (ExcludeFrom) { args[nargs++] = "-X"; args[nargs++] = ExcludeFrom; } args[nargs++] = "-T"; /* Take filenames from file instead of args. */ args[nargs++] = "-"; /* Use stdin for the file. */ args[nargs] = NULL; if (Verbose) printf("Creating %star ball in '%s'\n", cname, tball); /* Set up a pipe for passing the filenames, and fork off a tar process. */ if (pipe(pipefds) == -1) { cleanup(0); errx(2, "%s: cannot create pipe", __func__); } if ((pid = fork()) == -1) { cleanup(0); errx(2, "%s: cannot fork process for tar", __func__); } if (pid == 0) { /* The child */ dup2(pipefds[0], 0); close(pipefds[0]); close(pipefds[1]); execv("/usr/bin/tar", (char * const *)(uintptr_t)args); cleanup(0); errx(2, "%s: failed to execute tar command", __func__); } /* Meanwhile, back in the parent process ... */ close(pipefds[0]); if ((totar = fdopen(pipefds[1], "w")) == NULL) { cleanup(0); errx(2, "%s: fdopen failed", __func__); } fprintf(totar, "%s\n", CONTENTS_FNAME); fprintf(totar, "%s\n", COMMENT_FNAME); fprintf(totar, "%s\n", DESC_FNAME); if (Install) fprintf(totar, "%s\n", INSTALL_FNAME); if (PostInstall) fprintf(totar, "%s\n", POST_INSTALL_FNAME); if (DeInstall) fprintf(totar, "%s\n", DEINSTALL_FNAME); if (PostDeInstall) fprintf(totar, "%s\n", POST_DEINSTALL_FNAME); if (Require) fprintf(totar, "%s\n", REQUIRE_FNAME); if (Display) fprintf(totar, "%s\n", DISPLAY_FNAME); if (Mtree) fprintf(totar, "%s\n", MTREE_FNAME); for (p = plist->head; p; p = p->next) { if (p->type == PLIST_FILE) fprintf(totar, "%s\n", p->name); else if (p->type == PLIST_CWD || p->type == PLIST_SRC) fprintf(totar, "-C\n%s\n", p->name); else if (p->type == PLIST_IGNORE) p = p->next; } fclose(totar); wait(&ret); /* assume either signal or bad exit is enough for us */ if (ret) { cleanup(0); errx(2, "%s: tar command failed with code %d", __func__, ret); } } static void sanity_check() { if (!Comment) { cleanup(0); errx(2, "%s: required package comment string is missing (-c comment)", __func__); } if (!Desc) { cleanup(0); errx(2, "%s: required package description string is missing (-d desc)", __func__); } if (!Contents) { cleanup(0); errx(2, "%s: required package contents list is missing (-f [-]file)", __func__); } } /* Clean up those things that would otherwise hang around */ void cleanup(int sig) { int in_cleanup = 0; if (!in_cleanup) { in_cleanup = 1; leave_playpen(); } if (sig) exit(1); } static int create_from_installed(const char *pkg, const char *suf) { FILE *fp; Package plist; char homedir[MAXPATHLEN], log_dir[FILENAME_MAX]; snprintf(log_dir, sizeof(log_dir), "%s/%s", LOG_DIR, InstalledPkg); if (!fexists(log_dir)) { warnx("can't find package '%s' installed!", InstalledPkg); return FALSE; } getcwd(homedir, sizeof(homedir)); if (chdir(log_dir) == FAIL) { warnx("can't change directory to '%s'!", log_dir); return FALSE; } /* Suck in the contents list */ plist.head = plist.tail = NULL; fp = fopen(CONTENTS_FNAME, "r"); if (!fp) { warnx("unable to open %s file", CONTENTS_FNAME); return FALSE; } read_plist(&plist, fp); fclose(fp); (const char *)Install = isfile(INSTALL_FNAME) ? INSTALL_FNAME : NULL; (const char *)PostInstall = isfile(POST_INSTALL_FNAME) ? POST_INSTALL_FNAME : NULL; (const char *)DeInstall = isfile(DEINSTALL_FNAME) ? DEINSTALL_FNAME : NULL; (const char *)PostDeInstall = isfile(POST_DEINSTALL_FNAME) ? POST_DEINSTALL_FNAME : NULL; (const char *)Require = isfile(REQUIRE_FNAME) ? REQUIRE_FNAME : NULL; (const char *)Display = isfile(DISPLAY_FNAME) ? DISPLAY_FNAME : NULL; (const char *)Mtree = isfile(MTREE_FNAME) ? MTREE_FNAME : NULL; make_dist(homedir, pkg, suf, &plist); free_plist(&plist); return TRUE; } Index: head/usr.sbin/pkg_install/create/pkg_create.1 =================================================================== --- head/usr.sbin/pkg_install/create/pkg_create.1 (revision 113593) +++ head/usr.sbin/pkg_install/create/pkg_create.1 (revision 113594) @@ -1,545 +1,558 @@ .\" .\" 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_create.1 .\" $FreeBSD$ .\" .\" hacked up by John Kohl for NetBSD--fixed a few bugs, extended keywords, .\" added dependency tracking, etc. .\" .\" [jkh] Took John's changes back and made some additional extensions for .\" better integration with FreeBSD's new ports collection. .\" .Dd April 21, 1995 .Dt PKG_CREATE 1 .Os .Sh NAME .Nm pkg_create .Nd a utility for creating software package distributions .Sh SYNOPSIS .Nm .Op Fl YNOhjvyz +.Op Fl C Ar conflicts .Op Fl P Ar pkgs .Op Fl p Ar prefix .Op Fl f Ar contents .Op Fl i Ar iscript .Op Fl I Ar piscript .Op Fl k Ar dscript .Op Fl K Ar pdscript .Op Fl r Ar rscript .Op Fl s Ar srcdir .Op Fl t Ar template .Op Fl X Ar excludefile .Op Fl D Ar displayfile .Op Fl m Ar mtreefile .Op Fl o Ar originpath .Fl c Ar comment .Fl d Ar description .Fl f Ar packlist .Ar pkg-filename .Nm .Op Fl YNhvy .Fl b Ar pkg-name .Op Ar pkg-filename .Sh DESCRIPTION The .Nm command is used to create packages that will subsequently be fed to one of the package extraction/info utilities. The input description and command line arguments for the creation of a package are not really meant to be human-generated, though it is easy enough to do so. It is more expected that you will use a front-end tool for the job rather than muddling through it yourself. Nonetheless, a short description of the input syntax is included in this document. .Sh OPTIONS The following command line options are supported: .Bl -tag -width indent .It Fl f Ar packinglist Fetch .Dq packing list for package from the file .Ar packinglist or .Cm stdin if .Ar packinglist is a .Cm - (dash). .It Fl c Xo .Oo Fl Oc Ns Ar desc .Xc Fetch package .Dq one line description from file .Ar desc or, if preceded by .Cm - , the argument itself. This string should also give some idea of which version of the product (if any) the package represents. .It Fl d Xo .Oo Fl Oc Ns Ar desc .Xc Fetch long description for package from file .Ar desc or, if preceded by .Cm - , the argument itself. .It Fl Y Assume a default answer of `Yes' for any questions asked. .It Fl N Assume a default answer of `No' for any questions asked. .It Fl O Go into a `packing list Only' mode. This is a custom hack for the .Fx .Em "Ports Collection" and is used to do `fake pkg_add' operations when a port is installed. In such cases, it is necessary to know what the final, adjusted packing list will look like. .It Fl v Turn on verbose output. .It Fl h Force tar to follow symbolic links, so that the files they point to are dumped, rather than the links themselves. .It Fl i Ar iscript Set .Ar iscript to be the pre-install procedure for the package. This can be any executable program (or shell script). It will be invoked automatically when the package is later installed. It will be passed the package's name as the first argument. .Pp .Sy Note : if the .Fl I option is not given, this script will serve as both the pre-install and the post-install script for the package, differentiating between the functionality by passing the keywords .Ar PRE-INSTALL and .Ar POST-INSTALL respectively, along with the package's name. .It Fl I Ar piscript Set .Ar piscript to be the post-install procedure for the package. This can be any executable program (or shell script). It will be invoked automatically when the package is later installed. It will be passed the package's name as the first argument. +.It Fl C Ar conflicts +Set the initial package conflict list to +.Ar conflicts . +This is assumed to be a whitespace separated list of package names +and is meant as a convenient shorthand for specifying multiple +.Cm @conflicts +directives in the packing list (see PACKING LIST DETAILS section below). .It Fl P Ar pkgs Set the initial package dependency list to .Ar pkgs . This is assumed to be a whitespace separated list of package names and is meant as a convenient shorthand for specifying multiple .Cm @pkgdep directives in the packing list (see .Sx "PACKING LIST DETAILS" section below). Each argument from the .Ar pkgs list could be in the form .Ar pkgname Ns Op : Ns Ar pkgorigin , where optional .Ar pkgorigin element denotes origin of each dependency from the list and it is recorded into the packing list along with the .Ar pkgname using .Cm @comment directive. .It Fl p Ar prefix Set .Ar prefix as the initial directory .Dq base to start from in selecting files for the package. .It Fl k Ar dscript Set .Ar dscript to be the de-install procedure for the package. This can be any executable program (or shell script). It will be invoked automatically when the package is later (if ever) de-installed. It will be passed the package's name as the first argument. .Pp .Sy Note : if the .Fl K option is not given, this script will serve as both the de-install and the post-deinstall script for the package, differentiating between the functionality by passing the keywords .Ar DEINSTALL and .Ar POST-DEINSTALL respectively, along with the package's name. .It Fl K Ar pdscript Set .Ar pdscript to be the post-deinstall procedure for the package. This can be any executable program (or shell script). It will be invoked automatically when the package is later de-installed. It will be passed the package's name as the first argument. .It Fl r Ar rscript Set .Ar rscript to be the .Dq requirements procedure for the package. This can be any executable program (or shell script). It will be invoked automatically at installation/deinstallation time to determine whether or not installation/deinstallation should proceed. To differentiate between installation and deinstallation, the keywords .Ar INSTALL and .Ar DEINSTALL are passed respectively, along with the package's name. .It Fl s Ar srcdir .Ar srcdir will override the value of .Cm @cwd during package creation. .It Fl t Ar template Use .Ar template as the input to .Xr mktemp 3 . By default, this is the string .Pa /tmp/instmp.XXXXXX , but it may be necessary to override it in the situation where space in your .Pa /tmp directory is limited. Be sure to leave some number of `X' characters for .Xr mktemp 3 to fill in with a unique ID. .It Fl X Ar excludefile Pass .Ar excludefile as a .Fl exclude-from argument to .Cm tar when creating final package. See .Cm tar man page (or run .Cm tar with .Fl -help flag) for further information on using this flag. .It Fl D Ar displayfile Display the file (by concatenating it to stdout) after installing the package. Useful for things like legal notices on almost-free software, etc. .It Fl m Ar mtreefile Run .Xr mtree 8 with input from mtreefile before the package is installed. Mtree is invoked as .Cm mtree .Fl u .Fl f .Ar mtreefile .Fl d .Fl e .Fl p .Pa prefix , where .Pa prefix is the name of the first directory named by a .Cm @cwd directive. .It Fl o Ar originpath Record an .Ar originpath , as location of the port from which package has been created in the .Fx .Em "Ports Collection" . It should be in the form .Pa MASTERCATEGORY/PORTDIR . .It Fl j Use .Xr bzip2 1 utility to compress package tarball instead of .Xr gzip 1 . Please note that this option is a NO-OP if the format of the resulting archive is explicitly specified by the recognizable suffix of .Ar pkg-filename . Currently .Nm recognizes the following suffixes: .Pa .tbz , .tgz and .Pa .tar . .It Fl y Compatibility synonym for .Fl j . .It Fl z Use .Xr gzip 1 utility to compress package tarball. .It Fl b Ar pkg-name Create package file from a locally installed package named .Ar pkg-name . If the .Ar pkg-filename is not specified, then resulting archive will be created in the current directory and named .Ar pkg-name with an appropriate extraction suffix applied. .El .Sh PACKING LIST DETAILS The .Dq packing list format (see .Fl f ) is fairly simple, being nothing more than a single column of filenames to include in the package. However, since absolute pathnames are generally a bad idea for a package that could be installed potentially anywhere, there is another method of specifying where things are supposed to go and, optionally, what ownership and mode information they should be installed with. This is done by embedding specialized command sequences in the packing list. Briefly described, these sequences are: .Bl -tag -width indent -compact .It Cm @cwd Ar directory Set the internal directory pointer to point to .Ar directory . All subsequent filenames will be assumed relative to this directory. Note: .Cm @cd is also an alias for this command. .It Cm @srcdir Ar directory Set the internal directory pointer for _creation only_ to .Ar directory . That is to say that it overrides .Cm @cwd for package creation but not extraction. .It Cm @exec Ar command Execute .Ar command as part of the unpacking process. If .Ar command contains any of the following sequences somewhere in it, they will be expanded inline. For the following examples, assume that .Cm @cwd is set to .Pa /usr/local and the last extracted file was .Pa bin/emacs . .Bl -tag -width indent -compact .It Cm "%F" Expands to the last filename extracted (as specified), in the example case .Pa bin/emacs .It Cm "\&%D" Expand to the current directory prefix, as set with .Cm @cwd , in the example case .Pa /usr/local . .It Cm "\&%B" Expand to the .Dq basename of the fully qualified filename, that is the current directory prefix, plus the last filespec, minus the trailing filename. In the example case, that would be .Pa /usr/local/bin . .It Cm "%f" Expand to the filename part of the fully qualified name, or the converse of .Cm \&%B , being in the example case, .Pa emacs . .El .It Cm @unexec Ar command Execute .Ar command as part of the deinstallation process. Expansion of special .Cm % sequences is the same as for .Cm @exec . This command is not executed during the package add, as .Cm @exec is, but rather when the package is deleted. This is useful for deleting links and other ancillary files that were created as a result of adding the package, but not directly known to the package's table of contents (and hence not automatically removable). The advantage of using .Cm @unexec over a deinstallation script is that you can use the .Dq special sequence expansion to get at files regardless of where they've been potentially redirected (see .Fl p ) . .It Cm @mode Ar mode Set default permission for all subsequently extracted files to .Ar mode . Format is the same as that used by the .Cm chmod command (well, considering that it's later handed off to it, that's no surprise). Use without an arg to set back to default (extraction) permissions. .It Cm @option Ar option Set internal package options, the only two currently supported ones being .Ar extract-in-place , which tells the pkg_add command not to extract the package's tarball into a staging area but rather directly into the target hierarchy (this is typically meant to be used only by distributions or other special package types), and .Ar preserve , which tells pkg_add to move any existing files out of the way, preserving the previous contents (which are also resurrected on pkg_delete, so caveat emptor). .It Cm @owner Ar user Set default ownership for all subsequently extracted files to .Ar user . Use without an arg to set back to default (extraction) ownership. .It Cm @group Ar group Set default group ownership for all subsequently extracted files to .Ar group . Use without an arg to set back to default (extraction) group ownership. .It Cm @comment Ar string Imbed a comment in the packing list. Useful in trying to document some particularly hairy sequence that may trip someone up later. .It Cm @ignore Used internally to tell extraction to ignore the next file (don't copy it anywhere), as it's used for some special purpose. .It Cm @ignore_inst Similar to .Cm @ignore , but the ignoring of the next file is delayed one evaluation cycle. This makes it possible to use this directive in the .Ar packinglist file, so you can pack a specialized datafile in with a distribution for your install script (or something) yet have the installer ignore it. .It Cm @name Ar name Set the name of the package. This is mandatory and is usually put at the top. This name is potentially different from the name of the file it came in, and is used when keeping track of the package for later deinstallation. Note that .Nm will derive this field from the package name and add it automatically if none is given. .It Cm @dirrm Ar name Declare directory .Pa name to be deleted at deinstall time. By default, directories created by a package installation are not deleted when the package is deinstalled; this provides an explicit directory cleanup method. This directive should appear at the end of the package list. If more than one .Cm @dirrm directives are used, the directories are removed in the order specified. The .Pa name directory will not be removed unless it is empty. .It Cm @mtree Ar name Declare .Pa name as an .Xr mtree 8 input file to be used at install time (see .Fl m above). Only the first .Cm @mtree directive is honored. .It Cm @display Ar name Declare .Pa name as the file to be displayed at install time (see .Fl D above). .It Cm @pkgdep Ar pkgname Declare a dependency on the .Ar pkgname package. The .Ar pkgname package must be installed before this package may be installed, and this package must be deinstalled before the .Ar pkgname package is deinstalled. Multiple .Cm @pkgdep directives may be used if the package depends on multiple other packages. +.It Cm @conflicts Ar pkgcflname +Declare a conflict with the +.Ar pkgcflname +package, as the two packages contain references to the same files, +and so cannot co-exist on the same system. .El .Sh ENVIRONMENT The environment variable .Ev PKG_TMPDIR names the directory where .Nm will attempt to create its temporary files. If .Ev PKG_TMPDIR is not set, the directory named by the contents of .Ev TMPDIR will be used. If neither of .Ev PKG_TMPDIR and .Ev TMPDIR are set, the builtin defaults are used. .Sh FILES .Bl -tag -width /usr/tmp -compact .It Pa /var/tmp Temporary directory if environmental variables .Ev PKG_TMPDIR and .Ev TMPDIR are not set. .It Pa /tmp The next choice if .Pa /var/tmp does not exist. .It Pa /usr/tmp The last choice if .Pa /tmp is unsuitable. .El .Sh SEE ALSO .Xr pkg_add 1 , .Xr pkg_delete 1 , .Xr pkg_info 1 , .Xr pkg_version 1 , .Xr sysconf 3 .Sh HISTORY The .Nm command first appeared in .Fx . .Sh AUTHORS .An Jordan Hubbard .Sh CONTRIBUTORS .An John Kohl Aq jtk@rational.com .Sh BUGS Hard links between files in a distribution must be bracketed by .Cm @cwd directives in order to be preserved as hard links when the package is extracted. They additionally must not end up being split between .Cm tar invocations due to exec argument-space limitations (this depends on the value returned by .Fn sysconf _SC_ARG_MAX ) . .Pp Sure to be others. Index: head/usr.sbin/pkg_install/info/show.c =================================================================== --- head/usr.sbin/pkg_install/info/show.c (revision 113593) +++ head/usr.sbin/pkg_install/info/show.c (revision 113594) @@ -1,343 +1,347 @@ /* * 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 * 23 Aug 1993 * * Various display routines for the info module. * */ #include __FBSDID("$FreeBSD$"); #include "lib.h" #include "info.h" #include #include #include #include #include void show_file(const char *title, const char *fname) { FILE *fp; char line[1024]; int n; if (!Quiet) printf("%s%s", InfoPrefix, title); fp = fopen(fname, "r"); if (!fp) printf("ERROR: show_file: Can't open '%s' for reading!\n", fname); else { while ((n = fread(line, 1, 1024, fp)) != 0) fwrite(line, 1, n, stdout); fclose(fp); } printf("\n"); /* just in case */ } void show_index(const char *title, const char *fname) { FILE *fp; char line[MAXINDEXSIZE+2]; if (!Quiet) printf("%s%s", InfoPrefix, title); fp = fopen(fname, "r"); if (!fp) { warnx("show_file: can't open '%s' for reading", fname); return; } if(fgets(line, MAXINDEXSIZE+1, fp)) { if(line[MAXINDEXSIZE-1] != '\n') line[MAXINDEXSIZE] = '\n'; line[MAXINDEXSIZE+1] = 0; fputs(line, stdout); } fclose(fp); } /* Show a packing list item type. If showall is TRUE, show all */ void show_plist(const char *title, Package *plist, plist_t type, Boolean showall) { PackingList p; Boolean ign = FALSE; if (!Quiet) printf("%s%s", InfoPrefix, title); p = plist->head; while (p) { if (p->type != type && showall != TRUE) { p = p->next; continue; } switch(p->type) { case PLIST_FILE: if (ign) { printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name); ign = FALSE; } else printf(Quiet ? "%s\n" : "File: %s\n", p->name); break; case PLIST_CWD: printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name); break; case PLIST_SRC: printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name); break; case PLIST_CMD: printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name); break; case PLIST_UNEXEC: printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name); break; case PLIST_CHMOD: printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n", p->name ? p->name : "(clear default)"); break; case PLIST_CHOWN: printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n", p->name ? p->name : "(clear default)"); break; case PLIST_CHGRP: printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n", p->name ? p->name : "(clear default)"); break; case PLIST_COMMENT: printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name); break; case PLIST_IGNORE: ign = TRUE; break; case PLIST_IGNORE_INST: printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" : "\tIgnore next file installation directive (doesn't belong)\n"); ign = TRUE; break; case PLIST_NAME: printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name); break; case PLIST_DISPLAY: printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name); break; case PLIST_PKGDEP: printf(Quiet ? "@pkgdep %s\n" : "Dependency: %s\n", p->name); break; case PLIST_DEPORIGIN: printf(Quiet ? "@comment DEPORIGIN:%s\n" : "\tdependency origin: %s\n", p->name); break; + case PLIST_CONFLICTS: + printf(Quiet ? "@conflicts %s\n" : "Conflicts: %s\n", p->name); + break; + case PLIST_MTREE: printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name); break; case PLIST_DIR_RM: printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name); break; case PLIST_OPTION: printf(Quiet ? "@option %s\n" : "\tOption \"%s\" controlling package installation behaviour\n", p->name); break; case PLIST_ORIGIN: printf(Quiet ? "@comment ORIGIN:%s\n" : "\tPackage origin: %s\n", p->name); break; default: cleanup(0); errx(2, "%s: unknown command type %d (%s)", __func__, p->type, p->name); break; } p = p->next; } } /* Show all files in the packing list (except ignored ones) */ void show_files(const char *title, Package *plist) { PackingList p; Boolean ign = FALSE; const char *dir = "."; if (!Quiet) printf("%s%s", InfoPrefix, title); p = plist->head; while (p) { switch(p->type) { case PLIST_FILE: if (!ign) printf("%s/%s\n", dir, p->name); ign = FALSE; break; case PLIST_CWD: dir = p->name; break; case PLIST_IGNORE: ign = TRUE; break; /* Silence GCC in the -Wall mode */ default: break; } p = p->next; } } /* Calculate and show size of all installed package files (except ignored ones) */ void show_size(const char *title, Package *plist) { PackingList p; Boolean ign = FALSE; const char *dir = "."; struct stat sb; char tmp[FILENAME_MAX]; unsigned long size = 0; long blksize; int headerlen; char *descr; descr = getbsize(&headerlen, &blksize); if (!Quiet) printf("%s%s", InfoPrefix, title); for (p = plist->head; p != NULL; p = p->next) { switch (p->type) { case PLIST_FILE: if (!ign) { snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); if (!lstat(tmp, &sb)) { size += sb.st_size; if (Verbose) printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp); } } ign = FALSE; break; case PLIST_CWD: dir = p->name; break; case PLIST_IGNORE: ign = TRUE; break; /* Silence GCC in the -Wall mode */ default: break; } } if (!Quiet) printf("%lu\t(%s)\n", howmany(size, blksize), descr); else if (UseBlkSz) printf("%lu\n", howmany(size, blksize)); else printf("%lu\n", size); } /* Show files that don't match the recorded checksum */ void show_cksum(const char *title, Package *plist) { PackingList p; const char *dir = "."; char tmp[FILENAME_MAX]; if (!Quiet) printf("%s%s", InfoPrefix, title); for (p = plist->head; p != NULL; p = p->next) if (p->type == PLIST_CWD) dir = p->name; else if (p->type == PLIST_FILE) { snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); if (!fexists(tmp)) warnx("%s doesn't exist\n", tmp); else if (p->next && p->next->type == PLIST_COMMENT && (strncmp(p->next->name, "MD5:", 4) == 0)) { char *cp = NULL, buf[33]; /* * For packing lists whose version is 1.1 or greater, the md5 * hash for a symlink is calculated on the string returned * by readlink(). */ if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) { int len; char linkbuf[FILENAME_MAX]; if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0) cp = MD5Data((unsigned char *)linkbuf, len, buf); } else if (isfile(tmp) || verscmp(plist, 1, 1) < 0) cp = MD5File(tmp, buf); if (cp != NULL) { /* Mismatch? */ if (strcmp(cp, p->next->name + 4)) printf("%s fails the original MD5 checksum\n", tmp); else if (Verbose) printf("%s matched the original MD5 checksum\n", tmp); } } } } /* Show an "origin" path (usually category/portname) */ void show_origin(const char *title, Package *plist) { if (!Quiet) printf("%s%s", InfoPrefix, title); printf("%s\n", plist->origin != NULL ? plist->origin : ""); } /* Show revision number of the packing list */ void show_fmtrev(const char *title, Package *plist) { if (!Quiet) printf("%s%s", InfoPrefix, title); printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr); } Index: head/usr.sbin/pkg_install/lib/lib.h =================================================================== --- head/usr.sbin/pkg_install/lib/lib.h (revision 113593) +++ head/usr.sbin/pkg_install/lib/lib.h (revision 113594) @@ -1,225 +1,225 @@ /* $FreeBSD$ */ /* * 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 library routines. * */ #ifndef _INST_LIB_LIB_H_ #define _INST_LIB_LIB_H_ /* Includes */ #include #include #include #include #include #include #include #include #include #include #include /* Macros */ #define SUCCESS (0) #define FAIL (-1) #ifndef TRUE #define TRUE (1) #endif #ifndef FALSE #define FALSE (0) #endif #define YES 2 #define NO 1 /* Usually "rm", but often "echo" during debugging! */ #define REMOVE_CMD "rm" /* Usually "rm", but often "echo" during debugging! */ #define RMDIR_CMD "rmdir" /* Where we put logging information by default, else ${PKG_DBDIR} if set */ #define DEF_LOG_DIR "/var/db/pkg" /* just in case we change the environment variable name */ #define PKG_DBDIR "PKG_DBDIR" /* macro to get name of directory where we put logging information */ #define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) /* The names of our "special" files */ #define CONTENTS_FNAME "+CONTENTS" #define COMMENT_FNAME "+COMMENT" #define DESC_FNAME "+DESC" #define INSTALL_FNAME "+INSTALL" #define POST_INSTALL_FNAME "+POST-INSTALL" #define DEINSTALL_FNAME "+DEINSTALL" #define POST_DEINSTALL_FNAME "+POST-DEINSTALL" #define REQUIRE_FNAME "+REQUIRE" #define REQUIRED_BY_FNAME "+REQUIRED_BY" #define DISPLAY_FNAME "+DISPLAY" #define MTREE_FNAME "+MTREE_DIRS" #define CMD_CHAR '@' /* prefix for extended PLIST cmd */ /* The name of the "prefix" environment variable given to scripts */ #define PKG_PREFIX_VNAME "PKG_PREFIX" /* * Version of the package tools - increase only when some * functionality used by bsd.port.mk is changed, added or removed */ -#define PKG_INSTALL_VERSION 20020908 +#define PKG_INSTALL_VERSION 20030417 #define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf" #define main(argc, argv) real_main(argc, argv) /* Version numbers to assist with changes in package file format */ #define PLIST_FMT_VER_MAJOR 1 #define PLIST_FMT_VER_MINOR 1 enum _plist_t { PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY, - PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST, - PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN + PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM, + PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN }; typedef enum _plist_t plist_t; enum _match_t { MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_REGEX }; typedef enum _match_t match_t; /* Types */ typedef unsigned int Boolean; struct _plist { struct _plist *prev, *next; char *name; Boolean marked; plist_t type; }; typedef struct _plist *PackingList; struct _pack { struct _plist *head, *tail; char *name; char *origin; int fmtver_maj, fmtver_mnr; }; typedef struct _pack Package; struct reqr_by_entry { STAILQ_ENTRY(reqr_by_entry) link; char pkgname[PATH_MAX]; }; STAILQ_HEAD(reqr_by_head, reqr_by_entry); /* Prototypes */ /* Misc */ int vsystem(const char *, ...); char *vpipe(const char *, ...); void cleanup(int); char *make_playpen(char *, off_t); char *where_playpen(void); void leave_playpen(void); off_t min_free(const char *); /* String */ char *get_dash_string(char **); char *copy_string(const char *); Boolean suffix(const char *, const char *); void nuke_suffix(char *); void str_lowercase(char *); char *strconcat(const char *, const char *); char *get_string(char *, int, FILE *); /* File */ Boolean fexists(const char *); Boolean isdir(const char *); Boolean isemptydir(const char *fname); Boolean isemptyfile(const char *fname); Boolean isfile(const char *); Boolean isempty(const char *); Boolean issymlink(const char *); Boolean isURL(const char *); char *fileGetURL(const char *, const char *); char *fileFindByPath(const char *, const char *); char *fileGetContents(const char *); void write_file(const char *, const char *); void copy_file(const char *, const char *, const char *); void move_file(const char *, const char *, const char *); void copy_hierarchy(const char *, const char *, Boolean); int delete_hierarchy(const char *, Boolean, Boolean); int unpack(const char *, const char *); void format_cmd(char *, int, const char *, const char *, const char *); /* Msg */ void upchuck(const char *); void barf(const char *, ...); void whinge(const char *, ...); Boolean y_or_n(Boolean, const char *, ...); /* Packing list */ PackingList new_plist_entry(void); PackingList last_plist(Package *); PackingList find_plist(Package *, plist_t); char *find_plist_option(Package *, const char *name); void plist_delete(Package *, Boolean, plist_t, const char *); void free_plist(Package *); void mark_plist(Package *); void csum_plist_entry(char *, PackingList); void add_plist(Package *, plist_t, const char *); void add_plist_top(Package *, plist_t, const char *); void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name); void write_plist(Package *, FILE *); void read_plist(Package *, FILE *); int plist_cmd(const char *, char **); int delete_package(Boolean, Boolean, Package *); Boolean make_preserve_name(char *, int, const char *, const char *); /* For all */ int pkg_perform(char **); int real_main(int, char **); /* Query installed packages */ char **matchinstalled(match_t, char **, int *); char **matchbyorigin(const char *, int *); int isinstalledpkg(const char *name); /* Dependencies */ int sortdeps(char **); int chkifdepends(const char *, const char *); int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean); /* Version */ int verscmp(Package *, int, int); const char *version_of(const char *, int *, int *); int version_cmp(const char *, const char *); /* Externs */ extern Boolean Verbose; extern Boolean Fake; extern Boolean Force; extern int AutoAnswer; #endif /* _INST_LIB_LIB_H_ */ Index: head/usr.sbin/pkg_install/lib/plist.c =================================================================== --- head/usr.sbin/pkg_install/lib/plist.c (revision 113593) +++ head/usr.sbin/pkg_install/lib/plist.c (revision 113594) @@ -1,573 +1,579 @@ /* * 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 * * General packing list routines. * */ #include __FBSDID("$FreeBSD$"); #include "lib.h" #include #include /* Add an item to a packing list */ void add_plist(Package *p, plist_t type, const char *arg) { PackingList tmp; tmp = new_plist_entry(); tmp->name = copy_string(arg); tmp->type = type; if (!p->head) p->head = p->tail = tmp; else { tmp->prev = p->tail; p->tail->next = tmp; p->tail = tmp; } switch (type) { case PLIST_NAME: p->name = tmp->name; break; case PLIST_ORIGIN: p->origin = tmp->name; break; default: break; } } void add_plist_top(Package *p, plist_t type, const char *arg) { PackingList tmp; tmp = new_plist_entry(); tmp->name = copy_string(arg); tmp->type = type; if (!p->head) p->head = p->tail = tmp; else { tmp->next = p->head; p->head->prev = tmp; p->head = tmp; } } /* Return the last (most recent) entry in a packing list */ PackingList last_plist(Package *p) { return p->tail; } /* Mark all items in a packing list to prevent iteration over them */ void mark_plist(Package *pkg) { PackingList p = pkg->head; while (p) { p->marked = TRUE; p = p->next; } } /* Find a given item in a packing list and, if so, return it (else NULL) */ PackingList find_plist(Package *pkg, plist_t type) { PackingList p = pkg->head; while (p) { if (p->type == type) return p; p = p->next; } return NULL; } /* Look for a specific boolean option argument in the list */ char * find_plist_option(Package *pkg, const char *name) { PackingList p = pkg->head; while (p) { if (p->type == PLIST_OPTION && !strcmp(p->name, name)) return p->name; p = p->next; } return NULL; } /* * Delete plist item 'type' in the list (if 'name' is non-null, match it * too.) If 'all' is set, delete all items, not just the first occurance. */ void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name) { PackingList p = pkg->head; while (p) { PackingList pnext = p->next; if (p->type == type && (!name || !strcmp(name, p->name))) { free(p->name); if (p->prev) p->prev->next = pnext; else pkg->head = pnext; if (pnext) pnext->prev = p->prev; else pkg->tail = p->prev; free(p); if (!all) return; p = pnext; } else p = p->next; } } /* Allocate a new packing list entry */ PackingList new_plist_entry(void) { PackingList ret; ret = (PackingList)malloc(sizeof(struct _plist)); bzero(ret, sizeof(struct _plist)); return ret; } /* Free an entire packing list */ void free_plist(Package *pkg) { PackingList p = pkg->head; while (p) { PackingList p1 = p->next; free(p->name); free(p); p = p1; } pkg->head = pkg->tail = NULL; } /* * For an ascii string denoting a plist command, return its code and * optionally its argument(s) */ int plist_cmd(const char *s, char **arg) { char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */ char *cp; const char *sp; strcpy(cmd, s); str_lowercase(cmd); cp = cmd; sp = s; while (*cp) { if (isspace(*cp)) { *cp = '\0'; while (isspace(*sp)) /* Never sure if macro, increment later */ ++sp; break; } ++cp, ++sp; } if (arg) (const char *)*arg = sp; if (!strcmp(cmd, "cwd")) return PLIST_CWD; else if (!strcmp(cmd, "srcdir")) return PLIST_SRC; else if (!strcmp(cmd, "cd")) return PLIST_CWD; else if (!strcmp(cmd, "exec")) return PLIST_CMD; else if (!strcmp(cmd, "unexec")) return PLIST_UNEXEC; else if (!strcmp(cmd, "mode")) return PLIST_CHMOD; else if (!strcmp(cmd, "owner")) return PLIST_CHOWN; else if (!strcmp(cmd, "group")) return PLIST_CHGRP; else if (!strcmp(cmd, "comment")) { if (!strncmp(*arg, "ORIGIN:", 7)) { *arg += 7; return PLIST_ORIGIN; } else if (!strncmp(*arg, "DEPORIGIN:", 10)) { *arg += 10; return PLIST_DEPORIGIN; } return PLIST_COMMENT; } else if (!strcmp(cmd, "ignore")) return PLIST_IGNORE; else if (!strcmp(cmd, "ignore_inst")) return PLIST_IGNORE_INST; else if (!strcmp(cmd, "name")) return PLIST_NAME; else if (!strcmp(cmd, "display")) return PLIST_DISPLAY; else if (!strcmp(cmd, "pkgdep")) return PLIST_PKGDEP; + else if (!strcmp(cmd, "conflicts")) + return PLIST_CONFLICTS; else if (!strcmp(cmd, "mtree")) return PLIST_MTREE; else if (!strcmp(cmd, "dirrm")) return PLIST_DIR_RM; else if (!strcmp(cmd, "option")) return PLIST_OPTION; else return FAIL; } /* Read a packing list from a file */ void read_plist(Package *pkg, FILE *fp) { char *cp, pline[FILENAME_MAX]; int cmd, major, minor; pkg->fmtver_maj = 1; pkg->fmtver_mnr = 0; pkg->origin = NULL; while (fgets(pline, FILENAME_MAX, fp)) { int len = strlen(pline); while (len && isspace(pline[len - 1])) pline[--len] = '\0'; if (!len) continue; cp = pline; if (pline[0] != CMD_CHAR) { cmd = PLIST_FILE; goto bottom; } cmd = plist_cmd(pline + 1, &cp); if (cmd == FAIL) { warnx("%s: unknown command '%s' (package tools out of date?)", __func__, pline); goto bottom; } if (*cp == '\0') { cp = NULL; goto bottom; } if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", &major, &minor) == 2) { pkg->fmtver_maj = major; pkg->fmtver_mnr = minor; if (verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR) <= 0) goto bottom; warnx("plist format revision (%d.%d) is higher than supported" "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR); if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) { cleanup(0); exit(2); } } bottom: add_plist(pkg, cmd, cp); } } /* Write a packing list to a file, converting commands to ascii equivs */ void write_plist(Package *pkg, FILE *fp) { PackingList plist = pkg->head; while (plist) { switch(plist->type) { case PLIST_FILE: fprintf(fp, "%s\n", plist->name); break; case PLIST_CWD: fprintf(fp, "%ccwd %s\n", CMD_CHAR, plist->name); break; case PLIST_SRC: fprintf(fp, "%csrcdir %s\n", CMD_CHAR, plist->name); break; case PLIST_CMD: fprintf(fp, "%cexec %s\n", CMD_CHAR, plist->name); break; case PLIST_UNEXEC: fprintf(fp, "%cunexec %s\n", CMD_CHAR, plist->name); break; case PLIST_CHMOD: fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : ""); break; case PLIST_CHOWN: fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : ""); break; case PLIST_CHGRP: fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : ""); break; case PLIST_COMMENT: fprintf(fp, "%ccomment %s\n", CMD_CHAR, plist->name); break; case PLIST_IGNORE: case PLIST_IGNORE_INST: /* a one-time non-ignored file */ fprintf(fp, "%cignore\n", CMD_CHAR); break; case PLIST_NAME: fprintf(fp, "%cname %s\n", CMD_CHAR, plist->name); break; case PLIST_DISPLAY: fprintf(fp, "%cdisplay %s\n", CMD_CHAR, plist->name); break; case PLIST_PKGDEP: fprintf(fp, "%cpkgdep %s\n", CMD_CHAR, plist->name); + break; + + case PLIST_CONFLICTS: + fprintf(fp, "%cconflicts %s\n", CMD_CHAR, plist->name); break; case PLIST_MTREE: fprintf(fp, "%cmtree %s\n", CMD_CHAR, plist->name); break; case PLIST_DIR_RM: fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name); break; case PLIST_OPTION: fprintf(fp, "%coption %s\n", CMD_CHAR, plist->name); break; case PLIST_ORIGIN: fprintf(fp, "%ccomment ORIGIN:%s\n", CMD_CHAR, plist->name); break; case PLIST_DEPORIGIN: fprintf(fp, "%ccomment DEPORIGIN:%s\n", CMD_CHAR, plist->name); break; default: cleanup(0); errx(2, "%s: unknown command type %d (%s)", __func__, plist->type, plist->name); break; } plist = plist->next; } } /* * Delete the results of a package installation. * * This is here rather than in the pkg_delete code because pkg_add needs to * run it too in cases of failure. */ int delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) { PackingList p; const char *Where = ".", *last_file = ""; Boolean fail = SUCCESS; Boolean preserve; char tmp[FILENAME_MAX], *name = NULL; preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE; for (p = pkg->head; p; p = p->next) { switch (p->type) { case PLIST_NAME: name = p->name; break; case PLIST_IGNORE: p = p->next; break; case PLIST_CWD: Where = p->name; if (Verbose) printf("Change working directory to %s\n", Where); break; case PLIST_UNEXEC: format_cmd(tmp, FILENAME_MAX, p->name, Where, last_file); if (Verbose) printf("Execute '%s'\n", tmp); if (!Fake && system(tmp)) { warnx("unexec command for '%s' failed", tmp); fail = FAIL; } break; case PLIST_FILE: last_file = p->name; sprintf(tmp, "%s/%s", Where, p->name); if (isdir(tmp) && fexists(tmp) && !issymlink(tmp)) { warnx("cannot delete specified file '%s' - it is a directory!\n" "this packing list is incorrect - ignoring delete request", tmp); } else { if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) { char *cp = NULL, buf[33]; /* * For packing lists whose version is 1.1 or greater, the md5 * hash for a symlink is calculated on the string returned * by readlink(). */ if (issymlink(tmp) && verscmp(pkg, 1, 0) > 0) { int len; char linkbuf[FILENAME_MAX]; if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0) cp = MD5Data((unsigned char *)linkbuf, len, buf); } else if (isfile(tmp) || verscmp(pkg, 1, 1) < 0) cp = MD5File(tmp, buf); if (cp != NULL) { /* Mismatch? */ if (strcmp(cp, p->next->name + 4)) { warnx("'%s' fails original MD5 checksum - %s", tmp, Force ? "deleted anyway." : "not deleted."); if (!Force) { fail = FAIL; continue; } } } } if (Verbose) printf("Delete file %s\n", tmp); if (!Fake) { if (delete_hierarchy(tmp, ign_err, nukedirs)) fail = FAIL; if (preserve && name) { char tmp2[FILENAME_MAX]; if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) { if (fexists(tmp2)) { if (rename(tmp2, tmp)) warn("preserve: unable to restore %s as %s", tmp2, tmp); } } } } } break; case PLIST_DIR_RM: sprintf(tmp, "%s/%s", Where, p->name); if (!isdir(tmp) && fexists(tmp)) { warnx("cannot delete specified directory '%s' - it is a file!\n" "this packing list is incorrect - ignoring delete request", tmp); } else { if (Verbose) printf("Delete directory %s\n", tmp); if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) { warnx("unable to completely remove directory '%s'", tmp); fail = FAIL; } } last_file = p->name; break; default: break; } } return fail; } #ifdef DEBUG #define RMDIR(dir) vsystem("%s %s", RMDIR_CMD, dir) #define REMOVE(dir,ie) vsystem("%s %s%s", REMOVE_CMD, (ie ? "-f " : ""), dir) #else #define RMDIR rmdir #define REMOVE(file,ie) (remove(file) && !(ie)) #endif /* Selectively delete a hierarchy */ int delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs) { char *cp1, *cp2; cp1 = cp2 = strdup(dir); if (!fexists(dir)) { if (!ign_err) warnx("%s '%s' doesn't really exist", isdir(dir) ? "directory" : "file", dir); return !ign_err; } else if (nukedirs) { if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir)) return 1; } else if (isdir(dir) && !issymlink(dir)) { if (RMDIR(dir) && !ign_err) return 1; } else { if (REMOVE(dir, ign_err)) return 1; } if (!nukedirs) return 0; while (cp2) { if ((cp2 = strrchr(cp1, '/')) != NULL) *cp2 = '\0'; if (!isemptydir(dir)) return 0; if (RMDIR(dir) && !ign_err) { if (!fexists(dir)) warnx("directory '%s' doesn't really exist", dir); else return 1; } /* back up the pathname one component */ if (cp2) { cp1 = strdup(dir); } } return 0; }