15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland * CDDL HEADER START
35c51f124SMoriah Waterland *
45c51f124SMoriah Waterland * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland *
85c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland * See the License for the specific language governing permissions
115c51f124SMoriah Waterland * and limitations under the License.
125c51f124SMoriah Waterland *
135c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland *
195c51f124SMoriah Waterland * CDDL HEADER END
205c51f124SMoriah Waterland */
215c51f124SMoriah Waterland
225c51f124SMoriah Waterland /*
235c51f124SMoriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
245c51f124SMoriah Waterland * Use is subject to license terms.
255c51f124SMoriah Waterland */
265c51f124SMoriah Waterland
275c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
285c51f124SMoriah Waterland /* All Rights Reserved */
295c51f124SMoriah Waterland
305c51f124SMoriah Waterland
315c51f124SMoriah Waterland #include <stdio.h>
325c51f124SMoriah Waterland #include <fcntl.h>
335c51f124SMoriah Waterland #include <ctype.h>
345c51f124SMoriah Waterland #include <errno.h>
355c51f124SMoriah Waterland #include <string.h>
365c51f124SMoriah Waterland #include <signal.h>
375c51f124SMoriah Waterland #include <stdlib.h>
385c51f124SMoriah Waterland #include <unistd.h>
395c51f124SMoriah Waterland #include <pkginfo.h>
405c51f124SMoriah Waterland #include <pkgstrct.h>
415c51f124SMoriah Waterland #include <pkglocs.h>
425c51f124SMoriah Waterland #include <locale.h>
435c51f124SMoriah Waterland #include <libintl.h>
445c51f124SMoriah Waterland #include <instzones_api.h>
455c51f124SMoriah Waterland #include <pkglib.h>
465c51f124SMoriah Waterland #include <install.h>
475c51f124SMoriah Waterland #include <libadm.h>
485c51f124SMoriah Waterland #include <libinst.h>
495c51f124SMoriah Waterland #include "installf.h"
505c51f124SMoriah Waterland
515c51f124SMoriah Waterland #define BASEDIR "/BASEDIR/"
525c51f124SMoriah Waterland
535c51f124SMoriah Waterland #define INSTALF (*prog == 'i')
545c51f124SMoriah Waterland #define REMOVEF (*prog == 'r')
555c51f124SMoriah Waterland
565c51f124SMoriah Waterland #define MSG_MANMOUNT "Assuming mounts were provided."
575c51f124SMoriah Waterland
585c51f124SMoriah Waterland #define ERR_PKGNAME_TOO_LONG \
595c51f124SMoriah Waterland "The package name specified on the command line\n" \
605c51f124SMoriah Waterland "exceeds the maximum package name length: a package name may contain a\n" \
615c51f124SMoriah Waterland "maximum of <%d> characters; however, the package name specified on\n" \
625c51f124SMoriah Waterland "the command line contains <%d> characters, which exceeds the maximum\n" \
635c51f124SMoriah Waterland "package name length by <%d> characters. Please specify a package name\n" \
645c51f124SMoriah Waterland "that contains no more than <%d> characters."
655c51f124SMoriah Waterland
665c51f124SMoriah Waterland #define ERR_DB_GET "unable to retrieve entries from the database."
675c51f124SMoriah Waterland #define ERR_DB_PUT "unable to update the package database."
685c51f124SMoriah Waterland #define ERR_ROOT_SET "Could not set install root from the environment."
695c51f124SMoriah Waterland #define ERR_ROOT_CMD "Command line install root contends with environment."
705c51f124SMoriah Waterland #define ERR_CLASSLONG "classname argument too long"
715c51f124SMoriah Waterland #define ERR_CLASSCHAR "bad character in classname"
725c51f124SMoriah Waterland #define ERR_INVAL "package instance <%s> is invalid"
735c51f124SMoriah Waterland #define ERR_NOTINST "package instance <%s> is not installed"
745c51f124SMoriah Waterland #define ERR_MERG "unable to merge contents file"
755c51f124SMoriah Waterland #define ERR_SORT "unable to sort contents file"
765c51f124SMoriah Waterland #define ERR_I_FAIL "installf did not complete successfully"
775c51f124SMoriah Waterland #define ERR_R_FAIL "removef did not complete successfully"
785c51f124SMoriah Waterland #define ERR_NOTROOT "You must be \"root\" for %s to execute properly."
795c51f124SMoriah Waterland #define ERR_USAGE0 "usage:\n" \
805c51f124SMoriah Waterland "\t%s [[-M|-A] -R host_path] [-V ...] pkginst path " \
815c51f124SMoriah Waterland "[path ...]\n" \
825c51f124SMoriah Waterland "\t%s [[-M|-A] -R host_path] [-V ...] pkginst path\n"
835c51f124SMoriah Waterland
845c51f124SMoriah Waterland #define ERR_USAGE1 "usage:\n" \
855c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] <pkginst> " \
865c51f124SMoriah Waterland "<path>\n" \
875c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] <pkginst> " \
885c51f124SMoriah Waterland "<path> <specs>\n" \
895c51f124SMoriah Waterland "\t where <specs> may be defined as:\n" \
905c51f124SMoriah Waterland "\t\tf <mode> <owner> <group>\n" \
915c51f124SMoriah Waterland "\t\tv <mode> <owner> <group>\n" \
925c51f124SMoriah Waterland "\t\te <mode> <owner> <group>\n" \
935c51f124SMoriah Waterland "\t\td <mode> <owner> <group>\n" \
945c51f124SMoriah Waterland "\t\tx <mode> <owner> <group>\n" \
955c51f124SMoriah Waterland "\t\tp <mode> <owner> <group>\n" \
965c51f124SMoriah Waterland "\t\tc <major> <minor> <mode> <owner> <group>\n" \
975c51f124SMoriah Waterland "\t\tb <major> <minor> <mode> <owner> <group>\n" \
985c51f124SMoriah Waterland "\t\ts <path>=<srcpath>\n" \
995c51f124SMoriah Waterland "\t\tl <path>=<srcpath>\n" \
1005c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] -f pkginst\n"
1015c51f124SMoriah Waterland
1025c51f124SMoriah Waterland #define CMD_SORT "sort +0 -1"
1035c51f124SMoriah Waterland
1045c51f124SMoriah Waterland #define LINK 1
1055c51f124SMoriah Waterland
1065c51f124SMoriah Waterland extern char dbst; /* libinst/pkgdbmerg.c */
1075c51f124SMoriah Waterland
1085c51f124SMoriah Waterland struct cfextra **extlist;
1095c51f124SMoriah Waterland struct pinfo **eptlist;
1105c51f124SMoriah Waterland
1115c51f124SMoriah Waterland char *classname = NULL;
1125c51f124SMoriah Waterland char *pkginst;
1135c51f124SMoriah Waterland char *uniTmp;
1145c51f124SMoriah Waterland char *abi_sym_ptr;
1155c51f124SMoriah Waterland char *ulim;
1165c51f124SMoriah Waterland char *script;
1175c51f124SMoriah Waterland
1185c51f124SMoriah Waterland int eptnum;
1195c51f124SMoriah Waterland int nosetuid;
1205c51f124SMoriah Waterland int nocnflct;
1215c51f124SMoriah Waterland int warnflag = 0;
1225c51f124SMoriah Waterland
1235c51f124SMoriah Waterland /* libadm/pkgparam.c */
1245c51f124SMoriah Waterland extern void set_PKGADM(char *newpath);
1255c51f124SMoriah Waterland extern void set_PKGLOC(char *newpath);
1265c51f124SMoriah Waterland
1275c51f124SMoriah Waterland extern void set_limit(void);
1285c51f124SMoriah Waterland
1295c51f124SMoriah Waterland int
main(int argc,char ** argv)1305c51f124SMoriah Waterland main(int argc, char **argv)
1315c51f124SMoriah Waterland {
1325c51f124SMoriah Waterland VFP_T *cfTmpVfp;
13362224350SCasper H.S. Dik PKGserver pkgserver = NULL;
1345c51f124SMoriah Waterland char *tp;
1355c51f124SMoriah Waterland char *prog;
1365c51f124SMoriah Waterland char *pt;
1375c51f124SMoriah Waterland char *vfstab_file = NULL;
138*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char *temp_cl_basedir;
1395c51f124SMoriah Waterland char outbuf[PATH_MAX];
1405c51f124SMoriah Waterland int c;
1415c51f124SMoriah Waterland int dbchg;
1425c51f124SMoriah Waterland int err;
1435c51f124SMoriah Waterland int fflag = 0;
1445c51f124SMoriah Waterland int map_client = 1;
1455c51f124SMoriah Waterland int n;
1465c51f124SMoriah Waterland int pkgrmremote = 0; /* don't remove remote files */
1475c51f124SMoriah Waterland struct cfent *ept;
1485c51f124SMoriah Waterland
1495c51f124SMoriah Waterland /* hookup signals */
1505c51f124SMoriah Waterland
1515c51f124SMoriah Waterland (void) signal(SIGHUP, exit);
1525c51f124SMoriah Waterland (void) signal(SIGINT, exit);
1535c51f124SMoriah Waterland (void) signal(SIGQUIT, exit);
1545c51f124SMoriah Waterland
1555c51f124SMoriah Waterland /* initialize locale mechanism */
1565c51f124SMoriah Waterland
1575c51f124SMoriah Waterland (void) setlocale(LC_ALL, "");
1585c51f124SMoriah Waterland
1595c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
1605c51f124SMoriah Waterland #define TEXT_DOMAIN "SYS_TEST"
1615c51f124SMoriah Waterland #endif /* !defined(TEXT_DOMAIN) */
1625c51f124SMoriah Waterland
1635c51f124SMoriah Waterland (void) textdomain(TEXT_DOMAIN);
1645c51f124SMoriah Waterland
1655c51f124SMoriah Waterland /* determine program name */
1665c51f124SMoriah Waterland
1675c51f124SMoriah Waterland prog = set_prog_name(argv[0]);
1685c51f124SMoriah Waterland
1695c51f124SMoriah Waterland /* tell instzones interface how to access package output functions */
1705c51f124SMoriah Waterland
1715c51f124SMoriah Waterland z_set_output_functions(echo, echoDebug, progerr);
1725c51f124SMoriah Waterland
1735c51f124SMoriah Waterland /* only allow root to run this program */
1745c51f124SMoriah Waterland
1755c51f124SMoriah Waterland if (getuid() != 0) {
1765c51f124SMoriah Waterland progerr(gettext(ERR_NOTROOT), prog);
1775c51f124SMoriah Waterland exit(1);
1785c51f124SMoriah Waterland }
1795c51f124SMoriah Waterland
1805c51f124SMoriah Waterland ulim = getenv("PKG_ULIMIT");
1815c51f124SMoriah Waterland script = getenv("PKG_PROC_SCRIPT");
1825c51f124SMoriah Waterland
1835c51f124SMoriah Waterland if (ulim && script) {
1845c51f124SMoriah Waterland set_limit();
1855c51f124SMoriah Waterland clr_ulimit();
1865c51f124SMoriah Waterland }
1875c51f124SMoriah Waterland
1885c51f124SMoriah Waterland /* bug id 4244631, not ABI compliant */
1895c51f124SMoriah Waterland abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS");
1905c51f124SMoriah Waterland if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0)
1915c51f124SMoriah Waterland set_nonABI_symlinks();
1925c51f124SMoriah Waterland
1935c51f124SMoriah Waterland /* bugId 4012147 */
1945c51f124SMoriah Waterland if ((uniTmp = getenv("PKG_NO_UNIFIED")) != NULL)
1955c51f124SMoriah Waterland map_client = 0;
1965c51f124SMoriah Waterland if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) {
1975c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_SET));
1985c51f124SMoriah Waterland exit(1);
1995c51f124SMoriah Waterland }
2005c51f124SMoriah Waterland
2015c51f124SMoriah Waterland while ((c = getopt(argc, argv, "c:V:fAMR:?")) != EOF) {
2025c51f124SMoriah Waterland switch (c) {
2035c51f124SMoriah Waterland case 'f':
2045c51f124SMoriah Waterland fflag++;
2055c51f124SMoriah Waterland break;
2065c51f124SMoriah Waterland
2075c51f124SMoriah Waterland case 'c':
2085c51f124SMoriah Waterland classname = optarg;
2095c51f124SMoriah Waterland /* validate that classname is acceptable */
2105c51f124SMoriah Waterland if (strlen(classname) > (size_t)CLSSIZ) {
2115c51f124SMoriah Waterland progerr(gettext(ERR_CLASSLONG));
2125c51f124SMoriah Waterland exit(1);
2135c51f124SMoriah Waterland }
2145c51f124SMoriah Waterland for (pt = classname; *pt; pt++) {
2155c51f124SMoriah Waterland if (!isalpha(*pt) && !isdigit(*pt)) {
2165c51f124SMoriah Waterland progerr(gettext(ERR_CLASSCHAR));
2175c51f124SMoriah Waterland exit(1);
2185c51f124SMoriah Waterland }
2195c51f124SMoriah Waterland }
2205c51f124SMoriah Waterland break;
2215c51f124SMoriah Waterland
2225c51f124SMoriah Waterland /*
2235c51f124SMoriah Waterland * Don't map the client filesystem onto the server's. Assume
2245c51f124SMoriah Waterland * the mounts have been made for us.
2255c51f124SMoriah Waterland */
2265c51f124SMoriah Waterland case 'M':
2275c51f124SMoriah Waterland map_client = 0;
2285c51f124SMoriah Waterland break;
2295c51f124SMoriah Waterland
2305c51f124SMoriah Waterland /*
2315c51f124SMoriah Waterland * Allow admin to establish the client filesystem using a
2325c51f124SMoriah Waterland * vfstab-like file of stable format.
2335c51f124SMoriah Waterland */
2345c51f124SMoriah Waterland case 'V':
2355c51f124SMoriah Waterland vfstab_file = flex_device(optarg, 2);
2365c51f124SMoriah Waterland map_client = 1;
2375c51f124SMoriah Waterland break;
2385c51f124SMoriah Waterland
2395c51f124SMoriah Waterland case 'A':
2405c51f124SMoriah Waterland pkgrmremote++;
2415c51f124SMoriah Waterland break;
2425c51f124SMoriah Waterland
2435c51f124SMoriah Waterland case 'R': /* added for newroot option */
2445c51f124SMoriah Waterland if (!set_inst_root(optarg)) {
2455c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_CMD));
2465c51f124SMoriah Waterland exit(1);
2475c51f124SMoriah Waterland }
2485c51f124SMoriah Waterland break;
2495c51f124SMoriah Waterland
2505c51f124SMoriah Waterland default:
2515c51f124SMoriah Waterland usage();
2525c51f124SMoriah Waterland /*NOTREACHED*/
2535c51f124SMoriah Waterland /*
2545c51f124SMoriah Waterland * Although usage() calls a noreturn function,
2555c51f124SMoriah Waterland * needed to add return (1); so that main() would
2565c51f124SMoriah Waterland * pass compilation checks. The statement below
2575c51f124SMoriah Waterland * should never be executed.
2585c51f124SMoriah Waterland */
2595c51f124SMoriah Waterland return (1);
2605c51f124SMoriah Waterland }
2615c51f124SMoriah Waterland }
2625c51f124SMoriah Waterland
2635c51f124SMoriah Waterland if (pkgrmremote && (!is_an_inst_root() || fflag || INSTALF)) {
2645c51f124SMoriah Waterland usage();
2655c51f124SMoriah Waterland /*NOTREACHED*/
2665c51f124SMoriah Waterland }
2675c51f124SMoriah Waterland
2685c51f124SMoriah Waterland /*
2695c51f124SMoriah Waterland * Get the mount table info and store internally.
2705c51f124SMoriah Waterland */
2715c51f124SMoriah Waterland if (get_mntinfo(map_client, vfstab_file))
2725c51f124SMoriah Waterland exit(1);
2735c51f124SMoriah Waterland
2745c51f124SMoriah Waterland /*
2755c51f124SMoriah Waterland * This function defines the standard /var/... directories used later
2765c51f124SMoriah Waterland * to construct the paths to the various databases.
2775c51f124SMoriah Waterland */
2785c51f124SMoriah Waterland (void) set_PKGpaths(get_inst_root());
2795c51f124SMoriah Waterland
2805c51f124SMoriah Waterland /*
2815c51f124SMoriah Waterland * If this is being installed on a client whose /var filesystem is
2825c51f124SMoriah Waterland * mounted in some odd way, remap the administrative paths to the
2835c51f124SMoriah Waterland * real filesystem. This could be avoided by simply mounting up the
2845c51f124SMoriah Waterland * client now; but we aren't yet to the point in the process where
2855c51f124SMoriah Waterland * modification of the filesystem is permitted.
2865c51f124SMoriah Waterland */
2875c51f124SMoriah Waterland if (is_an_inst_root()) {
2885c51f124SMoriah Waterland int fsys_value;
2895c51f124SMoriah Waterland
2905c51f124SMoriah Waterland fsys_value = fsys(get_PKGLOC());
2915c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value))
2925c51f124SMoriah Waterland set_PKGLOC(server_map(get_PKGLOC(), fsys_value));
2935c51f124SMoriah Waterland
2945c51f124SMoriah Waterland fsys_value = fsys(get_PKGADM());
2955c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value))
2965c51f124SMoriah Waterland set_PKGADM(server_map(get_PKGADM(), fsys_value));
2975c51f124SMoriah Waterland }
2985c51f124SMoriah Waterland
2995c51f124SMoriah Waterland /*
3005c51f124SMoriah Waterland * get the package name and verify length is not too long
3015c51f124SMoriah Waterland */
3025c51f124SMoriah Waterland
3035c51f124SMoriah Waterland pkginst = argv[optind++];
3045c51f124SMoriah Waterland if (pkginst == NULL) {
3055c51f124SMoriah Waterland usage();
3065c51f124SMoriah Waterland /*NOTREACHED*/
3075c51f124SMoriah Waterland
3085c51f124SMoriah Waterland }
3095c51f124SMoriah Waterland
3105c51f124SMoriah Waterland n = strlen(pkginst);
3115c51f124SMoriah Waterland if (n > PKGSIZ) {
3125c51f124SMoriah Waterland progerr(gettext(ERR_PKGNAME_TOO_LONG), PKGSIZ, n, n-PKGSIZ,
3135c51f124SMoriah Waterland PKGSIZ);
3145c51f124SMoriah Waterland usage();
3155c51f124SMoriah Waterland /*NOTREACHED*/
3165c51f124SMoriah Waterland }
3175c51f124SMoriah Waterland
3185c51f124SMoriah Waterland /*
3195c51f124SMoriah Waterland * The following is used to setup the environment. Note that the
3205c51f124SMoriah Waterland * variable 'BASEDIR' is only meaningful for this utility if there
3215c51f124SMoriah Waterland * is an install root, recorded in PKG_INSTALL_ROOT. Otherwise, this
3225c51f124SMoriah Waterland * utility can create a file or directory anywhere unfettered by
3235c51f124SMoriah Waterland * the basedir associated with the package instance.
3245c51f124SMoriah Waterland */
3255c51f124SMoriah Waterland if ((err = set_basedirs(0, NULL, pkginst, 1)) != 0)
3265c51f124SMoriah Waterland exit(err);
3275c51f124SMoriah Waterland
3285c51f124SMoriah Waterland if (INSTALF)
3295c51f124SMoriah Waterland mkbasedir(0, get_basedir());
3305c51f124SMoriah Waterland
3315c51f124SMoriah Waterland if (fflag) {
3325c51f124SMoriah Waterland /* installf and removef must only have pkginst */
3335c51f124SMoriah Waterland if (optind != argc) {
3345c51f124SMoriah Waterland usage();
3355c51f124SMoriah Waterland /*NOTREACHED*/
3365c51f124SMoriah Waterland }
3375c51f124SMoriah Waterland } else {
3385c51f124SMoriah Waterland /*
3395c51f124SMoriah Waterland * installf and removef must have at minimum
3405c51f124SMoriah Waterland * pkginst & pathname specified on command line
3415c51f124SMoriah Waterland */
3425c51f124SMoriah Waterland if (optind >= argc) {
3435c51f124SMoriah Waterland usage();
3445c51f124SMoriah Waterland /*NOTREACHED*/
3455c51f124SMoriah Waterland }
3465c51f124SMoriah Waterland }
3475c51f124SMoriah Waterland if (REMOVEF) {
3485c51f124SMoriah Waterland if (classname) {
3495c51f124SMoriah Waterland usage();
3505c51f124SMoriah Waterland }
3515c51f124SMoriah Waterland }
3525c51f124SMoriah Waterland if (pkgnmchk(pkginst, "all", 0)) {
3535c51f124SMoriah Waterland progerr(gettext(ERR_INVAL), pkginst);
3545c51f124SMoriah Waterland exit(1);
3555c51f124SMoriah Waterland }
3565c51f124SMoriah Waterland if (fpkginst(pkginst, NULL, NULL) == NULL) {
3575c51f124SMoriah Waterland progerr(gettext(ERR_NOTINST), pkginst);
3585c51f124SMoriah Waterland exit(1);
3595c51f124SMoriah Waterland }
3605c51f124SMoriah Waterland
3615c51f124SMoriah Waterland /*
3625c51f124SMoriah Waterland * This maps the client filesystems into the server's space.
3635c51f124SMoriah Waterland */
3645c51f124SMoriah Waterland if (map_client && !mount_client())
3655c51f124SMoriah Waterland logerr(gettext(MSG_MANMOUNT));
3665c51f124SMoriah Waterland
3675c51f124SMoriah Waterland /* open the package database (contents) file */
3685c51f124SMoriah Waterland
36962224350SCasper H.S. Dik if (!ocfile(&pkgserver, &cfTmpVfp, 0L)) {
3705c51f124SMoriah Waterland quit(1);
3715c51f124SMoriah Waterland }
3725c51f124SMoriah Waterland
3735c51f124SMoriah Waterland if (fflag) {
37462224350SCasper H.S. Dik dbchg = dofinal(pkgserver, cfTmpVfp, REMOVEF, classname, prog);
3755c51f124SMoriah Waterland } else {
3765c51f124SMoriah Waterland if (INSTALF) {
3775c51f124SMoriah Waterland dbst = INST_RDY;
3785c51f124SMoriah Waterland if (installf(argc-optind, &argv[optind]))
3795c51f124SMoriah Waterland quit(1);
3805c51f124SMoriah Waterland } else {
3815c51f124SMoriah Waterland dbst = RM_RDY;
3825c51f124SMoriah Waterland removef(argc-optind, &argv[optind]);
3835c51f124SMoriah Waterland }
3845c51f124SMoriah Waterland
38562224350SCasper H.S. Dik dbchg = pkgdbmerg(pkgserver, cfTmpVfp, extlist);
3865c51f124SMoriah Waterland if (dbchg < 0) {
3875c51f124SMoriah Waterland progerr(gettext(ERR_MERG));
3885c51f124SMoriah Waterland quit(99);
3895c51f124SMoriah Waterland }
3905c51f124SMoriah Waterland }
3915c51f124SMoriah Waterland
3925c51f124SMoriah Waterland if (dbchg) {
39362224350SCasper H.S. Dik if ((n = swapcfile(pkgserver, &cfTmpVfp, pkginst, 1))
3945c51f124SMoriah Waterland == RESULT_WRN) {
3955c51f124SMoriah Waterland warnflag++;
3965c51f124SMoriah Waterland } else if (n == RESULT_ERR) {
3975c51f124SMoriah Waterland quit(99);
3985c51f124SMoriah Waterland }
3995c51f124SMoriah Waterland }
4005c51f124SMoriah Waterland
4015c51f124SMoriah Waterland relslock();
4025c51f124SMoriah Waterland
4035c51f124SMoriah Waterland if (REMOVEF && !fflag) {
4045c51f124SMoriah Waterland for (n = 0; extlist[n]; n++) {
4055c51f124SMoriah Waterland ept = &(extlist[n]->cf_ent);
4065c51f124SMoriah Waterland
4075c51f124SMoriah Waterland /* Skip duplicated paths */
4085c51f124SMoriah Waterland if ((n > 0) && (strncmp(ept->path,
4095c51f124SMoriah Waterland extlist[n-1]->cf_ent.path, PATH_MAX) == 0)) {
4105c51f124SMoriah Waterland continue;
4115c51f124SMoriah Waterland }
4125c51f124SMoriah Waterland
4135c51f124SMoriah Waterland if (!extlist[n]->mstat.shared) {
4145c51f124SMoriah Waterland /*
4155c51f124SMoriah Waterland * Only output paths that can be deleted.
4165c51f124SMoriah Waterland * so need to skip if the object is owned
4175c51f124SMoriah Waterland * by a remote server and removal is not
4185c51f124SMoriah Waterland * being forced.
4195c51f124SMoriah Waterland */
4205c51f124SMoriah Waterland if (ept->pinfo &&
4215c51f124SMoriah Waterland (ept->pinfo->status == SERVED_FILE) &&
4225c51f124SMoriah Waterland !pkgrmremote)
4235c51f124SMoriah Waterland continue;
4245c51f124SMoriah Waterland
4255c51f124SMoriah Waterland c = 0;
4265c51f124SMoriah Waterland if (is_a_cl_basedir() && !is_an_inst_root()) {
427*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
428*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * A path in contents db might have
429*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * other prefix than BASEDIR of the
430*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * package
431*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
432*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India temp_cl_basedir = get_client_basedir();
433*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (strncmp(ept->path, temp_cl_basedir,
434*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(temp_cl_basedir)) == 0) {
435*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India c = strlen(temp_cl_basedir);
436*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(outbuf,
437*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India sizeof (outbuf), "%s/%s\n",
438*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India get_basedir(),
4395c51f124SMoriah Waterland &(ept->path[c]));
440*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India } else {
441*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(outbuf,
442*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India sizeof (outbuf),
443*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India "%s\n", &(ept->path[c]));
444*9b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
4455c51f124SMoriah Waterland } else if (is_an_inst_root()) {
4465c51f124SMoriah Waterland (void) snprintf(outbuf, sizeof (outbuf),
4475c51f124SMoriah Waterland "%s/%s\n", get_inst_root(),
4485c51f124SMoriah Waterland &(ept->path[c]));
4495c51f124SMoriah Waterland } else {
4505c51f124SMoriah Waterland (void) snprintf(outbuf, sizeof (outbuf),
4515c51f124SMoriah Waterland "%s\n", &(ept->path[c]));
4525c51f124SMoriah Waterland }
4535c51f124SMoriah Waterland canonize(outbuf);
4545c51f124SMoriah Waterland (void) printf("%s", outbuf);
4555c51f124SMoriah Waterland }
4565c51f124SMoriah Waterland }
4575c51f124SMoriah Waterland } else if (INSTALF && !fflag) {
4585c51f124SMoriah Waterland for (n = 0; extlist[n]; n++) {
4595c51f124SMoriah Waterland ept = &(extlist[n]->cf_ent);
4605c51f124SMoriah Waterland
4615c51f124SMoriah Waterland if (strchr("dxcbp", ept->ftype)) {
4625c51f124SMoriah Waterland tp = fixpath(ept->path);
46362224350SCasper H.S. Dik (void) averify(1, &ept->ftype, tp, &ept->ainfo);
4645c51f124SMoriah Waterland }
4655c51f124SMoriah Waterland }
4665c51f124SMoriah Waterland }
4675c51f124SMoriah Waterland
46862224350SCasper H.S. Dik pkgcloseserver(pkgserver);
4695c51f124SMoriah Waterland
4705c51f124SMoriah Waterland z_destroyMountTable();
4715c51f124SMoriah Waterland
4725c51f124SMoriah Waterland quit(warnflag ? 1 : 0);
4735c51f124SMoriah Waterland /* LINTED: no return */
4745c51f124SMoriah Waterland }
4755c51f124SMoriah Waterland
4765c51f124SMoriah Waterland void
quit(int n)4775c51f124SMoriah Waterland quit(int n)
4785c51f124SMoriah Waterland {
4795c51f124SMoriah Waterland char *prog = get_prog_name();
4805c51f124SMoriah Waterland
4815c51f124SMoriah Waterland unmount_client();
4825c51f124SMoriah Waterland
4835c51f124SMoriah Waterland if (ulim && script) {
4845c51f124SMoriah Waterland if (REMOVEF) {
4855c51f124SMoriah Waterland set_ulimit(script, gettext(ERR_R_FAIL));
4865c51f124SMoriah Waterland } else {
4875c51f124SMoriah Waterland set_ulimit(script, gettext(ERR_I_FAIL));
4885c51f124SMoriah Waterland }
4895c51f124SMoriah Waterland }
4905c51f124SMoriah Waterland
4915c51f124SMoriah Waterland exit(n);
4925c51f124SMoriah Waterland }
4935c51f124SMoriah Waterland
4945c51f124SMoriah Waterland void
usage(void)4955c51f124SMoriah Waterland usage(void)
4965c51f124SMoriah Waterland {
4975c51f124SMoriah Waterland char *prog = get_prog_name();
4985c51f124SMoriah Waterland
4995c51f124SMoriah Waterland if (REMOVEF) {
5005c51f124SMoriah Waterland (void) fprintf(stderr, gettext(ERR_USAGE0), prog, prog);
5015c51f124SMoriah Waterland } else {
5025c51f124SMoriah Waterland (void) fprintf(stderr, gettext(ERR_USAGE1), prog, prog, prog);
5035c51f124SMoriah Waterland }
5045c51f124SMoriah Waterland exit(1);
5055c51f124SMoriah Waterland }
506