xref: /titanic_50/usr/src/cmd/svr4pkg/pkginstall/main.c (revision 4656d4747c8743290bfbe910c64cd75eb4e4af8d)
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 /*
23a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India"  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
245c51f124SMoriah Waterland  */
255c51f124SMoriah Waterland 
265c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
275c51f124SMoriah Waterland /* All Rights Reserved */
285c51f124SMoriah Waterland 
295c51f124SMoriah Waterland 
305c51f124SMoriah Waterland #include <stdio.h>
315c51f124SMoriah Waterland #include <time.h>
325c51f124SMoriah Waterland #include <wait.h>
335c51f124SMoriah Waterland #include <stdlib.h>
345c51f124SMoriah Waterland #include <unistd.h>
355c51f124SMoriah Waterland #include <ulimit.h>
365c51f124SMoriah Waterland #include <sys/stat.h>
375c51f124SMoriah Waterland #include <sys/statvfs.h>
385c51f124SMoriah Waterland #include <fcntl.h>
395c51f124SMoriah Waterland #include <errno.h>
405c51f124SMoriah Waterland #include <ctype.h>
415c51f124SMoriah Waterland #include <dirent.h>
425c51f124SMoriah Waterland #include <string.h>
435c51f124SMoriah Waterland #include <signal.h>
445c51f124SMoriah Waterland #include <locale.h>
455c51f124SMoriah Waterland #include <libintl.h>
465c51f124SMoriah Waterland #include <pkgstrct.h>
475c51f124SMoriah Waterland #include <pkginfo.h>
485c51f124SMoriah Waterland #include <pkgdev.h>
495c51f124SMoriah Waterland #include <pkglocs.h>
505c51f124SMoriah Waterland #include <pwd.h>
515c51f124SMoriah Waterland #include <assert.h>
525c51f124SMoriah Waterland #include <instzones_api.h>
535c51f124SMoriah Waterland #include <pkglib.h>
545c51f124SMoriah Waterland #include <pkgweb.h>
555c51f124SMoriah Waterland #include <install.h>
565c51f124SMoriah Waterland #include <libinst.h>
575c51f124SMoriah Waterland #include <libadm.h>
585c51f124SMoriah Waterland #include <dryrun.h>
595c51f124SMoriah Waterland #include <messages.h>
605c51f124SMoriah Waterland #include "pkginstall.h"
615c51f124SMoriah Waterland 
625c51f124SMoriah Waterland /* imported globals */
635c51f124SMoriah Waterland 
645c51f124SMoriah Waterland extern char	**environ;
655c51f124SMoriah Waterland extern char	*pkgabrv;
665c51f124SMoriah Waterland extern char	*pkgname;
675c51f124SMoriah Waterland extern char	*pkgarch;
685c51f124SMoriah Waterland extern char	*pkgvers;
695c51f124SMoriah Waterland extern char	pkgwild[];
705c51f124SMoriah Waterland 
715c51f124SMoriah Waterland /* libadm(3LIB) */
725c51f124SMoriah Waterland 
735c51f124SMoriah Waterland extern char	*get_install_root(void);
745c51f124SMoriah Waterland 
755c51f124SMoriah Waterland /* quit.c */
765c51f124SMoriah Waterland 
775c51f124SMoriah Waterland extern sighdlrFunc_t	*quitGetTrapHandler(void);
785c51f124SMoriah Waterland extern void		quitSetDstreamTmpdir(char *a_dstreamTempDir);
795c51f124SMoriah Waterland extern void		quitSetInstallStarted(boolean_t a_installStarted);
805c51f124SMoriah Waterland extern void		quitSetPkgask(boolean_t a_pkgaskFlag);
815c51f124SMoriah Waterland extern void		quitSetSilentExit(boolean_t a_silentExit);
825c51f124SMoriah Waterland extern void		quitSetUpdatingExisting(boolean_t a_updatingExisting);
835c51f124SMoriah Waterland extern void		quitSetZoneName(char *a_zoneName);
845c51f124SMoriah Waterland 
855c51f124SMoriah Waterland 
865c51f124SMoriah Waterland /* static globals */
875c51f124SMoriah Waterland 
885c51f124SMoriah Waterland static char	path[PATH_MAX];
895c51f124SMoriah Waterland static int	ck_instbase(void);
905c51f124SMoriah Waterland static int	cp_pkgdirs(void);
915c51f124SMoriah Waterland static int	merg_pkginfos(struct cl_attr **pclass,
925c51f124SMoriah Waterland 		struct cl_attr ***mpclass);
935c51f124SMoriah Waterland static int	merg_respfile(void);
945c51f124SMoriah Waterland static int	mv_pkgdirs(void);
955c51f124SMoriah Waterland static int	rdonly(char *p);
965c51f124SMoriah Waterland static void	ck_w_dryrun(int (*func)(), int type);
975c51f124SMoriah Waterland static void	copyright(void), usage(void);
985c51f124SMoriah Waterland static void	do_pkgask(boolean_t a_run_request_as_root);
995c51f124SMoriah Waterland static void	rm_icas(char *casdir);
1005c51f124SMoriah Waterland static void	set_dryrun_dir_loc(void);
1015c51f124SMoriah Waterland static void	unpack(void);
1025c51f124SMoriah Waterland 
1035c51f124SMoriah Waterland void	ckreturn(int retcode, char *msg);
1045c51f124SMoriah Waterland 
1055c51f124SMoriah Waterland static char	*ro_params[] = {
1065c51f124SMoriah Waterland 	"PATH", "NAME", "PKG", "PKGINST",
1075c51f124SMoriah Waterland 	"VERSION", "ARCH",
1085c51f124SMoriah Waterland 	"INSTDATE", "CATEGORY",
1095c51f124SMoriah Waterland 	NULL
1105c51f124SMoriah Waterland };
1115c51f124SMoriah Waterland 
1125c51f124SMoriah Waterland /*
1135c51f124SMoriah Waterland  * The following variable is the name of the device to which stdin
1145c51f124SMoriah Waterland  * is connected during execution of a procedure script. PROC_STDIN is
1155c51f124SMoriah Waterland  * correct for all ABI compliant packages. For non-ABI-compliant
1165c51f124SMoriah Waterland  * packages, the '-o' command line switch changes this to PROC_XSTDIN
1175c51f124SMoriah Waterland  * to allow user interaction during these scripts. -- JST
1185c51f124SMoriah Waterland  */
1195c51f124SMoriah Waterland static char	*script_in = PROC_STDIN;	/* assume ABI compliance */
1205c51f124SMoriah Waterland 
1215c51f124SMoriah Waterland static char	*pkgdrtarg = NULL;
1225c51f124SMoriah Waterland static char	*pkgcontsrc = NULL;
1235c51f124SMoriah Waterland static int	non_abi_scripts = 0;
1245c51f124SMoriah Waterland static char	*respfile = NULL;
1255c51f124SMoriah Waterland static char	*srcinst = NULL;
1265c51f124SMoriah Waterland static int	suppressCopyright = 0;
1275c51f124SMoriah Waterland static int	nointeract = 0;
1285c51f124SMoriah Waterland 
1295c51f124SMoriah Waterland /* exported globals */
1305c51f124SMoriah Waterland 
1315c51f124SMoriah Waterland char		*msgtext;
1325c51f124SMoriah Waterland char		*pkginst = (char *)NULL;
1335c51f124SMoriah Waterland char		*rw_block_size = NULL;
1345c51f124SMoriah Waterland char		ilockfile[PATH_MAX];
1355c51f124SMoriah Waterland char		instdir[PATH_MAX];
1365c51f124SMoriah Waterland char		saveSpoolInstallDir[PATH_MAX];
1375c51f124SMoriah Waterland char		pkgbin[PATH_MAX];
1385c51f124SMoriah Waterland char		pkgloc[PATH_MAX];
1395c51f124SMoriah Waterland char		pkgloc_sav[PATH_MAX];
1405c51f124SMoriah Waterland char		pkgsav[PATH_MAX];
1415c51f124SMoriah Waterland char		rlockfile[PATH_MAX];
1425c51f124SMoriah Waterland char		savlog[PATH_MAX];
1435c51f124SMoriah Waterland char		tmpdir[PATH_MAX];
1445c51f124SMoriah Waterland int		dbchg;
1455c51f124SMoriah Waterland int		dparts = 0;
1465c51f124SMoriah Waterland int		dreboot = 0;
1475c51f124SMoriah Waterland int		failflag = 0;
1485c51f124SMoriah Waterland static int	askflag = 0;		/* non-zero if invoked as "pkgask" */
1495c51f124SMoriah Waterland int		ireboot = 0;
1505c51f124SMoriah Waterland int		maxinst = 1;
1515c51f124SMoriah Waterland int		nocnflct;
1525c51f124SMoriah Waterland int		nosetuid;
1535c51f124SMoriah Waterland int		pkgverbose = 0;
1545c51f124SMoriah Waterland int		rprcflag;
1555c51f124SMoriah Waterland int		warnflag = 0;
1565c51f124SMoriah Waterland struct admin	adm;
1575c51f124SMoriah Waterland struct cfextra	**extlist; /* pkgmap structure and other path info */
1585c51f124SMoriah Waterland struct pkgdev	pkgdev;
1595c51f124SMoriah Waterland fsblkcnt_t	pkgmap_blks = 0LL;
1605c51f124SMoriah Waterland 
1615c51f124SMoriah Waterland /*
1625c51f124SMoriah Waterland  * this global is referenced by:
1635c51f124SMoriah Waterland  * getinst - [RW] - incremented if:
1645c51f124SMoriah Waterland  * - installing same instance again
1655c51f124SMoriah Waterland  * - overwriting an existing instance
1665c51f124SMoriah Waterland  * - not installing a new instance
1675c51f124SMoriah Waterland  * quit - [RO] - if non-zero and started non-zero:
1685c51f124SMoriah Waterland  * - the new <PKGINST>/install directory and rename <PKGINST>/install.save
1695c51f124SMoriah Waterland  * - back to <PKGINST>/install
1705c51f124SMoriah Waterland  * main.c - [RO] - if non-zero:
1715c51f124SMoriah Waterland  * - alter manner in which parameters are setup for scripts
1725c51f124SMoriah Waterland  * - set UPDATE=yes in environment
1735c51f124SMoriah Waterland  */
1745c51f124SMoriah Waterland static int		update = 0;
1755c51f124SMoriah Waterland 
1765c51f124SMoriah Waterland /* Set by -O debug: debug output is enabled? */
1775c51f124SMoriah Waterland 
1785c51f124SMoriah Waterland static boolean_t	debugFlag = B_FALSE;
1795c51f124SMoriah Waterland 
1805c51f124SMoriah Waterland /* Set by the -G option: install packages in global zone only */
1815c51f124SMoriah Waterland 
1825c51f124SMoriah Waterland static boolean_t	globalZoneOnly = B_FALSE;
1835c51f124SMoriah Waterland 
1845c51f124SMoriah Waterland /* Set by -O preinstallcheck */
1855c51f124SMoriah Waterland 
1865c51f124SMoriah Waterland static boolean_t	preinstallCheck = B_FALSE;
1875c51f124SMoriah Waterland 
1885c51f124SMoriah Waterland /* Set by -O parent-zone-name= */
1895c51f124SMoriah Waterland 
1905c51f124SMoriah Waterland static char		*parentZoneName = (char *)NULL;
1915c51f124SMoriah Waterland 
1925c51f124SMoriah Waterland /* Set by -O parent-zone-type= */
1935c51f124SMoriah Waterland 
1945c51f124SMoriah Waterland static char		*parentZoneType = (char *)NULL;
1955c51f124SMoriah Waterland 
1965c51f124SMoriah Waterland #define	DEFPATH		"/sbin:/usr/sbin:/usr/bin"
1975c51f124SMoriah Waterland #define	MALSIZ	4	/* best guess at likely maximum value of MAXINST */
1985c51f124SMoriah Waterland #define	LSIZE	256	/* maximum line size supported in copyright file */
1995c51f124SMoriah Waterland 
2005c51f124SMoriah Waterland #ifdef	ALLOW_EXCEPTION_PKG_LIST
2015c51f124SMoriah Waterland #define	SCRIPT	0	/* which exception_pkg() pkg list to use (SCRIPTS) */
2025c51f124SMoriah Waterland #define	LINK	1	/* which exception_pkg() pkg list to use (SYMLINKS) */
2035c51f124SMoriah Waterland #endif
2045c51f124SMoriah Waterland 
2055c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
2065c51f124SMoriah Waterland #define	TEXT_DOMAIN "SYS_TEST"
2075c51f124SMoriah Waterland #endif
2085c51f124SMoriah Waterland 
2095c51f124SMoriah Waterland /* This is the text for the "-O parent-zone-name=" option */
2105c51f124SMoriah Waterland 
2115c51f124SMoriah Waterland #define	PARENTZONENAME	"parent-zone-name="
2125c51f124SMoriah Waterland #define	PARENTZONENAME_LEN	((sizeof (PARENTZONENAME))-1)
2135c51f124SMoriah Waterland 
2145c51f124SMoriah Waterland /* This is the text for the "-O parent-zone-type=" option */
2155c51f124SMoriah Waterland 
2165c51f124SMoriah Waterland #define	PARENTZONETYPE	"parent-zone-type="
2175c51f124SMoriah Waterland #define	PARENTZONETYPE_LEN	((sizeof (PARENTZONETYPE))-1)
2185c51f124SMoriah Waterland 
2195c51f124SMoriah Waterland static char *cpio_names[] = {
2205c51f124SMoriah Waterland 	"root",
2215c51f124SMoriah Waterland 	"root.cpio",
2225c51f124SMoriah Waterland 	"reloc",
2235c51f124SMoriah Waterland 	"reloc.cpio",
2245c51f124SMoriah Waterland 	"root.Z",
2255c51f124SMoriah Waterland 	"root.cpio.Z",
2265c51f124SMoriah Waterland 	"reloc.Z",
2275c51f124SMoriah Waterland 	"reloc.cpio.Z",
2285c51f124SMoriah Waterland 	0
2295c51f124SMoriah Waterland };
2305c51f124SMoriah Waterland 
2315c51f124SMoriah Waterland int
2325c51f124SMoriah Waterland main(int argc, char *argv[])
2335c51f124SMoriah Waterland {
23462224350SCasper H.S. Dik 	VFP_T			*cfTmpVfp = NULL;	/* temporary */
2355c51f124SMoriah Waterland 	VFP_T			*pkgmapVfp;	/* "../pkgmap" file */
2365c51f124SMoriah Waterland 	boolean_t		run_request_as_root = B_FALSE;
2375c51f124SMoriah Waterland 	char			**np;
2385c51f124SMoriah Waterland 	char			*abi_comp_ptr;
2395c51f124SMoriah Waterland 	char			*abi_nm_ptr;
2405c51f124SMoriah Waterland 	char			*abi_sym_ptr;
2415c51f124SMoriah Waterland 	char			*admnfile = NULL;
2425c51f124SMoriah Waterland 	char			*device;
2435c51f124SMoriah Waterland 	char			*p;
2445c51f124SMoriah Waterland 	char			*prog_full_name = NULL;
2455c51f124SMoriah Waterland 	char			*pt;
2465c51f124SMoriah Waterland 	char			*updated = (char *)NULL;
2475c51f124SMoriah Waterland 	char			*vfstab_file = NULL;
2485c51f124SMoriah Waterland 	char			*zoneName = (char *)NULL;
2495c51f124SMoriah Waterland 	char			cbuf[MAX_PKG_PARAM_LENGTH];
2505c51f124SMoriah Waterland 	char			cmdbin[PATH_MAX];
2515c51f124SMoriah Waterland 	char			p_pkginfo[PATH_MAX];
2525c51f124SMoriah Waterland 	char			p_pkgmap[PATH_MAX];
2535c51f124SMoriah Waterland 	char			param[MAX_PKG_PARAM_LENGTH];
2545c51f124SMoriah Waterland 	char			script[PATH_MAX];
2555c51f124SMoriah Waterland 	char			altscript[PATH_MAX];
256a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	char			*temp;
2575c51f124SMoriah Waterland 	int			c;
2585c51f124SMoriah Waterland 	int			disableAttributes = 0;
2595c51f124SMoriah Waterland 	int			err;
2605c51f124SMoriah Waterland 	int			init_install = 0;
2615c51f124SMoriah Waterland 	int			is_comp_arch;
2625c51f124SMoriah Waterland 	int			live_continue = 0;
2635c51f124SMoriah Waterland 	int			map_client = 1;
2645c51f124SMoriah Waterland 	int			n;
2655c51f124SMoriah Waterland 	int			nparts;
2665c51f124SMoriah Waterland 	int			npkgs;
2675c51f124SMoriah Waterland 	int			part;
2685c51f124SMoriah Waterland 	int			saveSpoolInstall = 0;
2695c51f124SMoriah Waterland 	boolean_t		cont_file_read;
2705c51f124SMoriah Waterland 	struct cl_attr		**pclass = NULL;
2715c51f124SMoriah Waterland 	struct cl_attr		**mergd_pclass = NULL;
2725c51f124SMoriah Waterland 	struct pkginfo		*prvinfo;
2735c51f124SMoriah Waterland 	struct sigaction	nact;
2745c51f124SMoriah Waterland 	struct sigaction	oact;
2755c51f124SMoriah Waterland 	struct stat		statb;
2765c51f124SMoriah Waterland 	struct statvfs64	svfsb;
2775c51f124SMoriah Waterland 	time_t			clock;
27862224350SCasper H.S. Dik 	PKGserver		pkgserver = NULL;
2795c51f124SMoriah Waterland 
2805c51f124SMoriah Waterland 	/* reset contents of all default paths */
2815c51f124SMoriah Waterland 
2825c51f124SMoriah Waterland 	(void) memset(path, '\0', sizeof (path));
2835c51f124SMoriah Waterland 	(void) memset(cmdbin, '\0', sizeof (cmdbin));
2845c51f124SMoriah Waterland 	(void) memset(script, '\0', sizeof (script));
2855c51f124SMoriah Waterland 	(void) memset(cbuf, '\0', sizeof (cbuf));
2865c51f124SMoriah Waterland 	(void) memset(param, '\0', sizeof (param));
2875c51f124SMoriah Waterland 
2885c51f124SMoriah Waterland 	/* initialize locale environment */
2895c51f124SMoriah Waterland 
2905c51f124SMoriah Waterland 	(void) setlocale(LC_ALL, "");
2915c51f124SMoriah Waterland 	(void) textdomain(TEXT_DOMAIN);
2925c51f124SMoriah Waterland 
2935c51f124SMoriah Waterland 	/* initialize program name */
2945c51f124SMoriah Waterland 
2955c51f124SMoriah Waterland 	prog_full_name = argv[0];
2965c51f124SMoriah Waterland 	(void) set_prog_name(argv[0]);
2975c51f124SMoriah Waterland 
2985c51f124SMoriah Waterland 	/* tell spmi zones interface how to access package output functions */
2995c51f124SMoriah Waterland 
3005c51f124SMoriah Waterland 	z_set_output_functions(echo, echoDebug, progerr);
3015c51f124SMoriah Waterland 
3025c51f124SMoriah Waterland 	/* exit if not root */
3035c51f124SMoriah Waterland 
3045c51f124SMoriah Waterland 	if (getuid()) {
3055c51f124SMoriah Waterland 		progerr(ERR_NOT_ROOT, get_prog_name());
3065c51f124SMoriah Waterland 		exit(1);
3075c51f124SMoriah Waterland 		/* NOTREACHED */
3085c51f124SMoriah Waterland 	}
3095c51f124SMoriah Waterland 
3105c51f124SMoriah Waterland 	/*
3115c51f124SMoriah Waterland 	 * determine how pkgmap() deals with environment variables:
3125c51f124SMoriah Waterland 	 *  - MAPALL - resolve all variables
3135c51f124SMoriah Waterland 	 *  - MAPBUILD - map only build variables
3145c51f124SMoriah Waterland 	 *  - MAPINSTALL - map only install variables
3155c51f124SMoriah Waterland 	 *  - MAPNONE - map no variables
3165c51f124SMoriah Waterland 	 */
3175c51f124SMoriah Waterland 
3185c51f124SMoriah Waterland 	setmapmode(MAPINSTALL);
3195c51f124SMoriah Waterland 
3205c51f124SMoriah Waterland 	/* set sane umask */
3215c51f124SMoriah Waterland 
3225c51f124SMoriah Waterland 	(void) umask(0022);
3235c51f124SMoriah Waterland 
3245c51f124SMoriah Waterland 	/* initially no source "device" */
3255c51f124SMoriah Waterland 
3265c51f124SMoriah Waterland 	device = NULL;
3275c51f124SMoriah Waterland 
3285c51f124SMoriah Waterland 	/* reset npkgs (used as pkg remaining count in quit.c) */
3295c51f124SMoriah Waterland 
3305c51f124SMoriah Waterland 	npkgs = 0;
3315c51f124SMoriah Waterland 
3325c51f124SMoriah Waterland 	/* Read PKG_INSTALL_ROOT from the environment, if it's there. */
3335c51f124SMoriah Waterland 
3345c51f124SMoriah Waterland 	if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) {
3355c51f124SMoriah Waterland 		progerr(ERR_ROOT_SET);
3365c51f124SMoriah Waterland 		exit(1);
3375c51f124SMoriah Waterland 	}
3385c51f124SMoriah Waterland 
33962224350SCasper H.S. Dik 	pkgserversetmode(DEFAULTMODE);
34062224350SCasper H.S. Dik 
3415c51f124SMoriah Waterland 	/* parse command line options */
3425c51f124SMoriah Waterland 
3435c51f124SMoriah Waterland 	while ((c = getopt(argc, argv,
3445c51f124SMoriah Waterland 		"?Aa:B:b:Cc:D:d:eFf:GhIiMm:N:noO:p:R:r:StV:vyz")) != EOF) {
3455c51f124SMoriah Waterland 
3465c51f124SMoriah Waterland 		switch (c) {
3475c51f124SMoriah Waterland 
3485c51f124SMoriah Waterland 		/*
3495c51f124SMoriah Waterland 		 * Same as pkgadd: This disables attribute checking.
3505c51f124SMoriah Waterland 		 * It speeds up installation a little bit.
3515c51f124SMoriah Waterland 		 */
3525c51f124SMoriah Waterland 		case 'A':
3535c51f124SMoriah Waterland 			disableAttributes++;
3545c51f124SMoriah Waterland 			break;
3555c51f124SMoriah Waterland 
3565c51f124SMoriah Waterland 		/*
3575c51f124SMoriah Waterland 		 * Same as pkgadd: Define an installation administration
3585c51f124SMoriah Waterland 		 * file, admin, to be used in place of the default
3595c51f124SMoriah Waterland 		 * administration file.  The token none overrides the use
3605c51f124SMoriah Waterland 		 * of any admin file, and thus forces interaction with the
3615c51f124SMoriah Waterland 		 * user. Unless a full path name is given, pkgadd first
3625c51f124SMoriah Waterland 		 * looks in the current working directory for the
3635c51f124SMoriah Waterland 		 * administration file.  If the specified administration
3645c51f124SMoriah Waterland 		 * file is not in the current working directory, pkgadd
3655c51f124SMoriah Waterland 		 * looks in the /var/sadm/install/admin directory for the
3665c51f124SMoriah Waterland 		 * administration file.
3675c51f124SMoriah Waterland 		 */
3685c51f124SMoriah Waterland 		case 'a':
3695c51f124SMoriah Waterland 			admnfile = flex_device(optarg, 0);
3705c51f124SMoriah Waterland 			break;
3715c51f124SMoriah Waterland 
3725c51f124SMoriah Waterland 		/*
3735c51f124SMoriah Waterland 		 * Same as pkgadd: control block size given to
3745c51f124SMoriah Waterland 		 * pkginstall - block size used in read()/write() loop;
3755c51f124SMoriah Waterland 		 * default is st_blksize from stat() of source file.
3765c51f124SMoriah Waterland 		 */
3775c51f124SMoriah Waterland 		case 'B':
3785c51f124SMoriah Waterland 			rw_block_size = optarg;
3795c51f124SMoriah Waterland 			break;
3805c51f124SMoriah Waterland 
3815c51f124SMoriah Waterland 		/*
3825c51f124SMoriah Waterland 		 * Same as pkgadd: location where executables needed
3835c51f124SMoriah Waterland 		 * by procedure scripts can be found
3845c51f124SMoriah Waterland 		 * default is /usr/sadm/install/bin.
3855c51f124SMoriah Waterland 		 */
3865c51f124SMoriah Waterland 		case 'b':
3875c51f124SMoriah Waterland 			if (!path_valid(optarg)) {
3885c51f124SMoriah Waterland 				progerr(ERR_PATH, optarg);
3895c51f124SMoriah Waterland 				exit(1);
3905c51f124SMoriah Waterland 			}
3915c51f124SMoriah Waterland 			if (isdir(optarg) != 0) {
3925c51f124SMoriah Waterland 				char *p = strerror(errno);
3935c51f124SMoriah Waterland 				progerr(ERR_CANNOT_USE_DIR, optarg, p);
3945c51f124SMoriah Waterland 				exit(1);
3955c51f124SMoriah Waterland 			}
3965c51f124SMoriah Waterland 			(void) strlcpy(cmdbin, optarg, sizeof (cmdbin));
3975c51f124SMoriah Waterland 			break;
3985c51f124SMoriah Waterland 
3995c51f124SMoriah Waterland 		/*
4005c51f124SMoriah Waterland 		 * Same as pkgadd: This disables checksum tests on
4015c51f124SMoriah Waterland 		 * the source files. It speeds up installation a little bit.
4025c51f124SMoriah Waterland 		 */
4035c51f124SMoriah Waterland 		case 'C':
4045c51f124SMoriah Waterland 			(void) checksum_off();
4055c51f124SMoriah Waterland 			break;
4065c51f124SMoriah Waterland 
4075c51f124SMoriah Waterland 		/*
4085c51f124SMoriah Waterland 		 * Same as pkgadd: This allows designation of a
4095c51f124SMoriah Waterland 		 * continuation file. It is the same format as a dryrun file
4105c51f124SMoriah Waterland 		 * but it is used to take up where the dryrun left off.
4115c51f124SMoriah Waterland 		 */
4125c51f124SMoriah Waterland 		case 'c':
4135c51f124SMoriah Waterland 			pkgcontsrc = optarg;
4145c51f124SMoriah Waterland 			set_continue_mode();
4155c51f124SMoriah Waterland 			set_dr_info(DR_TYPE, INSTALL_TYPE);
4165c51f124SMoriah Waterland 			init_contfile(pkgcontsrc);
4175c51f124SMoriah Waterland 			break;
4185c51f124SMoriah Waterland 
4195c51f124SMoriah Waterland 		/*
4205c51f124SMoriah Waterland 		 * Same as pkgadd: This allows designation of a
4215c51f124SMoriah Waterland 		 * dryrun file. This pkgadd will create dryrun files
4225c51f124SMoriah Waterland 		 * in the directory provided.
4235c51f124SMoriah Waterland 		 */
4245c51f124SMoriah Waterland 		case 'D':
4255c51f124SMoriah Waterland 			pkgdrtarg = optarg;
4265c51f124SMoriah Waterland 			set_dryrun_mode();
4275c51f124SMoriah Waterland 			set_dr_info(DR_TYPE, INSTALL_TYPE);
4285c51f124SMoriah Waterland 			break;
4295c51f124SMoriah Waterland 
4305c51f124SMoriah Waterland 		/*
4315c51f124SMoriah Waterland 		 * Same as pkgadd: Install or copy a package from
4325c51f124SMoriah Waterland 		 * device. device can be a full path name to a directory
4335c51f124SMoriah Waterland 		 * or the identifiers for tape, floppy disk, or removable
4345c51f124SMoriah Waterland 		 * disk - for example, /var/tmp or /floppy/floppy_name.
4355c51f124SMoriah Waterland 		 * It can also be a device alias - for example,
4365c51f124SMoriah Waterland 		 * /floppy/floppy0, or a datastream created by pkgtrans.
4375c51f124SMoriah Waterland 		 */
4385c51f124SMoriah Waterland 		case 'd':
4395c51f124SMoriah Waterland 			device = flex_device(optarg, 1);
4405c51f124SMoriah Waterland 			break;
4415c51f124SMoriah Waterland 
4425c51f124SMoriah Waterland 		/*
4435c51f124SMoriah Waterland 		 * Different from pkgadd: disable the 32 char name
4445c51f124SMoriah Waterland 		 * limit extension
4455c51f124SMoriah Waterland 		 */
4465c51f124SMoriah Waterland 		case 'e':
4475c51f124SMoriah Waterland 			(void) set_ABI_namelngth();
4485c51f124SMoriah Waterland 			break;
4495c51f124SMoriah Waterland 
4505c51f124SMoriah Waterland 		/*
4515c51f124SMoriah Waterland 		 * Different from pkgadd: specify file system type for
4525c51f124SMoriah Waterland 		 * the package device. Must be used with -m.
4535c51f124SMoriah Waterland 		 */
4545c51f124SMoriah Waterland 		case 'f':
4555c51f124SMoriah Waterland 			pkgdev.fstyp = optarg;
4565c51f124SMoriah Waterland 			break;
4575c51f124SMoriah Waterland 
4585c51f124SMoriah Waterland 		/*
4595c51f124SMoriah Waterland 		 * Same as pkgadd: install package in global zone only.
4605c51f124SMoriah Waterland 		 */
4615c51f124SMoriah Waterland 		case 'G':
4625c51f124SMoriah Waterland 			globalZoneOnly = B_TRUE;
4635c51f124SMoriah Waterland 			break;
4645c51f124SMoriah Waterland 
4655c51f124SMoriah Waterland 		/*
4665c51f124SMoriah Waterland 		 * Same as pkgadd: Enable hollow package support. When
4675c51f124SMoriah Waterland 		 * specified, for any package that has SUNW_PKG_HOLLOW=true:
4685c51f124SMoriah Waterland 		 *  Do not calculate and verify package size against target.
4695c51f124SMoriah Waterland 		 *  Do not run any package procedure or class action scripts.
4705c51f124SMoriah Waterland 		 *  Do not create any target directories.
4715c51f124SMoriah Waterland 		 *  Do not perform any script locking.
4725c51f124SMoriah Waterland 		 *  Do not install any components of any package.
4735c51f124SMoriah Waterland 		 *  Do not output any status or database update messages.
4745c51f124SMoriah Waterland 		 */
4755c51f124SMoriah Waterland 		case 'h':
4765c51f124SMoriah Waterland 			set_depend_pkginfo_DB(B_TRUE);
4775c51f124SMoriah Waterland 			break;
4785c51f124SMoriah Waterland 
4795c51f124SMoriah Waterland 		/*
4805c51f124SMoriah Waterland 		 * Same as pkgadd: Informs scripts that this is
4815c51f124SMoriah Waterland 		 * an initial install by setting the environment parameter
4825c51f124SMoriah Waterland 		 * PKG_INIT_INSTALL=TRUE for all scripts. They may use it as
4835c51f124SMoriah Waterland 		 * they see fit, safe in the knowledge that the target
4845c51f124SMoriah Waterland 		 * filesystem is tabula rasa.
4855c51f124SMoriah Waterland 		 */
4865c51f124SMoriah Waterland 		case 'I':
4875c51f124SMoriah Waterland 			init_install++;
4885c51f124SMoriah Waterland 			break;
4895c51f124SMoriah Waterland 
4905c51f124SMoriah Waterland 		/*
4915c51f124SMoriah Waterland 		 * Different from pkgadd: use by pkgask.
4925c51f124SMoriah Waterland 		 */
4935c51f124SMoriah Waterland 		case 'i':
4945c51f124SMoriah Waterland 			askflag++;
4955c51f124SMoriah Waterland 			quitSetPkgask(B_TRUE);
4965c51f124SMoriah Waterland 			break;
4975c51f124SMoriah Waterland 
4985c51f124SMoriah Waterland 		/*
4995c51f124SMoriah Waterland 		 * Same as pkgadd: Instruct pkgadd not to use the
5005c51f124SMoriah Waterland 		 * $root_path/etc/vfstab file for determining the client's
5015c51f124SMoriah Waterland 		 * mount points. This option assumes the mount points are
5025c51f124SMoriah Waterland 		 * correct on the server and it behaves consistently with
5035c51f124SMoriah Waterland 		 * Solaris 2.5 and earlier releases.
5045c51f124SMoriah Waterland 		 */
5055c51f124SMoriah Waterland 		case 'M':
5065c51f124SMoriah Waterland 			map_client = 0;
5075c51f124SMoriah Waterland 			break;
5085c51f124SMoriah Waterland 
5095c51f124SMoriah Waterland 		/*
5105c51f124SMoriah Waterland 		 * Different from pkgadd: specify device to use for package
5115c51f124SMoriah Waterland 		 * source.
5125c51f124SMoriah Waterland 		 */
5135c51f124SMoriah Waterland 		case 'm':
5145c51f124SMoriah Waterland 			pkgdev.mount = optarg;
5155c51f124SMoriah Waterland 			pkgdev.rdonly++;
5165c51f124SMoriah Waterland 			pkgdev.mntflg++;
5175c51f124SMoriah Waterland 			break;
5185c51f124SMoriah Waterland 
5195c51f124SMoriah Waterland 		/*
5205c51f124SMoriah Waterland 		 * Different from pkgadd: specify program name to use
5215c51f124SMoriah Waterland 		 * for messages.
5225c51f124SMoriah Waterland 		 */
5235c51f124SMoriah Waterland 		case 'N':
5245c51f124SMoriah Waterland 			(void) set_prog_name(optarg);
5255c51f124SMoriah Waterland 			break;
5265c51f124SMoriah Waterland 
5275c51f124SMoriah Waterland 		/*
5285c51f124SMoriah Waterland 		 * Same as pkgadd: installation occurs in
5295c51f124SMoriah Waterland 		 * non-interactive mode.  Suppress output of the list of
5305c51f124SMoriah Waterland 		 * installed files. The default mode is interactive.
5315c51f124SMoriah Waterland 		 */
5325c51f124SMoriah Waterland 		case 'n':
5335c51f124SMoriah Waterland 			nointeract++;
5345c51f124SMoriah Waterland 			(void) echoSetFlag(B_FALSE);
5355c51f124SMoriah Waterland 			break;
5365c51f124SMoriah Waterland 
5375c51f124SMoriah Waterland 		/*
5385c51f124SMoriah Waterland 		 * Almost same as pkgadd: the -O option allows the behavior
5395c51f124SMoriah Waterland 		 * of the package tools to be modified. Recognized options:
5405c51f124SMoriah Waterland 		 * -> debug
5415c51f124SMoriah Waterland 		 * ---> enable debugging output
5425c51f124SMoriah Waterland 		 * -> preinstallcheck
5435c51f124SMoriah Waterland 		 * ---> perform a "pre installation" check of the specified
5445c51f124SMoriah Waterland 		 * ---> package - suppress all regular output and cause a
5455c51f124SMoriah Waterland 		 * ---> series of one or more "name=value" pair format lines
5465c51f124SMoriah Waterland 		 * ---> to be output that describes the "installability" of
5475c51f124SMoriah Waterland 		 * ---> the specified package
5485c51f124SMoriah Waterland 		 * -> enable-hollow-package-support
5495c51f124SMoriah Waterland 		 * --> Enable hollow package support. When specified, for any
5505c51f124SMoriah Waterland 		 * --> package that has SUNW_PKG_HOLLOW=true:
5515c51f124SMoriah Waterland 		 * --> Do not calculate and verify package size against target
5525c51f124SMoriah Waterland 		 * --> Do not run any package procedure or class action scripts
5535c51f124SMoriah Waterland 		 * --> Do not create or remove any target directories
5545c51f124SMoriah Waterland 		 * --> Do not perform any script locking
5555c51f124SMoriah Waterland 		 * --> Do not install or uninstall any components of any package
5565c51f124SMoriah Waterland 		 * --> Do not output any status or database update messages
5575c51f124SMoriah Waterland 		 */
5585c51f124SMoriah Waterland 		case 'O':
5595c51f124SMoriah Waterland 			for (p = strtok(optarg, ","); p != (char *)NULL;
5605c51f124SMoriah Waterland 				p = strtok(NULL, ",")) {
5615c51f124SMoriah Waterland 
5625c51f124SMoriah Waterland 				/* process debug option */
5635c51f124SMoriah Waterland 
5645c51f124SMoriah Waterland 				if (strcmp(p, "debug") == 0) {
5655c51f124SMoriah Waterland 					/* set debug flag/enable debug output */
5665c51f124SMoriah Waterland 					if (debugFlag == B_TRUE) {
5675c51f124SMoriah Waterland 						smlSetVerbose(B_TRUE);
5685c51f124SMoriah Waterland 					}
5695c51f124SMoriah Waterland 					debugFlag = B_TRUE;
5705c51f124SMoriah Waterland 					(void) echoDebugSetFlag(debugFlag);
5715c51f124SMoriah Waterland 
5725c51f124SMoriah Waterland 					/* debug info on arguments to pkgadd */
5735c51f124SMoriah Waterland 					for (n = 0; n < argc && argv[n]; n++) {
5745c51f124SMoriah Waterland 						echoDebug(DBG_ARG, n, argv[n]);
5755c51f124SMoriah Waterland 					}
5765c51f124SMoriah Waterland 
5775c51f124SMoriah Waterland 					continue;
5785c51f124SMoriah Waterland 				}
5795c51f124SMoriah Waterland 
5805c51f124SMoriah Waterland 				/* process enable-hollow-package-support opt */
5815c51f124SMoriah Waterland 
5825c51f124SMoriah Waterland 				if (strcmp(p,
5835c51f124SMoriah Waterland 					"enable-hollow-package-support") == 0) {
5845c51f124SMoriah Waterland 					set_depend_pkginfo_DB(B_TRUE);
5855c51f124SMoriah Waterland 					continue;
5865c51f124SMoriah Waterland 				}
5875c51f124SMoriah Waterland 
5885c51f124SMoriah Waterland 				/* process preinstallcheck option */
5895c51f124SMoriah Waterland 
5905c51f124SMoriah Waterland 				if (strcmp(p, "preinstallcheck") == 0) {
5915c51f124SMoriah Waterland 					preinstallCheck = B_TRUE;
5925c51f124SMoriah Waterland 					nointeract++;	/* -n */
5935c51f124SMoriah Waterland 					suppressCopyright++;	/* -S */
5945c51f124SMoriah Waterland 					quitSetSilentExit(B_TRUE);
5955c51f124SMoriah Waterland 					continue;
5965c51f124SMoriah Waterland 				}
5975c51f124SMoriah Waterland 
5985c51f124SMoriah Waterland 				/* process addzonename option */
5995c51f124SMoriah Waterland 
6005c51f124SMoriah Waterland 				if (strcmp(p, "addzonename") == 0) {
6015c51f124SMoriah Waterland 					/*
6025c51f124SMoriah Waterland 					 * set zone name to add to messages;
6035c51f124SMoriah Waterland 					 * first look in the current environment
6045c51f124SMoriah Waterland 					 * and use the default package zone name
6055c51f124SMoriah Waterland 					 * if it is set; otherwise, use the name
6065c51f124SMoriah Waterland 					 * of the current zone
6075c51f124SMoriah Waterland 					 */
6085c51f124SMoriah Waterland 					zoneName =
6095c51f124SMoriah Waterland 						getenv(PKG_ZONENAME_VARIABLE);
6105c51f124SMoriah Waterland 
6115c51f124SMoriah Waterland 					if ((zoneName == (char *)NULL) ||
6125c51f124SMoriah Waterland 							(*zoneName == '\0')) {
6135c51f124SMoriah Waterland 						zoneName = z_get_zonename();
6145c51f124SMoriah Waterland 					}
6155c51f124SMoriah Waterland 
6165c51f124SMoriah Waterland 					if (zoneName != (char *)NULL) {
6175c51f124SMoriah Waterland 						if (*zoneName != '\0') {
6185c51f124SMoriah Waterland 							quitSetZoneName(
6195c51f124SMoriah Waterland 								zoneName);
6205c51f124SMoriah Waterland 						} else {
6215c51f124SMoriah Waterland 							zoneName = (char *)NULL;
6225c51f124SMoriah Waterland 						}
6235c51f124SMoriah Waterland 					}
6245c51f124SMoriah Waterland 					continue;
6255c51f124SMoriah Waterland 				}
6265c51f124SMoriah Waterland 
6275c51f124SMoriah Waterland 				/* process parent-zone-name option */
6285c51f124SMoriah Waterland 
6295c51f124SMoriah Waterland 				if (strncmp(p, PARENTZONENAME,
6305c51f124SMoriah Waterland 						PARENTZONENAME_LEN) == 0) {
6315c51f124SMoriah Waterland 					parentZoneName = p+PARENTZONENAME_LEN;
6325c51f124SMoriah Waterland 					continue;
6335c51f124SMoriah Waterland 				}
6345c51f124SMoriah Waterland 
6355c51f124SMoriah Waterland 				/* process parent-zone-type option */
6365c51f124SMoriah Waterland 
6375c51f124SMoriah Waterland 				if (strncmp(p, PARENTZONETYPE,
6385c51f124SMoriah Waterland 						PARENTZONETYPE_LEN) == 0) {
6395c51f124SMoriah Waterland 					parentZoneType = p+PARENTZONETYPE_LEN;
6405c51f124SMoriah Waterland 					continue;
6415c51f124SMoriah Waterland 				}
6425c51f124SMoriah Waterland 
64362224350SCasper H.S. Dik 				if (strncmp(p, PKGSERV_MODE,
64462224350SCasper H.S. Dik 				    PKGSERV_MODE_LEN) == 0) {
64562224350SCasper H.S. Dik 					pkgserversetmode(pkgparsemode(p +
64662224350SCasper H.S. Dik 					    PKGSERV_MODE_LEN));
64762224350SCasper H.S. Dik 					continue;
64862224350SCasper H.S. Dik 				}
64962224350SCasper H.S. Dik 
6505c51f124SMoriah Waterland 				/* option not recognized - issue warning */
6515c51f124SMoriah Waterland 
6525c51f124SMoriah Waterland 				progerr(ERR_INVALID_O_OPTION, p);
6535c51f124SMoriah Waterland 				continue;
6545c51f124SMoriah Waterland 
6555c51f124SMoriah Waterland 			}
6565c51f124SMoriah Waterland 			break;
6575c51f124SMoriah Waterland 
6585c51f124SMoriah Waterland 		/*
6595c51f124SMoriah Waterland 		 * Different from pkgadd: This is an old non-ABI package
6605c51f124SMoriah Waterland 		 */
6615c51f124SMoriah Waterland 		case 'o':
6625c51f124SMoriah Waterland 			non_abi_scripts++;
6635c51f124SMoriah Waterland 			break;
6645c51f124SMoriah Waterland 
6655c51f124SMoriah Waterland 		/*
6665c51f124SMoriah Waterland 		 * Different from pkgadd: specify number of parts to package.
6675c51f124SMoriah Waterland 		 */
6685c51f124SMoriah Waterland 		case 'p':
6695c51f124SMoriah Waterland 			dparts = ds_getinfo(optarg);
6705c51f124SMoriah Waterland 			break;
6715c51f124SMoriah Waterland 
6725c51f124SMoriah Waterland 		/*
6735c51f124SMoriah Waterland 		 * Same as pkgadd: Define the full path name of a
6745c51f124SMoriah Waterland 		 * directory to use as the root_path.  All files,
6755c51f124SMoriah Waterland 		 * including package system information files, are
6765c51f124SMoriah Waterland 		 * relocated to a directory tree starting in the specified
6775c51f124SMoriah Waterland 		 * root_path. The root_path may be specified when
6785c51f124SMoriah Waterland 		 * installing to a client from a server (for example,
6795c51f124SMoriah Waterland 		 * /export/root/client1).
6805c51f124SMoriah Waterland 		 */
6815c51f124SMoriah Waterland 		case 'R':
6825c51f124SMoriah Waterland 			if (!set_inst_root(optarg)) {
6835c51f124SMoriah Waterland 				progerr(ERR_ROOT_CMD);
6845c51f124SMoriah Waterland 				exit(1);
6855c51f124SMoriah Waterland 			}
6865c51f124SMoriah Waterland 			break;
6875c51f124SMoriah Waterland 
6885c51f124SMoriah Waterland 		/*
6895c51f124SMoriah Waterland 		 * Same as pkgadd: Identify a file or directory which
6905c51f124SMoriah Waterland 		 * contains output from a previous pkgask(1M)
6915c51f124SMoriah Waterland 		 * session. This file supplies the interaction responses
6925c51f124SMoriah Waterland 		 * that would be requested by the package in interactive
6935c51f124SMoriah Waterland 		 * mode. response must be a full pathname.
6945c51f124SMoriah Waterland 		 */
6955c51f124SMoriah Waterland 		case 'r':
6965c51f124SMoriah Waterland 			respfile = flex_device(optarg, 2);
6975c51f124SMoriah Waterland 			break;
6985c51f124SMoriah Waterland 
6995c51f124SMoriah Waterland 		/*
7005c51f124SMoriah Waterland 		 * Same as pkgadd: suppress copyright notice being
7015c51f124SMoriah Waterland 		 * output during installation.
7025c51f124SMoriah Waterland 		 */
7035c51f124SMoriah Waterland 		case 'S':
7045c51f124SMoriah Waterland 			suppressCopyright++;
7055c51f124SMoriah Waterland 			break;
7065c51f124SMoriah Waterland 
7075c51f124SMoriah Waterland 		/*
7085c51f124SMoriah Waterland 		 * Same as pkgadd: disable save spool area creation;
7095c51f124SMoriah Waterland 		 * do not spool any partial package contents, that is,
7105c51f124SMoriah Waterland 		 * suppress the creation and population of the package save
7115c51f124SMoriah Waterland 		 * spool area (var/sadm/pkg/PKG/save/pspool/PKG).
7125c51f124SMoriah Waterland 		 */
7135c51f124SMoriah Waterland 		case 't':
7145c51f124SMoriah Waterland 			disable_spool_create();
7155c51f124SMoriah Waterland 			break;
7165c51f124SMoriah Waterland 
7175c51f124SMoriah Waterland 		/*
7185c51f124SMoriah Waterland 		 * Same as pkgadd: Specify an alternative fs_file to map
7195c51f124SMoriah Waterland 		 * the client's file systems.  For example, used in
7205c51f124SMoriah Waterland 		 * situations where the $root_path/etc/vfstab file is
7215c51f124SMoriah Waterland 		 * non-existent or unreliable. Informs the pkginstall
7225c51f124SMoriah Waterland 		 * portion to mount up a client filesystem based upon the
7235c51f124SMoriah Waterland 		 * supplied vfstab-like file of stable format.
7245c51f124SMoriah Waterland 		 */
7255c51f124SMoriah Waterland 		case 'V':
7265c51f124SMoriah Waterland 			vfstab_file = flex_device(optarg, 2);
7275c51f124SMoriah Waterland 			map_client = 1;
7285c51f124SMoriah Waterland 			break;
7295c51f124SMoriah Waterland 
7305c51f124SMoriah Waterland 		/*
7315c51f124SMoriah Waterland 		 * Same as pkgadd: Trace all of the scripts that get
7325c51f124SMoriah Waterland 		 * executed by pkgadd, located in the pkginst/install
7335c51f124SMoriah Waterland 		 * directory. This option is used for debugging the
7345c51f124SMoriah Waterland 		 * procedural and non-procedural scripts
7355c51f124SMoriah Waterland 		 */
7365c51f124SMoriah Waterland 		case 'v':
7375c51f124SMoriah Waterland 			pkgverbose++;
7385c51f124SMoriah Waterland 			break;
7395c51f124SMoriah Waterland 
7405c51f124SMoriah Waterland 		/*
7415c51f124SMoriah Waterland 		 * Different from pkgadd: process this package using
7425c51f124SMoriah Waterland 		 * old non-ABI symlinks
7435c51f124SMoriah Waterland 		 */
7445c51f124SMoriah Waterland 		case 'y':
7455c51f124SMoriah Waterland 			set_nonABI_symlinks();
7465c51f124SMoriah Waterland 			break;
7475c51f124SMoriah Waterland 
7485c51f124SMoriah Waterland 		/*
7495c51f124SMoriah Waterland 		 * Same as pkgadd: perform fresh install from
7505c51f124SMoriah Waterland 		 * package save spool area. When set, the package contents
7515c51f124SMoriah Waterland 		 * are installed from the package spool save area instead
7525c51f124SMoriah Waterland 		 * of from the package root area, so that the original
7535c51f124SMoriah Waterland 		 * source packages are not required to install the
7545c51f124SMoriah Waterland 		 * package. If the -h option is also specified and the
7555c51f124SMoriah Waterland 		 * package is hollow, then this option is ignored. When -z
7565c51f124SMoriah Waterland 		 * is specified:
7575c51f124SMoriah Waterland 		 *  - Editable files are installed from the package instance
7585c51f124SMoriah Waterland 		 *    save area.
7595c51f124SMoriah Waterland 		 *  - Volatile files are installed from the package instance
7605c51f124SMoriah Waterland 		 *    save area.
7615c51f124SMoriah Waterland 		 *  - Executable and data files are installed from the final
7625c51f124SMoriah Waterland 		 *    installed location as specified in the pkgmap file.
7635c51f124SMoriah Waterland 		 *  - Installation scripts are run from the package spool
7645c51f124SMoriah Waterland 		 *    save area.
7655c51f124SMoriah Waterland 		 */
7665c51f124SMoriah Waterland 		case 'z':
7675c51f124SMoriah Waterland 			saveSpoolInstall++;
7685c51f124SMoriah Waterland 			break;
7695c51f124SMoriah Waterland 
7705c51f124SMoriah Waterland 		/*
7715c51f124SMoriah Waterland 		 * unrecognized option
7725c51f124SMoriah Waterland 		 */
7735c51f124SMoriah Waterland 		default:
7745c51f124SMoriah Waterland 			usage();
7755c51f124SMoriah Waterland 			/*NOTREACHED*/
7765c51f124SMoriah Waterland 			/*
7775c51f124SMoriah Waterland 			 * Although usage() calls a noreturn function,
7785c51f124SMoriah Waterland 			 * needed to add return (1);  so that main() would
7795c51f124SMoriah Waterland 			 * pass compilation checks. The statement below
7805c51f124SMoriah Waterland 			 * should never be executed.
7815c51f124SMoriah Waterland 			 */
7825c51f124SMoriah Waterland 			return (1);
7835c51f124SMoriah Waterland 		}
7845c51f124SMoriah Waterland 	}
7855c51f124SMoriah Waterland 
7865c51f124SMoriah Waterland 	/*
7875c51f124SMoriah Waterland 	 * ********************************************************************
7885c51f124SMoriah Waterland 	 * validate command line options
7895c51f124SMoriah Waterland 	 * ********************************************************************
7905c51f124SMoriah Waterland 	 */
7915c51f124SMoriah Waterland 
7925c51f124SMoriah Waterland 	/* set "debug echo" flag according to setting of "-O debug" option */
7935c51f124SMoriah Waterland 
7945c51f124SMoriah Waterland 	(void) echoDebugSetFlag(debugFlag);
7955c51f124SMoriah Waterland 	(void) log_set_verbose(debugFlag);
7965c51f124SMoriah Waterland 
7975c51f124SMoriah Waterland 	/* output entry debugging information */
7985c51f124SMoriah Waterland 
7995c51f124SMoriah Waterland 	if (z_running_in_global_zone()) {
8005c51f124SMoriah Waterland 		echoDebug(DBG_ENTRY_IN_GZ, prog_full_name);
8015c51f124SMoriah Waterland 	} else {
8025c51f124SMoriah Waterland 		echoDebug(DBG_ENTRY_IN_LZ, prog_full_name, getzoneid(),
8035c51f124SMoriah Waterland 		    z_get_zonename());
8045c51f124SMoriah Waterland 	}
8055c51f124SMoriah Waterland 
8065c51f124SMoriah Waterland 	if (in_continue_mode() && !in_dryrun_mode()) {
8075c51f124SMoriah Waterland 		progerr(ERR_LIVE_CONTINUE_NOT_SUPPORTED);
8085c51f124SMoriah Waterland 		usage();
8095c51f124SMoriah Waterland 		/*NOTREACHED*/
8105c51f124SMoriah Waterland 	}
8115c51f124SMoriah Waterland 
8125c51f124SMoriah Waterland 	/* pkgask requires a response file */
8135c51f124SMoriah Waterland 
8145c51f124SMoriah Waterland 	if (askflag && (respfile == NULL)) {
8155c51f124SMoriah Waterland 		usage();
8165c51f124SMoriah Waterland 		/*NOTREACHED*/
8175c51f124SMoriah Waterland 	}
8185c51f124SMoriah Waterland 
8195c51f124SMoriah Waterland 	/* if device specified, set appropriate device in pkgdev */
8205c51f124SMoriah Waterland 
8215c51f124SMoriah Waterland 	if (device) {
8225c51f124SMoriah Waterland 		if (pkgdev.mount) {
8235c51f124SMoriah Waterland 			pkgdev.bdevice = device;
8245c51f124SMoriah Waterland 		} else {
8255c51f124SMoriah Waterland 			pkgdev.cdevice = device;
8265c51f124SMoriah Waterland 		}
8275c51f124SMoriah Waterland 	}
8285c51f124SMoriah Waterland 
8295c51f124SMoriah Waterland 	/* if file system type specified, must have a device to mount */
8305c51f124SMoriah Waterland 
8315c51f124SMoriah Waterland 	if (pkgdev.fstyp && !pkgdev.mount) {
8325c51f124SMoriah Waterland 		progerr(ERR_F_REQUIRES_M);
8335c51f124SMoriah Waterland 		usage();
8345c51f124SMoriah Waterland 		/*NOTREACHED*/
8355c51f124SMoriah Waterland 	}
8365c51f124SMoriah Waterland 
8375c51f124SMoriah Waterland 	/* BEGIN DATA GATHERING PHASE */
8385c51f124SMoriah Waterland 
8395c51f124SMoriah Waterland 	/*
8405c51f124SMoriah Waterland 	 * Get the mount table info and store internally.
8415c51f124SMoriah Waterland 	 */
8425c51f124SMoriah Waterland 	cont_file_read = B_FALSE;
8435c51f124SMoriah Waterland 	if (in_continue_mode()) {
8445c51f124SMoriah Waterland 		int error;
8455c51f124SMoriah Waterland 		cont_file_read = read_continuation(&error);
8465c51f124SMoriah Waterland 		if (error == -1) {
8475c51f124SMoriah Waterland 			quit(99);
8485c51f124SMoriah Waterland 			/*NOTREACHED*/
8495c51f124SMoriah Waterland 		}
8505c51f124SMoriah Waterland 		if (!in_dryrun_mode()) {
8515c51f124SMoriah Waterland 			live_continue = 1;
8525c51f124SMoriah Waterland 		}
8535c51f124SMoriah Waterland 	}
8545c51f124SMoriah Waterland 	/* Read the mount table if not done in continuation mode */
8555c51f124SMoriah Waterland 	if (!cont_file_read) {
8565c51f124SMoriah Waterland 		if (get_mntinfo(map_client, vfstab_file)) {
8575c51f124SMoriah Waterland 			quit(99);
8585c51f124SMoriah Waterland 			/*NOTREACHED*/
8595c51f124SMoriah Waterland 		}
8605c51f124SMoriah Waterland 	}
8615c51f124SMoriah Waterland 
8625c51f124SMoriah Waterland 	/*
8635c51f124SMoriah Waterland 	 * This function defines the standard /var/... directories used later
8645c51f124SMoriah Waterland 	 * to construct the paths to the various databases.
8655c51f124SMoriah Waterland 	 */
8665c51f124SMoriah Waterland 
8675c51f124SMoriah Waterland 	set_PKGpaths(get_inst_root());
8685c51f124SMoriah Waterland 
8695c51f124SMoriah Waterland 	/*
8705c51f124SMoriah Waterland 	 * If this is being installed on a client whose /var filesystem is
8715c51f124SMoriah Waterland 	 * mounted in some odd way, remap the administrative paths to the
8725c51f124SMoriah Waterland 	 * real filesystem. This could be avoided by simply mounting up the
8735c51f124SMoriah Waterland 	 * client now; but we aren't yet to the point in the process where
8745c51f124SMoriah Waterland 	 * modification of the filesystem is permitted.
8755c51f124SMoriah Waterland 	 */
8765c51f124SMoriah Waterland 	if (is_an_inst_root()) {
8775c51f124SMoriah Waterland 		int fsys_value;
8785c51f124SMoriah Waterland 
8795c51f124SMoriah Waterland 		fsys_value = fsys(get_PKGLOC());
8805c51f124SMoriah Waterland 		if (use_srvr_map_n(fsys_value))
8815c51f124SMoriah Waterland 			set_PKGLOC(server_map(get_PKGLOC(), fsys_value));
8825c51f124SMoriah Waterland 
8835c51f124SMoriah Waterland 		fsys_value = fsys(get_PKGADM());
8845c51f124SMoriah Waterland 		if (use_srvr_map_n(fsys_value))
8855c51f124SMoriah Waterland 			set_PKGADM(server_map(get_PKGADM(), fsys_value));
8865c51f124SMoriah Waterland 	}
8875c51f124SMoriah Waterland 
8885c51f124SMoriah Waterland 	/*
8895c51f124SMoriah Waterland 	 * Initialize pkginfo PKGSAV entry, just in case we dryrun to
8905c51f124SMoriah Waterland 	 * somewhere else.
8915c51f124SMoriah Waterland 	 */
8925c51f124SMoriah Waterland 	set_infoloc(get_PKGLOC());
8935c51f124SMoriah Waterland 
8945c51f124SMoriah Waterland 	/* pull off directory and package name from end of command line */
8955c51f124SMoriah Waterland 
8965c51f124SMoriah Waterland 	switch (argc-optind) {
8975c51f124SMoriah Waterland 	case 0:	/* missing directory and package instance */
8985c51f124SMoriah Waterland 		progerr(ERR_MISSING_DIR_AND_PKG);
8995c51f124SMoriah Waterland 		usage();
9005c51f124SMoriah Waterland 		/*NOTREACHED*/
9015c51f124SMoriah Waterland 	case 1: /* missing package instance */
9025c51f124SMoriah Waterland 		progerr(ERR_MISSING_PKG_INSTANCE);
9035c51f124SMoriah Waterland 		usage();
9045c51f124SMoriah Waterland 		/*NOTREACHED*/
9055c51f124SMoriah Waterland 	case 2:	/* just right! */
9065c51f124SMoriah Waterland 		pkgdev.dirname = argv[optind++];
9075c51f124SMoriah Waterland 		srcinst = argv[optind++];
9085c51f124SMoriah Waterland 		break;
9095c51f124SMoriah Waterland 	default:	/* too many args! */
9105c51f124SMoriah Waterland 		progerr(ERR_TOO_MANY_CMD_ARGS);
9115c51f124SMoriah Waterland 		usage();
9125c51f124SMoriah Waterland 		break;
9135c51f124SMoriah Waterland 	}
9145c51f124SMoriah Waterland 
9155c51f124SMoriah Waterland 	(void) pkgparam(NULL, NULL);  /* close up prior pkg file if needed */
9165c51f124SMoriah Waterland 
9175c51f124SMoriah Waterland 	/*
9185c51f124SMoriah Waterland 	 * Initialize installation admin parameters by reading
9195c51f124SMoriah Waterland 	 * the adminfile.
9205c51f124SMoriah Waterland 	 */
9215c51f124SMoriah Waterland 
9225c51f124SMoriah Waterland 	if (!askflag && !live_continue) {
9235c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_ADMINFILE, admnfile ? admnfile : "");
9245c51f124SMoriah Waterland 		setadminFile(admnfile);
9255c51f124SMoriah Waterland 	}
9265c51f124SMoriah Waterland 
9275c51f124SMoriah Waterland 	/*
9285c51f124SMoriah Waterland 	 * about to perform first operation that could be modified by the
9295c51f124SMoriah Waterland 	 * preinstall check option - if preinstall check is selected (that is,
9305c51f124SMoriah Waterland 	 * only gathering dependencies), then output a debug message to
9315c51f124SMoriah Waterland 	 * indicate that the check is beginning. Also turn echo() output
9325c51f124SMoriah Waterland 	 * off and set various other flags.
9335c51f124SMoriah Waterland 	 */
9345c51f124SMoriah Waterland 
9355c51f124SMoriah Waterland 	if (preinstallCheck == B_TRUE) {
9365c51f124SMoriah Waterland 		(void) echoSetFlag(B_FALSE);
9375c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_PREINSCHK,
9385c51f124SMoriah Waterland 			pkginst ? pkginst : (srcinst ? srcinst : ""),
9395c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
9405c51f124SMoriah Waterland 		cksetPreinstallCheck(B_TRUE);
9415c51f124SMoriah Waterland 		cksetZoneName(zoneName);
9425c51f124SMoriah Waterland 		/* inform quit that the install has started */
9435c51f124SMoriah Waterland 		quitSetInstallStarted(B_TRUE);
9445c51f124SMoriah Waterland 	}
9455c51f124SMoriah Waterland 
9465c51f124SMoriah Waterland 	/*
9475c51f124SMoriah Waterland 	 * validate the "rscriptalt" admin file setting
9485c51f124SMoriah Waterland 	 * The rscriptalt admin file parameter may be set to either
9495c51f124SMoriah Waterland 	 * RSCRIPTALT_ROOT or RSCRIPTALT_NOACCESS:
9505c51f124SMoriah Waterland 	 * --> If rscriptalt is not set, or is set to RSCRIPTALT_NOACCESS,
9515c51f124SMoriah Waterland 	 * --> or is set to any value OTHER than RSCRIPTALT_ROOT, then
9525c51f124SMoriah Waterland 	 * --> assume that the parameter is set to RSCRIPTALT_NOACCESS
9535c51f124SMoriah Waterland 	 * If rscriptalt is set to RSCRIPTALT_ROOT, then run request scripts
9545c51f124SMoriah Waterland 	 * as the "root" user if user "install" is not defined.
9555c51f124SMoriah Waterland 	 * Otherwise, assume rscriptalt is set to RSCRIPTALT_NOACCESS, and run
9565c51f124SMoriah Waterland 	 * request scripts as the "alternative" user if user "install" is not
9575c51f124SMoriah Waterland 	 * defined, as appropriate for the current setting of the NONABI_SCRIPTS
9585c51f124SMoriah Waterland 	 * environment variable.
9595c51f124SMoriah Waterland 	 */
9605c51f124SMoriah Waterland 
9615c51f124SMoriah Waterland 	if (ADMSET(RSCRIPTALT)) {
9625c51f124SMoriah Waterland 		p = adm.RSCRIPTALT;
9635c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_RSCRIPT_SET_TO, RSCRIPTALT_KEYWORD, p);
9645c51f124SMoriah Waterland 		if (strcasecmp(p, RSCRIPTALT_ROOT) == 0) {
9655c51f124SMoriah Waterland 			/* rscriptalt=root */
9665c51f124SMoriah Waterland 			run_request_as_root = B_TRUE;
9675c51f124SMoriah Waterland 		} else if (strcasecmp(p, RSCRIPTALT_NOACCESS) == 0) {
9685c51f124SMoriah Waterland 			/* rscriptalt=noaccess */
9695c51f124SMoriah Waterland 			run_request_as_root = B_FALSE;
9705c51f124SMoriah Waterland 		} else {
9715c51f124SMoriah Waterland 			/* rscriptalt=??? */
9725c51f124SMoriah Waterland 			logerr(WRN_RSCRIPTALT_BAD, RSCRIPTALT_KEYWORD, p,
9735c51f124SMoriah Waterland 				RSCRIPTALT_ROOT, RSCRIPTALT_NOACCESS);
9745c51f124SMoriah Waterland 			logerr(WRN_RSCRIPTALT_USING, RSCRIPTALT_KEYWORD,
9755c51f124SMoriah Waterland 				RSCRIPTALT_NOACCESS);
9765c51f124SMoriah Waterland 			run_request_as_root = B_FALSE;
9775c51f124SMoriah Waterland 		}
9785c51f124SMoriah Waterland 	} else {
9795c51f124SMoriah Waterland 		/* rscriptalt not set - assume rscriptalt=noaccess */
9805c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_RSCRIPT_NOT_SET, RSCRIPTALT_KEYWORD);
9815c51f124SMoriah Waterland 		run_request_as_root = B_FALSE;
9825c51f124SMoriah Waterland 	}
9835c51f124SMoriah Waterland 
9845c51f124SMoriah Waterland 	echoDebug(DBG_PKGINSTALL_RSCRIPT_IS_ROOT, run_request_as_root);
9855c51f124SMoriah Waterland 
9865c51f124SMoriah Waterland 	/*
9875c51f124SMoriah Waterland 	 * hook SIGINT and SIGHUP interrupts into quit.c's trap handler
9885c51f124SMoriah Waterland 	 */
9895c51f124SMoriah Waterland 
9905c51f124SMoriah Waterland 	/* hold SIGINT/SIGHUP interrupts */
9915c51f124SMoriah Waterland 
9925c51f124SMoriah Waterland 	(void) sighold(SIGHUP);
9935c51f124SMoriah Waterland 	(void) sighold(SIGINT);
9945c51f124SMoriah Waterland 
9955c51f124SMoriah Waterland 	/* connect quit.c:trap() to SIGINT */
9965c51f124SMoriah Waterland 
9975c51f124SMoriah Waterland 	nact.sa_handler = quitGetTrapHandler();
9985c51f124SMoriah Waterland 	nact.sa_flags = SA_RESTART;
9995c51f124SMoriah Waterland 	(void) sigemptyset(&nact.sa_mask);
10005c51f124SMoriah Waterland 
10015c51f124SMoriah Waterland 	(void) sigaction(SIGINT, &nact, &oact);
10025c51f124SMoriah Waterland 
10035c51f124SMoriah Waterland 	/* connect quit.c:trap() to SIGHUP */
10045c51f124SMoriah Waterland 
10055c51f124SMoriah Waterland 	nact.sa_handler = quitGetTrapHandler();
10065c51f124SMoriah Waterland 	nact.sa_flags = SA_RESTART;
10075c51f124SMoriah Waterland 	(void) sigemptyset(&nact.sa_mask);
10085c51f124SMoriah Waterland 
10095c51f124SMoriah Waterland 	(void) sigaction(SIGHUP, &nact, &oact);
10105c51f124SMoriah Waterland 
10115c51f124SMoriah Waterland 	/* release hold on signals */
10125c51f124SMoriah Waterland 
10135c51f124SMoriah Waterland 	(void) sigrelse(SIGHUP);
10145c51f124SMoriah Waterland 	(void) sigrelse(SIGINT);
10155c51f124SMoriah Waterland 
10165c51f124SMoriah Waterland 	/*
10175c51f124SMoriah Waterland 	 * create required /var... directories if they do not exist;
10185c51f124SMoriah Waterland 	 * this function will call quit(99) if any required path cannot
10195c51f124SMoriah Waterland 	 * be created.
10205c51f124SMoriah Waterland 	 */
10215c51f124SMoriah Waterland 
10225c51f124SMoriah Waterland 	ckdirs();
10235c51f124SMoriah Waterland 
10245c51f124SMoriah Waterland 	tzset();
10255c51f124SMoriah Waterland 
10265c51f124SMoriah Waterland 	/*
10275c51f124SMoriah Waterland 	 * create path to temporary directory "installXXXXXX" - if TMPDIR
10285c51f124SMoriah Waterland 	 * environment variable is set, create the directory in $TMPDIR;
10295c51f124SMoriah Waterland 	 * otherwise, create the directory in P_tmpdir.
10305c51f124SMoriah Waterland 	 */
10315c51f124SMoriah Waterland 
10325c51f124SMoriah Waterland 	pt = getenv("TMPDIR");
10335c51f124SMoriah Waterland 	(void) snprintf(tmpdir, sizeof (tmpdir), "%s/installXXXXXX",
10345c51f124SMoriah Waterland 		((pt != (char *)NULL) && (*pt != '\0')) ? pt : P_tmpdir);
10355c51f124SMoriah Waterland 
10365c51f124SMoriah Waterland 	echoDebug(DBG_PKGINSTALL_TMPDIR, tmpdir);
10375c51f124SMoriah Waterland 
10385c51f124SMoriah Waterland 	if ((mktemp(tmpdir) == NULL) || mkdir(tmpdir, 0771)) {
10395c51f124SMoriah Waterland 		progerr(ERR_MKDIR, tmpdir);
10405c51f124SMoriah Waterland 		quit(99);
10415c51f124SMoriah Waterland 		/*NOTREACHED*/
10425c51f124SMoriah Waterland 	}
10435c51f124SMoriah Waterland 
10445c51f124SMoriah Waterland 	/*
10455c51f124SMoriah Waterland 	 * if the package device is a file containing a package stream,
10465c51f124SMoriah Waterland 	 * unpack the stream into a temporary directory
10475c51f124SMoriah Waterland 	 */
10485c51f124SMoriah Waterland 
10495c51f124SMoriah Waterland 	if ((isdir(pkgdev.dirname) != 0) &&
10505c51f124SMoriah Waterland 		(pkgdev.cdevice == (char *)NULL) &&
10515c51f124SMoriah Waterland 		(pkgdev.bdevice == (char *)NULL) &&
10525c51f124SMoriah Waterland 		(isfile((char *)NULL, pkgdev.dirname) == 0)) {
10535c51f124SMoriah Waterland 
10545c51f124SMoriah Waterland 		char		*idsName = (char *)NULL;
10555c51f124SMoriah Waterland 		char		*pkgnames[2];
10565c51f124SMoriah Waterland 		char		*device = pkgdev.dirname;
10575c51f124SMoriah Waterland 		boolean_t	b;
10585c51f124SMoriah Waterland 
10595c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_DS_ISFILE, pkgdev.dirname);
10605c51f124SMoriah Waterland 
10615c51f124SMoriah Waterland 		/*
10625c51f124SMoriah Waterland 		 * validate the package source device - return pkgdev info that
10635c51f124SMoriah Waterland 		 * describes the package source device.
10645c51f124SMoriah Waterland 		 */
10655c51f124SMoriah Waterland 
10665c51f124SMoriah Waterland 		if (devtype(device, &pkgdev)) {
10675c51f124SMoriah Waterland 			progerr(ERR_BAD_DEVICE, device);
10685c51f124SMoriah Waterland 			quit(99);
10695c51f124SMoriah Waterland 			/* NOTREACHED */
10705c51f124SMoriah Waterland 		}
10715c51f124SMoriah Waterland 
10725c51f124SMoriah Waterland 		/* generate the list of packages to verify */
10735c51f124SMoriah Waterland 
10745c51f124SMoriah Waterland 		pkgnames[0] = srcinst;
10755c51f124SMoriah Waterland 		pkgnames[1] = (char *)NULL;
10765c51f124SMoriah Waterland 
10775c51f124SMoriah Waterland 		b = open_package_datastream(1, pkgnames, (char *)NULL,
10785c51f124SMoriah Waterland 			pkgdev.dirname, (int *)NULL, &idsName, tmpdir, &pkgdev,
10795c51f124SMoriah Waterland 			1);
10805c51f124SMoriah Waterland 
10815c51f124SMoriah Waterland 		if (b == B_FALSE) {
10825c51f124SMoriah Waterland 			progerr(ERR_CANNOT_OPEN_PKG_STREAM,
10835c51f124SMoriah Waterland 				pkgdev.dirname ? pkgdev.dirname : "?");
10845c51f124SMoriah Waterland 			quit(99);
10855c51f124SMoriah Waterland 			/*NOTREACHED*/
10865c51f124SMoriah Waterland 		}
10875c51f124SMoriah Waterland 
10885c51f124SMoriah Waterland 		/* make sure temporary directory is removed on exit */
10895c51f124SMoriah Waterland 
10905c51f124SMoriah Waterland 		quitSetDstreamTmpdir(pkgdev.dirname);
10915c51f124SMoriah Waterland 
10925c51f124SMoriah Waterland 		/* unpack the package instance from the data stream */
10935c51f124SMoriah Waterland 
10945c51f124SMoriah Waterland 		b = unpack_package_from_stream(idsName, srcinst,
10955c51f124SMoriah Waterland 							pkgdev.dirname);
10965c51f124SMoriah Waterland 		if (b == B_FALSE) {
10975c51f124SMoriah Waterland 			progerr(ERR_CANNOT_UNPACK_PKGSTRM,
10985c51f124SMoriah Waterland 				srcinst ? srcinst : "?",
10995c51f124SMoriah Waterland 				idsName ? idsName : "?",
11005c51f124SMoriah Waterland 				pkgdev.dirname ? pkgdev.dirname : "?");
11015c51f124SMoriah Waterland 			quit(99);
11025c51f124SMoriah Waterland 			/*NOTREACHED*/
11035c51f124SMoriah Waterland 		}
11045c51f124SMoriah Waterland 
11055c51f124SMoriah Waterland 		/* close the datastream - no longer needed */
11065c51f124SMoriah Waterland 
11075c51f124SMoriah Waterland 		echoDebug(DBG_CLOSING_STREAM, idsName, pkgdev.dirname);
11085c51f124SMoriah Waterland 		(void) ds_close(1);
11095c51f124SMoriah Waterland 	}
11105c51f124SMoriah Waterland 
11115c51f124SMoriah Waterland 	if (snprintf(instdir, PATH_MAX, "%s/%s", pkgdev.dirname, srcinst)
11125c51f124SMoriah Waterland 	    >= PATH_MAX) {
11135c51f124SMoriah Waterland 		progerr(ERR_SNPRINTF, instdir);
11145c51f124SMoriah Waterland 		quit(99);
11155c51f124SMoriah Waterland 		/*NOTREACHED*/
11165c51f124SMoriah Waterland 	}
11175c51f124SMoriah Waterland 
11185c51f124SMoriah Waterland 	zoneName = getenv(PKG_ZONENAME_VARIABLE);
11195c51f124SMoriah Waterland 
11205c51f124SMoriah Waterland 	/*
11215c51f124SMoriah Waterland 	 * If the environment has a CLIENT_BASEDIR, that takes precedence
11225c51f124SMoriah Waterland 	 * over anything we will construct. We need to save it here because
11235c51f124SMoriah Waterland 	 * in three lines, the current environment goes away.
11245c51f124SMoriah Waterland 	 */
11255c51f124SMoriah Waterland 	(void) set_env_cbdir();	/* copy over environ */
11265c51f124SMoriah Waterland 
11275c51f124SMoriah Waterland 	getuserlocale();
11285c51f124SMoriah Waterland 
11295c51f124SMoriah Waterland 	/*
11305c51f124SMoriah Waterland 	 * current environment has been read; clear environment out
11315c51f124SMoriah Waterland 	 * so putparam() can be used to populate the new environment
11325c51f124SMoriah Waterland 	 * to be passed to any executables/scripts.
11335c51f124SMoriah Waterland 	 */
11345c51f124SMoriah Waterland 
11355c51f124SMoriah Waterland 	environ = NULL;
11365c51f124SMoriah Waterland 
11375c51f124SMoriah Waterland 	/* write parent condition information to environment */
11385c51f124SMoriah Waterland 
11395c51f124SMoriah Waterland 	putConditionInfo(parentZoneName, parentZoneType);
11405c51f124SMoriah Waterland 
11415c51f124SMoriah Waterland 	putuserlocale();
11425c51f124SMoriah Waterland 
11435c51f124SMoriah Waterland 	if (init_install) {
11445c51f124SMoriah Waterland 		putparam("PKG_INIT_INSTALL", "TRUE");
11455c51f124SMoriah Waterland 	}
11465c51f124SMoriah Waterland 
11475c51f124SMoriah Waterland 	if (is_an_inst_root()) {
11485c51f124SMoriah Waterland 		export_client_env(get_inst_root());
11495c51f124SMoriah Waterland 	}
11505c51f124SMoriah Waterland 
11515c51f124SMoriah Waterland 	if (zoneName != (char *)NULL) {
11525c51f124SMoriah Waterland 		putparam(PKG_ZONENAME_VARIABLE, zoneName);
11535c51f124SMoriah Waterland 	}
11545c51f124SMoriah Waterland 
11555c51f124SMoriah Waterland 	putparam("INST_DATADIR", pkgdev.dirname);
11565c51f124SMoriah Waterland 
11575c51f124SMoriah Waterland 	if (non_abi_scripts) {
11585c51f124SMoriah Waterland 		putparam("NONABI_SCRIPTS", "TRUE");
11595c51f124SMoriah Waterland 	}
11605c51f124SMoriah Waterland 
11615c51f124SMoriah Waterland 	if (nonABI_symlinks()) {
11625c51f124SMoriah Waterland 		putparam("PKG_NONABI_SYMLINKS", "TRUE");
11635c51f124SMoriah Waterland 	}
11645c51f124SMoriah Waterland 
11655c51f124SMoriah Waterland 	if (get_ABI_namelngth()) {
11665c51f124SMoriah Waterland 		putparam("PKG_ABI_NAMELENGTH", "TRUE");
11675c51f124SMoriah Waterland 	}
11685c51f124SMoriah Waterland 
11695c51f124SMoriah Waterland 	/* establish path and oambase */
11705c51f124SMoriah Waterland 
11715c51f124SMoriah Waterland 	if (cmdbin[0] == '\0') {
11725c51f124SMoriah Waterland 		(void) strlcpy(cmdbin, PKGBIN, sizeof (cmdbin));
11735c51f124SMoriah Waterland 	}
11745c51f124SMoriah Waterland 
11755c51f124SMoriah Waterland 	(void) snprintf(path, sizeof (path), "%s:%s", DEFPATH, cmdbin);
11765c51f124SMoriah Waterland 
11775c51f124SMoriah Waterland 	putparam("PATH", path);
11785c51f124SMoriah Waterland 
11795c51f124SMoriah Waterland 	putparam("OAMBASE", OAMBASE);
11805c51f124SMoriah Waterland 
11815c51f124SMoriah Waterland 	(void) snprintf(p_pkginfo, sizeof (p_pkginfo),
11825c51f124SMoriah Waterland 			"%s/%s", instdir, PKGINFO);
11835c51f124SMoriah Waterland 	(void) snprintf(p_pkgmap, sizeof (p_pkgmap),
11845c51f124SMoriah Waterland 			"%s/%s", instdir, PKGMAP);
11855c51f124SMoriah Waterland 
11865c51f124SMoriah Waterland 	/* Read the environment (from pkginfo or '-e') ... */
11875c51f124SMoriah Waterland 	abi_nm_ptr = getenv("PKG_ABI_NAMELENGTH");
11885c51f124SMoriah Waterland 
11895c51f124SMoriah Waterland 	/* Disable the 32 char name limit extension */
11905c51f124SMoriah Waterland 	if (abi_nm_ptr && strncasecmp(abi_nm_ptr, "TRUE", 4) == 0) {
11915c51f124SMoriah Waterland 		(void) set_ABI_namelngth();
11925c51f124SMoriah Waterland 	}
11935c51f124SMoriah Waterland 
11945c51f124SMoriah Waterland 	/*
11955c51f124SMoriah Waterland 	 * This tests the pkginfo and pkgmap files for validity and
11965c51f124SMoriah Waterland 	 * puts all delivered pkginfo variables (except for PATH) into
11975c51f124SMoriah Waterland 	 * our environment. This is where a delivered pkginfo BASEDIR
11985c51f124SMoriah Waterland 	 * would come from. See set_basedirs() below.
11995c51f124SMoriah Waterland 	 */
12005c51f124SMoriah Waterland 
12015c51f124SMoriah Waterland 	if (pkgenv(srcinst, p_pkginfo, p_pkgmap)) {
12025c51f124SMoriah Waterland 		quit(1);
12035c51f124SMoriah Waterland 		/*NOTREACHED*/
12045c51f124SMoriah Waterland 	}
12055c51f124SMoriah Waterland 
12065c51f124SMoriah Waterland 	echo("\n%s(%s) %s", pkgname, pkgarch, pkgvers);
12075c51f124SMoriah Waterland 
12085c51f124SMoriah Waterland 	/*
12095c51f124SMoriah Waterland 	 * If this script was invoked by 'pkgask', just
12105c51f124SMoriah Waterland 	 * execute request script and quit (do_pkgask()).
12115c51f124SMoriah Waterland 	 */
12125c51f124SMoriah Waterland 
12135c51f124SMoriah Waterland 	if (askflag) {
12145c51f124SMoriah Waterland 		do_pkgask(run_request_as_root);
12155c51f124SMoriah Waterland 	}
12165c51f124SMoriah Waterland 
12175c51f124SMoriah Waterland 	/* validate package contents file */
12185c51f124SMoriah Waterland 
12195c51f124SMoriah Waterland 	if (vcfile() == 0) {
12205c51f124SMoriah Waterland 		quit(99);
12215c51f124SMoriah Waterland 	}
12225c51f124SMoriah Waterland 
12235c51f124SMoriah Waterland 	/* if not in dryrun mode aquire packaging lock */
12245c51f124SMoriah Waterland 
12255c51f124SMoriah Waterland 	if (!in_dryrun_mode()) {
12265c51f124SMoriah Waterland 		/* acquire the package lock - at install initialization */
12275c51f124SMoriah Waterland 		if (!lockinst(get_prog_name(), srcinst, "install-initial")) {
12285c51f124SMoriah Waterland 			quit(99);
12295c51f124SMoriah Waterland 			/*NOTREACHED*/
12305c51f124SMoriah Waterland 		}
12315c51f124SMoriah Waterland 	}
12325c51f124SMoriah Waterland 
12335c51f124SMoriah Waterland 	/*
12345c51f124SMoriah Waterland 	 * Now do all the various setups based on ABI compliance
12355c51f124SMoriah Waterland 	 */
12365c51f124SMoriah Waterland 
12375c51f124SMoriah Waterland 	/* Read the environment (from pkginfo or '-o') ... */
12385c51f124SMoriah Waterland 	abi_comp_ptr = getenv("NONABI_SCRIPTS");
12395c51f124SMoriah Waterland 
12405c51f124SMoriah Waterland 	/* Read the environment (from pkginfo or '-y') ... */
12415c51f124SMoriah Waterland 	abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS");
12425c51f124SMoriah Waterland 
12435c51f124SMoriah Waterland 	/* bug id 4244631, not ABI compliant */
12445c51f124SMoriah Waterland 	if (abi_comp_ptr && strncasecmp(abi_comp_ptr, "TRUE", 4) == 0) {
12455c51f124SMoriah Waterland 		script_in = PROC_XSTDIN;
12465c51f124SMoriah Waterland 		non_abi_scripts = 1;
12475c51f124SMoriah Waterland 	}
12485c51f124SMoriah Waterland 
12495c51f124SMoriah Waterland #ifdef	ALLOW_EXCEPTION_PKG_LIST
12505c51f124SMoriah Waterland 	/*
12515c51f124SMoriah Waterland 	 * *********************************************************************
12525c51f124SMoriah Waterland 	 * this feature is removed starting with Solaris 10 - there is no built
12535c51f124SMoriah Waterland 	 * in list of packages that should be run "the old way"
12545c51f124SMoriah Waterland 	 * *********************************************************************
12555c51f124SMoriah Waterland 	 */
12565c51f124SMoriah Waterland 
12575c51f124SMoriah Waterland 	else if (exception_pkg(srcinst, SCRIPT)) {
12585c51f124SMoriah Waterland 		/*
12595c51f124SMoriah Waterland 		 * Until on1095, set it from exception package names as
12605c51f124SMoriah Waterland 		 * well.
12615c51f124SMoriah Waterland 		 */
12625c51f124SMoriah Waterland 		putparam("NONABI_SCRIPTS", "TRUE");
12635c51f124SMoriah Waterland 		script_in = PROC_XSTDIN;
12645c51f124SMoriah Waterland 		non_abi_scripts = 1;
12655c51f124SMoriah Waterland 	}
12665c51f124SMoriah Waterland #endif
12675c51f124SMoriah Waterland 
12685c51f124SMoriah Waterland 	/* Set symlinks to be processed the old way */
12695c51f124SMoriah Waterland 	if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0) {
12705c51f124SMoriah Waterland 		set_nonABI_symlinks();
12715c51f124SMoriah Waterland 	}
12725c51f124SMoriah Waterland 	/*
12735c51f124SMoriah Waterland 	 * *********************************************************************
12745c51f124SMoriah Waterland 	 * this feature is removed starting with Solaris 10 - there is no built
12755c51f124SMoriah Waterland 	 * in list of packages that should be run "the old way"
12765c51f124SMoriah Waterland 	 * *********************************************************************
12775c51f124SMoriah Waterland 	 */
12785c51f124SMoriah Waterland 
12795c51f124SMoriah Waterland #ifdef	ALLOW_EXCEPTION_PKG_LIST
12805c51f124SMoriah Waterland 	else if (exception_pkg(srcinst, LINK)) {
12815c51f124SMoriah Waterland 		/* Until 2.9, set it from the execption list */
12825c51f124SMoriah Waterland 		putparam("PKG_NONABI_SYMLINKS", "TRUE");
12835c51f124SMoriah Waterland 		set_nonABI_symlinks();
12845c51f124SMoriah Waterland 	}
12855c51f124SMoriah Waterland #endif
12865c51f124SMoriah Waterland 	/*
12875c51f124SMoriah Waterland 	 * At this point, script_in, non_abi_scripts & the environment are
12885c51f124SMoriah Waterland 	 * all set correctly for the ABI status of the package.
12895c51f124SMoriah Waterland 	 */
12905c51f124SMoriah Waterland 
12915c51f124SMoriah Waterland 	if (pt = getenv("MAXINST")) {
12925c51f124SMoriah Waterland 		maxinst = atol(pt);
12935c51f124SMoriah Waterland 	}
12945c51f124SMoriah Waterland 
12955c51f124SMoriah Waterland 	/*
12965c51f124SMoriah Waterland 	 * See if were are installing a package that only wants to update
12975c51f124SMoriah Waterland 	 * the database or only install files associated with CAS's. We
12985c51f124SMoriah Waterland 	 * only check the PKG_HOLLOW_VARIABLE variable if told to do so by
12995c51f124SMoriah Waterland 	 * the caller.
13005c51f124SMoriah Waterland 	 */
13015c51f124SMoriah Waterland 
13025c51f124SMoriah Waterland 	if (is_depend_pkginfo_DB()) {
13035c51f124SMoriah Waterland 		pt = getenv(PKG_HOLLOW_VARIABLE);
13045c51f124SMoriah Waterland 		if ((pt != NULL) && (strncasecmp(pt, "true", 4) == 0)) {
13055c51f124SMoriah Waterland 			echoDebug(DBG_PKGREMOVE_HOLLOW_ENABLED);
13065c51f124SMoriah Waterland 			if (disableAttributes) {
13075c51f124SMoriah Waterland 				disable_attribute_check();
13085c51f124SMoriah Waterland 			}
13095c51f124SMoriah Waterland 
13105c51f124SMoriah Waterland 			/*
13115c51f124SMoriah Waterland 			 * this is a hollow package and hollow package support
13125c51f124SMoriah Waterland 			 * is enabled -- override admin settings to suppress
13135c51f124SMoriah Waterland 			 * checks that do not make sense since no scripts will
13145c51f124SMoriah Waterland 			 * be executed and no files will be installed.
13155c51f124SMoriah Waterland 			 */
13165c51f124SMoriah Waterland 
13175c51f124SMoriah Waterland 			setadminSetting("conflict", "nocheck");
13185c51f124SMoriah Waterland 			setadminSetting("setuid", "nocheck");
13195c51f124SMoriah Waterland 			setadminSetting("action", "nocheck");
13205c51f124SMoriah Waterland 			setadminSetting("partial", "nocheck");
13215c51f124SMoriah Waterland 			setadminSetting("space", "nocheck");
13225c51f124SMoriah Waterland 			setadminSetting("authentication", "nocheck");
13235c51f124SMoriah Waterland 		} else {
13245c51f124SMoriah Waterland 			echoDebug(DBG_PKGREMOVE_HOLLOW_DISABLED);
13255c51f124SMoriah Waterland 			set_depend_pkginfo_DB(B_FALSE);
13265c51f124SMoriah Waterland 		}
13275c51f124SMoriah Waterland 	}
13285c51f124SMoriah Waterland 
13295c51f124SMoriah Waterland 	/*
13305c51f124SMoriah Waterland 	 * if performing a fresh install to a non-global zone, and doing
13315c51f124SMoriah Waterland 	 * more than just updating the package database (that is, the
13325c51f124SMoriah Waterland 	 * package to install is NOT "hollow"), then set the global flag
13335c51f124SMoriah Waterland 	 * that directs installation is from partially spooled packages
13345c51f124SMoriah Waterland 	 * (that is, packages installed in the global zone).
13355c51f124SMoriah Waterland 	 */
13365c51f124SMoriah Waterland 
13375c51f124SMoriah Waterland 	if (saveSpoolInstall && (!is_depend_pkginfo_DB())) {
13385c51f124SMoriah Waterland 		set_partial_inst();
13395c51f124SMoriah Waterland 	} else {
13405c51f124SMoriah Waterland 		saveSpoolInstall = 0;
13415c51f124SMoriah Waterland 	}
13425c51f124SMoriah Waterland 
13435c51f124SMoriah Waterland 	/*
13445c51f124SMoriah Waterland 	 * verify that we are not trying to install an
13455c51f124SMoriah Waterland 	 * INTONLY package with no interaction
13465c51f124SMoriah Waterland 	 */
13475c51f124SMoriah Waterland 
13485c51f124SMoriah Waterland 	if (pt = getenv("INTONLY")) {
13495c51f124SMoriah Waterland 		if (askflag || nointeract) {
13505c51f124SMoriah Waterland 			progerr(ERR_INTONLY, pkgabrv ? pkgabrv : "?");
13515c51f124SMoriah Waterland 			quit(1);
13525c51f124SMoriah Waterland 			/*NOTREACHED*/
13535c51f124SMoriah Waterland 		}
13545c51f124SMoriah Waterland 	}
13555c51f124SMoriah Waterland 
13565c51f124SMoriah Waterland 	if (!suppressCopyright && !pkgdev.cdevice) {
13575c51f124SMoriah Waterland 		copyright();
13585c51f124SMoriah Waterland 	}
13595c51f124SMoriah Waterland 
13605c51f124SMoriah Waterland 	/*
13615c51f124SMoriah Waterland 	 * inspect the system to determine if any instances of the
13625c51f124SMoriah Waterland 	 * package being installed already exist on the system
13635c51f124SMoriah Waterland 	 */
13645c51f124SMoriah Waterland 
13655c51f124SMoriah Waterland 	prvinfo = (struct pkginfo *)calloc(MALSIZ, sizeof (struct pkginfo));
13665c51f124SMoriah Waterland 	if (prvinfo == NULL) {
13675c51f124SMoriah Waterland 		progerr(ERR_MEMORY, errno);
13685c51f124SMoriah Waterland 		quit(99);
13695c51f124SMoriah Waterland 		/*NOTREACHED*/
13705c51f124SMoriah Waterland 	}
13715c51f124SMoriah Waterland 
13725c51f124SMoriah Waterland 	for (;;) {
13735c51f124SMoriah Waterland 		if (pkginfo(&prvinfo[npkgs], pkgwild, NULL, NULL)) {
13745c51f124SMoriah Waterland 			if ((errno == ESRCH) || (errno == ENOENT)) {
13755c51f124SMoriah Waterland 				break;
13765c51f124SMoriah Waterland 			}
13775c51f124SMoriah Waterland 			progerr(ERR_SYSINFO, errno);
13785c51f124SMoriah Waterland 			quit(99);
13795c51f124SMoriah Waterland 			/*NOTREACHED*/
13805c51f124SMoriah Waterland 		}
13815c51f124SMoriah Waterland 		if ((++npkgs % MALSIZ) == 0) {
13825c51f124SMoriah Waterland 			prvinfo = (struct pkginfo *)realloc(prvinfo,
13835c51f124SMoriah Waterland 				(npkgs+MALSIZ) * sizeof (struct pkginfo));
13845c51f124SMoriah Waterland 			if (prvinfo == NULL) {
13855c51f124SMoriah Waterland 				progerr(ERR_MEMORY, errno);
13865c51f124SMoriah Waterland 				quit(99);
13875c51f124SMoriah Waterland 				/*NOTREACHED*/
13885c51f124SMoriah Waterland 			}
13895c51f124SMoriah Waterland 		}
13905c51f124SMoriah Waterland 	}
13915c51f124SMoriah Waterland 
13925c51f124SMoriah Waterland 	/*
13935c51f124SMoriah Waterland 	 * Determine the correct package instance based on how many packages are
13945c51f124SMoriah Waterland 	 * already installed. If there are none (npkgs == 0), getinst() just
13955c51f124SMoriah Waterland 	 * returns the package abbreviation. Otherwise, getinst() interacts with
13965c51f124SMoriah Waterland 	 * the user (or reads the admin file) to determine if an instance which
13975c51f124SMoriah Waterland 	 * is already installed should be overwritten, or possibly install a new
13985c51f124SMoriah Waterland 	 * instance of this package
13995c51f124SMoriah Waterland 	 */
14005c51f124SMoriah Waterland 
14015c51f124SMoriah Waterland 	pkginst = getinst(&update, prvinfo, npkgs, preinstallCheck);
14025c51f124SMoriah Waterland 
14035c51f124SMoriah Waterland 	/* set "update flag" if updating an existing instance of this package */
14045c51f124SMoriah Waterland 
14055c51f124SMoriah Waterland 	if (update) {
14065c51f124SMoriah Waterland 		setUpdate();
14075c51f124SMoriah Waterland 	}
14085c51f124SMoriah Waterland 
14095c51f124SMoriah Waterland 	/*
1410*4656d474SGarrett D'Amore 	 * Some pkgs (SUNWcsr) already spooled to the zone, check the
1411*4656d474SGarrett D'Amore 	 * value of UPDATE in their postinstall script.  After a pkg
1412*4656d474SGarrett D'Amore 	 * has been patched UPDATE exists statically in the pkginfo
1413*4656d474SGarrett D'Amore 	 * file and this value must be reset when installing a zone.
14145c51f124SMoriah Waterland 	 */
14155c51f124SMoriah Waterland 
1416*4656d474SGarrett D'Amore 	if (saveSpoolInstall != 0 && !isUpdate()) {
14175c51f124SMoriah Waterland 		putparam("UPDATE", "");
14185c51f124SMoriah Waterland 	}
14195c51f124SMoriah Waterland 
14205c51f124SMoriah Waterland 	/* inform quit() if updating existing or installing new instance */
14215c51f124SMoriah Waterland 
14225c51f124SMoriah Waterland 	quitSetUpdatingExisting(update ? B_TRUE : B_FALSE);
14235c51f124SMoriah Waterland 
14245c51f124SMoriah Waterland 	if (respfile) {
14255c51f124SMoriah Waterland 		(void) set_respfile(respfile, pkginst, RESP_RO);
14265c51f124SMoriah Waterland 	}
14275c51f124SMoriah Waterland 
14285c51f124SMoriah Waterland 	(void) snprintf(pkgloc, sizeof (pkgloc),
14295c51f124SMoriah Waterland 			"%s/%s", get_PKGLOC(), pkginst);
14305c51f124SMoriah Waterland 
14315c51f124SMoriah Waterland 	(void) snprintf(pkgbin, sizeof (pkgbin),
14325c51f124SMoriah Waterland 			"%s/install", pkgloc);
14335c51f124SMoriah Waterland 
14345c51f124SMoriah Waterland 	(void) snprintf(pkgsav, sizeof (pkgsav),
14355c51f124SMoriah Waterland 			"%s/save", pkgloc);
14365c51f124SMoriah Waterland 
14375c51f124SMoriah Waterland 	if (snprintf(saveSpoolInstallDir, PATH_MAX, "%s/pspool/%s", pkgsav,
14385c51f124SMoriah Waterland 			pkginst) < 0) {
14395c51f124SMoriah Waterland 		progerr(ERR_SNPRINTF, saveSpoolInstallDir);
14405c51f124SMoriah Waterland 		quit(99);
14415c51f124SMoriah Waterland 		/*NOTREACHED*/
14425c51f124SMoriah Waterland 	}
14435c51f124SMoriah Waterland 
14445c51f124SMoriah Waterland 	(void) snprintf(ilockfile, sizeof (ilockfile),
14455c51f124SMoriah Waterland 			"%s/!I-Lock!", pkgloc);
14465c51f124SMoriah Waterland 	(void) snprintf(rlockfile, sizeof (rlockfile),
14475c51f124SMoriah Waterland 			"%s/!R-Lock!", pkgloc);
14485c51f124SMoriah Waterland 	(void) snprintf(savlog, sizeof (savlog),
14495c51f124SMoriah Waterland 			"%s/logs/%s", get_PKGADM(), pkginst);
14505c51f124SMoriah Waterland 
14515c51f124SMoriah Waterland 	putparam("PKGINST", pkginst);
14525c51f124SMoriah Waterland 	putparam("PKGSAV", pkgsav);
14535c51f124SMoriah Waterland 
14545c51f124SMoriah Waterland 	/*
14555c51f124SMoriah Waterland 	 * Be sure request script has access to PKG_INSTALL_ROOT if there is
14565c51f124SMoriah Waterland 	 * one
14575c51f124SMoriah Waterland 	 */
14585c51f124SMoriah Waterland 
14595c51f124SMoriah Waterland 	put_path_params();
14605c51f124SMoriah Waterland 
14615c51f124SMoriah Waterland 	if (!map_client) {
14625c51f124SMoriah Waterland 		putparam("PKG_NO_UNIFIED", "TRUE");
14635c51f124SMoriah Waterland 	}
14645c51f124SMoriah Waterland 
14655c51f124SMoriah Waterland 	/*
14665c51f124SMoriah Waterland 	 * This maps the client filesystems into the server's space.
14675c51f124SMoriah Waterland 	 */
14685c51f124SMoriah Waterland 
14695c51f124SMoriah Waterland 	if (map_client && !mount_client()) {
14705c51f124SMoriah Waterland 		logerr(MSG_MANMOUNT);
14715c51f124SMoriah Waterland 	}
14725c51f124SMoriah Waterland 
14735c51f124SMoriah Waterland 	/*
14745c51f124SMoriah Waterland 	 * If this is an UPDATE then either this is exactly the same version
14755c51f124SMoriah Waterland 	 * and architecture of an installed package or a different package is
14765c51f124SMoriah Waterland 	 * intended to entirely replace an installed package of the same name
14775c51f124SMoriah Waterland 	 * with a different VERSION or ARCH string.
14785c51f124SMoriah Waterland 	 * Don't merge any databases if only gathering dependencies.
14795c51f124SMoriah Waterland 	 */
14805c51f124SMoriah Waterland 
14815c51f124SMoriah Waterland 	if ((preinstallCheck == B_FALSE) && (update)) {
14825c51f124SMoriah Waterland 		/*
14835c51f124SMoriah Waterland 		 * If this version and architecture is already installed,
14845c51f124SMoriah Waterland 		 * merge the installed and installing parameters and inform
14855c51f124SMoriah Waterland 		 * all procedure scripts by defining UPDATE in the
14865c51f124SMoriah Waterland 		 * environment.
14875c51f124SMoriah Waterland 		 */
14885c51f124SMoriah Waterland 
14895c51f124SMoriah Waterland 		if (is_samepkg()) {
14905c51f124SMoriah Waterland 			/*
14915c51f124SMoriah Waterland 			 * If it's the same ARCH and VERSION, then a merge
14925c51f124SMoriah Waterland 			 * and copy operation is necessary.
14935c51f124SMoriah Waterland 			 */
14945c51f124SMoriah Waterland 
14955c51f124SMoriah Waterland 			if (n = merg_pkginfos(pclass, &mergd_pclass)) {
14965c51f124SMoriah Waterland 				quit(n);
14975c51f124SMoriah Waterland 				/*NOTREACHED*/
14985c51f124SMoriah Waterland 			}
14995c51f124SMoriah Waterland 
15005c51f124SMoriah Waterland 			if (n = cp_pkgdirs()) {
15015c51f124SMoriah Waterland 				quit(n);
15025c51f124SMoriah Waterland 				/*NOTREACHED*/
15035c51f124SMoriah Waterland 			}
15045c51f124SMoriah Waterland 
15055c51f124SMoriah Waterland 		} else {
15065c51f124SMoriah Waterland 			/*
15075c51f124SMoriah Waterland 			 * If it's a different ARCH and/or VERSION then this
15085c51f124SMoriah Waterland 			 * is an "instance=overwrite" situation. The
15095c51f124SMoriah Waterland 			 * installed base needs to be confirmed and the
15105c51f124SMoriah Waterland 			 * package directories renamed.
15115c51f124SMoriah Waterland 			 */
15125c51f124SMoriah Waterland 
15135c51f124SMoriah Waterland 			if (n = ck_instbase()) {
15145c51f124SMoriah Waterland 				quit(n);
15155c51f124SMoriah Waterland 				/*NOTREACHED*/
15165c51f124SMoriah Waterland 			}
15175c51f124SMoriah Waterland 
15185c51f124SMoriah Waterland 			if (n = mv_pkgdirs()) {
15195c51f124SMoriah Waterland 				quit(n);
15205c51f124SMoriah Waterland 				/*NOTREACHED*/
15215c51f124SMoriah Waterland 			}
15225c51f124SMoriah Waterland 		}
15235c51f124SMoriah Waterland 
15245c51f124SMoriah Waterland 		putparam("UPDATE", "yes");
15255c51f124SMoriah Waterland 
15265c51f124SMoriah Waterland 	}
15275c51f124SMoriah Waterland 
15285c51f124SMoriah Waterland 	if (in_dryrun_mode()) {
15295c51f124SMoriah Waterland 		set_dryrun_dir_loc();
15305c51f124SMoriah Waterland 	}
15315c51f124SMoriah Waterland 
15325c51f124SMoriah Waterland 	if (preinstallCheck == B_FALSE) {
15335c51f124SMoriah Waterland 		/*
15345c51f124SMoriah Waterland 		 * Determine if the package has been partially installed on or
15355c51f124SMoriah Waterland 		 * removed from this system.
15365c51f124SMoriah Waterland 		 */
15375c51f124SMoriah Waterland 		ck_w_dryrun(ckpartial, PARTIAL);
15385c51f124SMoriah Waterland 
15395c51f124SMoriah Waterland 		/*
15405c51f124SMoriah Waterland 		 * make sure current runlevel is appropriate
15415c51f124SMoriah Waterland 		 */
15425c51f124SMoriah Waterland 		ck_w_dryrun(ckrunlevel, RUNLEVEL);
15435c51f124SMoriah Waterland 	} else {
15445c51f124SMoriah Waterland 		int	r;
15455c51f124SMoriah Waterland 
15465c51f124SMoriah Waterland 		/*
15475c51f124SMoriah Waterland 		 * Just gathering dependencies - determine if the package has
15485c51f124SMoriah Waterland 		 * been partially installed on or removed from this system and
15495c51f124SMoriah Waterland 		 * output information to stdout
15505c51f124SMoriah Waterland 		 */
15515c51f124SMoriah Waterland 		r = ckpartial();
15525c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckpartialinstall=%d\n", r == 8 ? 1 : 0);
15535c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckpartialremove=%d\n", r == 9 ? 1 : 0);
15545c51f124SMoriah Waterland 
15555c51f124SMoriah Waterland 		/*
15565c51f124SMoriah Waterland 		 * make sure current runlevel is appropriate
15575c51f124SMoriah Waterland 		 */
15585c51f124SMoriah Waterland 		r = ckrunlevel();
15595c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckrunlevel=%d\n", r);
15605c51f124SMoriah Waterland 	}
15615c51f124SMoriah Waterland 
15625c51f124SMoriah Waterland 	if (pkgdev.cdevice) {
15635c51f124SMoriah Waterland 		/* get first volume which contains info files */
15645c51f124SMoriah Waterland 		unpack();
15655c51f124SMoriah Waterland 		if (!suppressCopyright) {
15665c51f124SMoriah Waterland 			copyright();
15675c51f124SMoriah Waterland 		}
15685c51f124SMoriah Waterland 	}
15695c51f124SMoriah Waterland 
15705c51f124SMoriah Waterland 	/* update the lock - at the request script */
15715c51f124SMoriah Waterland 
15725c51f124SMoriah Waterland 	lockupd("request");
15735c51f124SMoriah Waterland 
15745c51f124SMoriah Waterland 	/*
15755c51f124SMoriah Waterland 	 * If no response file has been provided, initialize response file by
15765c51f124SMoriah Waterland 	 * executing any request script provided by this package. Initialize
15775c51f124SMoriah Waterland 	 * the response file if not gathering dependencies only.
15785c51f124SMoriah Waterland 	 */
15795c51f124SMoriah Waterland 
15805c51f124SMoriah Waterland 	if ((!rdonly_respfile()) && (preinstallCheck == B_FALSE)) {
15815c51f124SMoriah Waterland 		(void) snprintf(path, sizeof (path),
15825c51f124SMoriah Waterland 			"%s/%s", instdir, REQUEST_FILE);
15835c51f124SMoriah Waterland 		n = reqexec(update, path, non_abi_scripts,
15845c51f124SMoriah Waterland 			run_request_as_root);
15855c51f124SMoriah Waterland 		if (in_dryrun_mode()) {
15865c51f124SMoriah Waterland 			set_dr_info(REQUESTEXITCODE, n);
15875c51f124SMoriah Waterland 		}
15885c51f124SMoriah Waterland 
15895c51f124SMoriah Waterland 		ckreturn(n, ERR_REQUEST);
15905c51f124SMoriah Waterland 	}
15915c51f124SMoriah Waterland 
15925c51f124SMoriah Waterland 	/*
15935c51f124SMoriah Waterland 	 * Look for all parameters in response file which begin with a
15945c51f124SMoriah Waterland 	 * capital letter, and place them in the environment.
15955c51f124SMoriah Waterland 	 */
15965c51f124SMoriah Waterland 
15975c51f124SMoriah Waterland 	if ((is_a_respfile()) && (preinstallCheck == B_FALSE)) {
15985c51f124SMoriah Waterland 		if (n = merg_respfile()) {
15995c51f124SMoriah Waterland 			quit(n);
16005c51f124SMoriah Waterland 			/*NOTREACHED*/
16015c51f124SMoriah Waterland 		}
16025c51f124SMoriah Waterland 	}
16035c51f124SMoriah Waterland 
16045c51f124SMoriah Waterland 	/*
16055c51f124SMoriah Waterland 	 * Run a checkinstall script if one is provided by the package.
16065c51f124SMoriah Waterland 	 * Don't execute checkinstall script if we are only updating the DB.
16075c51f124SMoriah Waterland 	 * Don't execute checkinstall script if only gathering dependencies.
16085c51f124SMoriah Waterland 	 */
16095c51f124SMoriah Waterland 
16105c51f124SMoriah Waterland 	/* update the lock - at the checkinstall script */
16115c51f124SMoriah Waterland 	lockupd("checkinstall");
16125c51f124SMoriah Waterland 
16135c51f124SMoriah Waterland 	/* Execute checkinstall script if one is provided. */
16145c51f124SMoriah Waterland 	(void) snprintf(script, sizeof (script), "%s/install/checkinstall",
16155c51f124SMoriah Waterland 			instdir);
16165c51f124SMoriah Waterland 	if (access(script, F_OK) != 0) {
16175c51f124SMoriah Waterland 		/* no script present */
16185c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_COC_NONE, pkginst, script,
16195c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
16205c51f124SMoriah Waterland 	} else if (is_depend_pkginfo_DB()) {
16215c51f124SMoriah Waterland 		/* updating db only: skip checkinstall script */
16225c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_COC_DBUPD, pkginst, script,
16235c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
16245c51f124SMoriah Waterland 	} else if (preinstallCheck == B_TRUE) {
16255c51f124SMoriah Waterland 		/* only gathering dependencies: skip checkinstall script */
16265c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_COC_NODEL, pkginst, script,
16275c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
16285c51f124SMoriah Waterland 	} else {
16295c51f124SMoriah Waterland 		/* script present and ok to run: run the script */
16305c51f124SMoriah Waterland 		if (zoneName == (char *)NULL) {
16315c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXECOC_GZ);
16325c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXECOC_GZ, pkginst, script);
16335c51f124SMoriah Waterland 		} else {
16345c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXECOC_LZ, zoneName);
16355c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXECOC_LZ, pkginst, script,
16365c51f124SMoriah Waterland 				zoneName);
16375c51f124SMoriah Waterland 		}
16385c51f124SMoriah Waterland 		n = chkexec(update, script);
16395c51f124SMoriah Waterland 		if (in_dryrun_mode()) {
16405c51f124SMoriah Waterland 			set_dr_info(CHECKEXITCODE, n);
16415c51f124SMoriah Waterland 		}
16425c51f124SMoriah Waterland 
16435c51f124SMoriah Waterland 		if (n == 3) {
16445c51f124SMoriah Waterland 			echo(WRN_CHKINSTALL);
16455c51f124SMoriah Waterland 			ckreturn(4, NULL);
16465c51f124SMoriah Waterland 		} else if (n == 7) {
16475c51f124SMoriah Waterland 			/* access returned error */
16485c51f124SMoriah Waterland 			progerr(ERR_CHKINSTALL_NOSCRIPT, script);
16495c51f124SMoriah Waterland 			ckreturn(4, ERR_CHKINSTALL);
16505c51f124SMoriah Waterland 		} else {
16515c51f124SMoriah Waterland 			ckreturn(n, ERR_CHKINSTALL);
16525c51f124SMoriah Waterland 		}
16535c51f124SMoriah Waterland 	}
16545c51f124SMoriah Waterland 
16555c51f124SMoriah Waterland 	/*
16565c51f124SMoriah Waterland 	 * Now that the internal data structures are initialized, we can
16575c51f124SMoriah Waterland 	 * initialize the dryrun files (which may be the same files).
16585c51f124SMoriah Waterland 	 */
16595c51f124SMoriah Waterland 
16605c51f124SMoriah Waterland 	if (pkgdrtarg) {
16615c51f124SMoriah Waterland 		init_dryrunfile(pkgdrtarg);
16625c51f124SMoriah Waterland 	}
16635c51f124SMoriah Waterland 
16645c51f124SMoriah Waterland 	/*
16655c51f124SMoriah Waterland 	 * Look for all parameters in response file which begin with a
16665c51f124SMoriah Waterland 	 * capital letter, and place them in the environment.
16675c51f124SMoriah Waterland 	 */
16685c51f124SMoriah Waterland 	if (is_a_respfile()) {
16695c51f124SMoriah Waterland 		if (n = merg_respfile()) {
16705c51f124SMoriah Waterland 			quit(n);
16715c51f124SMoriah Waterland 			/*NOTREACHED*/
16725c51f124SMoriah Waterland 		}
16735c51f124SMoriah Waterland 	}
16745c51f124SMoriah Waterland 
16755c51f124SMoriah Waterland 	/* update the lock - doing analysis */
16765c51f124SMoriah Waterland 
16775c51f124SMoriah Waterland 	lockupd("analysis");
16785c51f124SMoriah Waterland 
16795c51f124SMoriah Waterland 	/*
16805c51f124SMoriah Waterland 	 * Determine package base directory and client base directory
16815c51f124SMoriah Waterland 	 * if appropriate. Then encapsulate them for future retrieval.
16825c51f124SMoriah Waterland 	 */
16835c51f124SMoriah Waterland 	if ((err = set_basedirs(isreloc(instdir), adm.basedir, pkginst,
16845c51f124SMoriah Waterland 		nointeract)) != 0) {
16855c51f124SMoriah Waterland 		quit(err);
16865c51f124SMoriah Waterland 		/*NOTREACHED*/
16875c51f124SMoriah Waterland 	}
16885c51f124SMoriah Waterland 
16895c51f124SMoriah Waterland 	/*
16905c51f124SMoriah Waterland 	 * Create the base directory if specified.
16915c51f124SMoriah Waterland 	 * Don't create if we are only updating the DB.
16925c51f124SMoriah Waterland 	 * Don't create if only gathering dependencies.
16935c51f124SMoriah Waterland 	 */
16945c51f124SMoriah Waterland 
16955c51f124SMoriah Waterland 	if (!is_depend_pkginfo_DB() &&
16965c51f124SMoriah Waterland 		!preinstallCheck && is_a_basedir()) {
16975c51f124SMoriah Waterland 		mkbasedir(!nointeract, get_basedir());
16985c51f124SMoriah Waterland 		echo(MSG_BASE_USED, get_basedir());
16995c51f124SMoriah Waterland 	}
17005c51f124SMoriah Waterland 
17015c51f124SMoriah Waterland 	/*
17025c51f124SMoriah Waterland 	 * Store PKG_INSTALL_ROOT, BASEDIR & CLIENT_BASEDIR in our
17035c51f124SMoriah Waterland 	 * environment for later use by procedure scripts.
17045c51f124SMoriah Waterland 	 */
17055c51f124SMoriah Waterland 	put_path_params();
17065c51f124SMoriah Waterland 
17075c51f124SMoriah Waterland 	/*
17085c51f124SMoriah Waterland 	 * the following two checks are done in the corresponding
17095c51f124SMoriah Waterland 	 * ck() routine, but are repeated here to avoid re-processing
17105c51f124SMoriah Waterland 	 * the database if we are administered to not include these
17115c51f124SMoriah Waterland 	 * processes
17125c51f124SMoriah Waterland 	 */
17135c51f124SMoriah Waterland 	if (ADM(setuid, "nochange")) {
17145c51f124SMoriah Waterland 		nosetuid++;	/* Clear setuid/gid bits. */
17155c51f124SMoriah Waterland 	}
17165c51f124SMoriah Waterland 
17175c51f124SMoriah Waterland 	if (ADM(conflict, "nochange")) {
17185c51f124SMoriah Waterland 		nocnflct++;	/* Don't install conflicting files. */
17195c51f124SMoriah Waterland 	}
17205c51f124SMoriah Waterland 
17215c51f124SMoriah Waterland 	/*
17225c51f124SMoriah Waterland 	 * Get the filesystem space information for the filesystem on which
17235c51f124SMoriah Waterland 	 * the "contents" file resides.
17245c51f124SMoriah Waterland 	 */
17255c51f124SMoriah Waterland 
17265c51f124SMoriah Waterland 	svfsb.f_bsize = 8192;
17275c51f124SMoriah Waterland 	svfsb.f_frsize = 1024;
17285c51f124SMoriah Waterland 
17295c51f124SMoriah Waterland 	if (statvfs64(get_PKGADM(), &svfsb) == -1) {
17305c51f124SMoriah Waterland 		int	lerrno = errno;
17315c51f124SMoriah Waterland 		if (!access(get_PKGADM(), F_OK)) {
17325c51f124SMoriah Waterland 			progerr(ERR_PKGINSTALL_STATVFS, get_PKGADM(),
17335c51f124SMoriah Waterland 				strerror(errno));
17345c51f124SMoriah Waterland 			logerr("(errno %d)", lerrno);
17355c51f124SMoriah Waterland 			quit(99);
17365c51f124SMoriah Waterland 			/*NOTREACHED*/
17375c51f124SMoriah Waterland 		}
17385c51f124SMoriah Waterland 	}
17395c51f124SMoriah Waterland 
17405c51f124SMoriah Waterland 	/*
17415c51f124SMoriah Waterland 	 * Get the number of blocks used by the pkgmap, ocfile()
17425c51f124SMoriah Waterland 	 * needs this to properly determine its space requirements.
17435c51f124SMoriah Waterland 	 */
17445c51f124SMoriah Waterland 
17455c51f124SMoriah Waterland 	if (stat(p_pkgmap, &statb) == -1) {
17465c51f124SMoriah Waterland 		progerr(ERR_PKGINSTALL_STATOF, p_pkgmap, strerror(errno));
17475c51f124SMoriah Waterland 		quit(99);
17485c51f124SMoriah Waterland 		/*NOTREACHED*/
17495c51f124SMoriah Waterland 	}
17505c51f124SMoriah Waterland 
17515c51f124SMoriah Waterland 	pkgmap_blks = nblk(statb.st_size, svfsb.f_bsize, svfsb.f_frsize);
17525c51f124SMoriah Waterland 
17535c51f124SMoriah Waterland 	/*
17545c51f124SMoriah Waterland 	 * Merge information in memory with the "contents" file; this creates
17555c51f124SMoriah Waterland 	 * a temporary version of the "contents" file. Note that in dryrun
17565c51f124SMoriah Waterland 	 * mode, we still need to record the contents file data somewhere,
17575c51f124SMoriah Waterland 	 * but we do it in the dryrun directory.
17585c51f124SMoriah Waterland 	 */
17595c51f124SMoriah Waterland 
17605c51f124SMoriah Waterland 	if (in_dryrun_mode()) {
17615c51f124SMoriah Waterland 		if (n = set_cfdir(pkgdrtarg)) {
17625c51f124SMoriah Waterland 			quit(n);
17635c51f124SMoriah Waterland 			/*NOTREACHED*/
17645c51f124SMoriah Waterland 		}
17655c51f124SMoriah Waterland 	} else {
17665c51f124SMoriah Waterland 		if (n = set_cfdir(NULL)) {
17675c51f124SMoriah Waterland 			quit(n);
17685c51f124SMoriah Waterland 			/*NOTREACHED*/
17695c51f124SMoriah Waterland 		}
17705c51f124SMoriah Waterland 	}
177162224350SCasper H.S. Dik 	if (!ocfile(&pkgserver, &cfTmpVfp, pkgmap_blks)) {
17725c51f124SMoriah Waterland 		quit(99);
17735c51f124SMoriah Waterland 		/*NOTREACHED*/
17745c51f124SMoriah Waterland 	}
17755c51f124SMoriah Waterland 
17765c51f124SMoriah Waterland 	/*
17775c51f124SMoriah Waterland 	 * if cpio is being used,  tell pkgdbmerg since attributes will
17785c51f124SMoriah Waterland 	 * have to be check and repaired on all file and directories
17795c51f124SMoriah Waterland 	 */
17805c51f124SMoriah Waterland 	for (np = cpio_names; *np != NULL; np++) {
17815c51f124SMoriah Waterland 		(void) snprintf(path, sizeof (path),
17825c51f124SMoriah Waterland 			"%s/%s", instdir, *np);
17835c51f124SMoriah Waterland 		if (iscpio(path, &is_comp_arch)) {
17845c51f124SMoriah Waterland 			is_WOS_arch();
17855c51f124SMoriah Waterland 			break;
17865c51f124SMoriah Waterland 		}
17875c51f124SMoriah Waterland 	}
17885c51f124SMoriah Waterland 
17895c51f124SMoriah Waterland 	/* Establish the class list and the class attributes. */
17905c51f124SMoriah Waterland 	cl_sets(getenv("CLASSES"));
17915c51f124SMoriah Waterland 	find_CAS(I_ONLY, pkgbin, instdir);
17925c51f124SMoriah Waterland 
17935c51f124SMoriah Waterland 	if (vfpOpen(&pkgmapVfp, p_pkgmap, "r", VFP_NEEDNOW) != 0) {
17945c51f124SMoriah Waterland 		progerr(ERR_PKGMAP, p_pkgmap);
17955c51f124SMoriah Waterland 		quit(99);
17965c51f124SMoriah Waterland 		/*NOTREACHED*/
17975c51f124SMoriah Waterland 	}
17985c51f124SMoriah Waterland 
17995c51f124SMoriah Waterland 	/*
18005c51f124SMoriah Waterland 	 * This modifies the path list entries in memory to reflect
18015c51f124SMoriah Waterland 	 * how they should look after the merg is complete
18025c51f124SMoriah Waterland 	 */
18035c51f124SMoriah Waterland 
180462224350SCasper H.S. Dik 	nparts = sortmap(&extlist, pkgmapVfp, pkgserver, cfTmpVfp, zoneName);
18055c51f124SMoriah Waterland 
18065c51f124SMoriah Waterland 	if ((n = files_installed()) > 0) {
18075c51f124SMoriah Waterland 		if (n > 1) {
18085c51f124SMoriah Waterland 			echo(MSG_INST_MANY, n);
18095c51f124SMoriah Waterland 		} else {
18105c51f124SMoriah Waterland 			echo(MSG_INST_ONE, n);
18115c51f124SMoriah Waterland 		}
18125c51f124SMoriah Waterland 	}
18135c51f124SMoriah Waterland 
18145c51f124SMoriah Waterland 	/*
18155c51f124SMoriah Waterland 	 * Check ulimit requirement (provided in pkginfo). The purpose of
18165c51f124SMoriah Waterland 	 * this limit is to terminate pathological file growth resulting from
18175c51f124SMoriah Waterland 	 * file edits in scripts. It does not apply to files in the pkgmap
18185c51f124SMoriah Waterland 	 * and it does not apply to any database files manipulated by the
18195c51f124SMoriah Waterland 	 * installation service.
18205c51f124SMoriah Waterland 	 */
18215c51f124SMoriah Waterland 	if (pt = getenv("ULIMIT")) {
18225c51f124SMoriah Waterland 		if (assign_ulimit(pt) == -1) {
18235c51f124SMoriah Waterland 			progerr(ERR_BADULIMIT, pt);
18245c51f124SMoriah Waterland 			quit(99);
18255c51f124SMoriah Waterland 			/*NOTREACHED*/
18265c51f124SMoriah Waterland 		}
18275c51f124SMoriah Waterland 		putparam("PKG_ULIMIT", "TRUE");
18285c51f124SMoriah Waterland 	}
18295c51f124SMoriah Waterland 
18305c51f124SMoriah Waterland 	/*
18315c51f124SMoriah Waterland 	 * If only gathering dependencies, check and output status of all
18325c51f124SMoriah Waterland 	 * remaining dependencies and exit.
18335c51f124SMoriah Waterland 	 */
18345c51f124SMoriah Waterland 
18355c51f124SMoriah Waterland 	if (preinstallCheck == B_TRUE) {
18365c51f124SMoriah Waterland 		/* update the lock file - final checking */
18375c51f124SMoriah Waterland 
18385c51f124SMoriah Waterland 		lockupd("preinstallcheck");
18395c51f124SMoriah Waterland 
18405c51f124SMoriah Waterland 		/* verify package information files are not corrupt */
18415c51f124SMoriah Waterland 
18425c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckpkgfiles=%d\n", ckpkgfiles());
18435c51f124SMoriah Waterland 
18445c51f124SMoriah Waterland 		/* verify package dependencies */
18455c51f124SMoriah Waterland 
18465c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckdepend=%d\n", ckdepend());
18475c51f124SMoriah Waterland 
18485c51f124SMoriah Waterland 		/* Check space requirements */
18495c51f124SMoriah Waterland 
18505c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckspace=%d\n", ckspace());
18515c51f124SMoriah Waterland 
18525c51f124SMoriah Waterland 		/*
18535c51f124SMoriah Waterland 		 * Determine if any objects provided by this package conflict
18545c51f124SMoriah Waterland 		 * with the files of previously installed packages.
18555c51f124SMoriah Waterland 		 */
18565c51f124SMoriah Waterland 
18575c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckconflict=%d\n", ckconflct());
18585c51f124SMoriah Waterland 
18595c51f124SMoriah Waterland 		/*
18605c51f124SMoriah Waterland 		 * Determine if any objects provided by this package will be
18615c51f124SMoriah Waterland 		 * installed with setuid or setgid enabled.
18625c51f124SMoriah Waterland 		 */
18635c51f124SMoriah Waterland 
18645c51f124SMoriah Waterland 		(void) fprintf(stdout, "cksetuid=%d\n", cksetuid());
18655c51f124SMoriah Waterland 
18665c51f124SMoriah Waterland 		/*
18675c51f124SMoriah Waterland 		 * Determine if any packaging scripts provided with this package
18685c51f124SMoriah Waterland 		 * will execute as a priviledged user.
18695c51f124SMoriah Waterland 		 */
18705c51f124SMoriah Waterland 
18715c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckpriv=%d\n", ckpriv());
18725c51f124SMoriah Waterland 
18735c51f124SMoriah Waterland 		/* Verify neccessary package installation directories exist */
18745c51f124SMoriah Waterland 
18755c51f124SMoriah Waterland 		(void) fprintf(stdout, "ckpkgdirs=%d\n", ckpkgdirs());
18765c51f124SMoriah Waterland 
18775c51f124SMoriah Waterland 		/*
18785c51f124SMoriah Waterland 		 * ****** preinstall check done - exit ******
18795c51f124SMoriah Waterland 		 */
18805c51f124SMoriah Waterland 
18815c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_PREINSCHK_OK);
18825c51f124SMoriah Waterland 		quit(0);
18835c51f124SMoriah Waterland 		/*NOTREACHED*/
18845c51f124SMoriah Waterland 	}
18855c51f124SMoriah Waterland 
18865c51f124SMoriah Waterland 	/*
18875c51f124SMoriah Waterland 	 * Not gathering dependencies only, proceed to check dependencies
18885c51f124SMoriah Waterland 	 * and continue with the package installation operation.
18895c51f124SMoriah Waterland 	 */
18905c51f124SMoriah Waterland 
18915c51f124SMoriah Waterland 	/*
18925c51f124SMoriah Waterland 	 * verify package information files are not corrupt
18935c51f124SMoriah Waterland 	 */
18945c51f124SMoriah Waterland 	ck_w_dryrun(ckpkgfiles, PKGFILES);
18955c51f124SMoriah Waterland 
18965c51f124SMoriah Waterland 	/*
18975c51f124SMoriah Waterland 	 * verify package dependencies
18985c51f124SMoriah Waterland 	 */
18995c51f124SMoriah Waterland 	ck_w_dryrun(ckdepend, DEPEND);
19005c51f124SMoriah Waterland 
19015c51f124SMoriah Waterland 	/*
19025c51f124SMoriah Waterland 	 * Check space requirements.
19035c51f124SMoriah Waterland 	 */
19045c51f124SMoriah Waterland 	ck_w_dryrun(ckspace, SPACE);
19055c51f124SMoriah Waterland 
19065c51f124SMoriah Waterland 	/*
19075c51f124SMoriah Waterland 	 * Determine if any objects provided by this package conflict with
19085c51f124SMoriah Waterland 	 * the files of previously installed packages.
19095c51f124SMoriah Waterland 	 */
19105c51f124SMoriah Waterland 	ck_w_dryrun(ckconflct, CONFLICT);
19115c51f124SMoriah Waterland 
19125c51f124SMoriah Waterland 	/*
19135c51f124SMoriah Waterland 	 * Determine if any objects provided by this package will be
19145c51f124SMoriah Waterland 	 * installed with setuid or setgid enabled.
19155c51f124SMoriah Waterland 	 */
19165c51f124SMoriah Waterland 	ck_w_dryrun(cksetuid, SETUID);
19175c51f124SMoriah Waterland 
19185c51f124SMoriah Waterland 	/*
19195c51f124SMoriah Waterland 	 * Determine if any packaging scripts provided with this package will
19205c51f124SMoriah Waterland 	 * execute as a priviledged user.
19215c51f124SMoriah Waterland 	 */
19225c51f124SMoriah Waterland 	ck_w_dryrun(ckpriv, PRIV);
19235c51f124SMoriah Waterland 
19245c51f124SMoriah Waterland 	/*
19255c51f124SMoriah Waterland 	 * Verify neccessary package installation directories exist.
19265c51f124SMoriah Waterland 	 */
19275c51f124SMoriah Waterland 	ck_w_dryrun(ckpkgdirs, PKGDIRS);
19285c51f124SMoriah Waterland 
19295c51f124SMoriah Waterland 	/*
19305c51f124SMoriah Waterland 	 * If we have assumed that we were installing setuid or conflicting
19315c51f124SMoriah Waterland 	 * files, and the user chose to do otherwise, we need to read in the
19325c51f124SMoriah Waterland 	 * package map again and re-merg with the "contents" file
19335c51f124SMoriah Waterland 	 */
19345c51f124SMoriah Waterland 
19355c51f124SMoriah Waterland 	if (rprcflag) {
193662224350SCasper H.S. Dik 		nparts = sortmap(&extlist, pkgmapVfp, pkgserver,
19375c51f124SMoriah Waterland 				cfTmpVfp, zoneName);
19385c51f124SMoriah Waterland 	}
19395c51f124SMoriah Waterland 
19405c51f124SMoriah Waterland 	(void) vfpClose(&pkgmapVfp);
19415c51f124SMoriah Waterland 
19425c51f124SMoriah Waterland 	/* BEGIN INSTALLATION PHASE */
19435c51f124SMoriah Waterland 	if (in_dryrun_mode()) {
19445c51f124SMoriah Waterland 		echo(MSG_PKGINSTALL_DRYRUN, pkgname, pkginst);
19455c51f124SMoriah Waterland 	} else if (zoneName == (char *)NULL) {
19465c51f124SMoriah Waterland 		echo(MSG_PKGINSTALL_INSIN_GZ, pkgname, pkginst);
19475c51f124SMoriah Waterland 	} else {
19485c51f124SMoriah Waterland 		echo(MSG_PKGINSTALL_INSIN_LZ, pkgname, pkginst, zoneName);
19495c51f124SMoriah Waterland 	}
19505c51f124SMoriah Waterland 
19515c51f124SMoriah Waterland 	/* inform quit that the install has started */
19525c51f124SMoriah Waterland 
19535c51f124SMoriah Waterland 	quitSetInstallStarted(B_TRUE);
19545c51f124SMoriah Waterland 
19555c51f124SMoriah Waterland 	/*
19565c51f124SMoriah Waterland 	 * This replaces the contents file with recently created temp version
19575c51f124SMoriah Waterland 	 * which contains information about the objects being installed.
19585c51f124SMoriah Waterland 	 * Under old lock protocol it closes both files and releases the
19595c51f124SMoriah Waterland 	 * locks. Beginning in Solaris 2.7, this lock method should be
19605c51f124SMoriah Waterland 	 * reviewed.
19615c51f124SMoriah Waterland 	 */
19625c51f124SMoriah Waterland 
196362224350SCasper H.S. Dik 	n = swapcfile(pkgserver, &cfTmpVfp, pkginst, dbchg);
19645c51f124SMoriah Waterland 	if (n == RESULT_WRN) {
19655c51f124SMoriah Waterland 		warnflag++;
19665c51f124SMoriah Waterland 	} else if (n == RESULT_ERR) {
19675c51f124SMoriah Waterland 		quit(99);
19685c51f124SMoriah Waterland 		/*NOTREACHED*/
19695c51f124SMoriah Waterland 	}
19705c51f124SMoriah Waterland 
19715c51f124SMoriah Waterland 	/*
19725c51f124SMoriah Waterland 	 * Create install-specific lockfile to indicate start of
19735c51f124SMoriah Waterland 	 * installation. This is really just an information file. If the
19745c51f124SMoriah Waterland 	 * process dies, the initial lockfile (from lockinst(), is
19755c51f124SMoriah Waterland 	 * relinquished by the kernel, but this one remains in support of the
19765c51f124SMoriah Waterland 	 * post-mortem.
19775c51f124SMoriah Waterland 	 */
19785c51f124SMoriah Waterland 
19795c51f124SMoriah Waterland 	if (access(ilockfile, F_OK) == 0) {
19805c51f124SMoriah Waterland 		(void) remove(ilockfile);
19815c51f124SMoriah Waterland 	}
19825c51f124SMoriah Waterland 
19835c51f124SMoriah Waterland 	if (open(ilockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644) < 0) {
19845c51f124SMoriah Waterland 		progerr(ERR_LOCKFILE, ilockfile);
19855c51f124SMoriah Waterland 		quit(99);
19865c51f124SMoriah Waterland 		/*NOTREACHED*/
19875c51f124SMoriah Waterland 	}
19885c51f124SMoriah Waterland 
19895c51f124SMoriah Waterland 	(void) time(&clock);
1990a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
1991a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	/*
1992a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	 * We do not want the time in locale in the pkginfo.
1993a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	 * save the LC_TIME and set it to C. Reset it with saved one
1994a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	 * after cftime().
1995a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	 */
1996a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	temp = setlocale(LC_TIME, NULL);
1997a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	(void) setlocale(LC_TIME, "C");
1998a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
19995c51f124SMoriah Waterland 	/* LINTED warning: do not use cftime(); ... */
20005c51f124SMoriah Waterland 	(void) cftime(cbuf, "%b %d \045Y \045H:\045M", &clock);
20015c51f124SMoriah Waterland 	putparam("INSTDATE", qstrdup(cbuf));
2002a1aee5eeS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	(void) setlocale(LC_TIME, temp);
20035c51f124SMoriah Waterland 
20045c51f124SMoriah Waterland 	/*
20055c51f124SMoriah Waterland 	 * Store information about package being installed;
20065c51f124SMoriah Waterland 	 * modify installation parameters as neccessary and
20075c51f124SMoriah Waterland 	 * copy contents of 'install' directory into $pkgloc
20085c51f124SMoriah Waterland 	 */
20095c51f124SMoriah Waterland 	merginfo(mergd_pclass, saveSpoolInstall);
20105c51f124SMoriah Waterland 
20115c51f124SMoriah Waterland 	/* If this was just a dryrun, then quit() will write out that file. */
20125c51f124SMoriah Waterland 	if (in_dryrun_mode()) {
20135c51f124SMoriah Waterland 		quit(0);
20145c51f124SMoriah Waterland 		/*NOTREACHED*/
20155c51f124SMoriah Waterland 	}
20165c51f124SMoriah Waterland 
20175c51f124SMoriah Waterland 	/*
20185c51f124SMoriah Waterland 	 * Execute preinstall script, if one was provided with the
20195c51f124SMoriah Waterland 	 * package. We check the package to avoid running an old
20205c51f124SMoriah Waterland 	 * preinstall script if one was provided with a prior instance.
20215c51f124SMoriah Waterland 	 * Don't execute preinstall script if we are only updating the DB.
20225c51f124SMoriah Waterland 	 */
20235c51f124SMoriah Waterland 
20245c51f124SMoriah Waterland 	/* update the lock - at the preinstall altscript */
20255c51f124SMoriah Waterland 	lockupd("preinstall");
20265c51f124SMoriah Waterland 
20275c51f124SMoriah Waterland 	/* preinstall script in the media (package source) */
20285c51f124SMoriah Waterland 	(void) snprintf(altscript, sizeof (altscript), "%s/install/preinstall",
20295c51f124SMoriah Waterland 			instdir);
20305c51f124SMoriah Waterland 
20315c51f124SMoriah Waterland 	/* preinstall script in the pkgbin instead of media */
20325c51f124SMoriah Waterland 	(void) snprintf(script, sizeof (script), "%s/preinstall", pkgbin);
20335c51f124SMoriah Waterland 
20345c51f124SMoriah Waterland 	if (access(altscript, F_OK) != 0) {
20355c51f124SMoriah Waterland 		/* no script present */
20365c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POCALT_NONE, pkginst, altscript,
20375c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
20385c51f124SMoriah Waterland 	} else if (access(script, F_OK) != 0) {
20395c51f124SMoriah Waterland 		/* no script present */
20405c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POC_NONE, pkginst, script,
20415c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
20425c51f124SMoriah Waterland 	} else if (is_depend_pkginfo_DB()) {
20435c51f124SMoriah Waterland 		/* updating db only: skip preinstall script */
20445c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POC_DBUPD, pkginst, script,
20455c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
20465c51f124SMoriah Waterland 	} else {
20475c51f124SMoriah Waterland 		/* script present and ok to run: run the script */
20485c51f124SMoriah Waterland 		assert(preinstallCheck == B_FALSE);
20495c51f124SMoriah Waterland 
20505c51f124SMoriah Waterland 		set_ulimit("preinstall", ERR_PREINSTALL);
20515c51f124SMoriah Waterland 		if (zoneName == (char *)NULL) {
20525c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXEPOC_GZ);
20535c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXEPOC_GZ, pkginst, script);
20545c51f124SMoriah Waterland 		} else {
20555c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXEPOC_LZ, zoneName);
20565c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXEPOC_LZ, pkginst, script,
20575c51f124SMoriah Waterland 				zoneName);
20585c51f124SMoriah Waterland 		}
20595c51f124SMoriah Waterland 		putparam("PKG_PROC_script", "preinstall");
20605c51f124SMoriah Waterland 		if (pkgverbose) {
20615c51f124SMoriah Waterland 			ckreturn(pkgexecl(script_in, PROC_STDOUT,
20625c51f124SMoriah Waterland 				PROC_USER, PROC_GRP, SHELL, "-x",
20635c51f124SMoriah Waterland 				script, NULL), ERR_PREINSTALL);
20645c51f124SMoriah Waterland 		} else {
20655c51f124SMoriah Waterland 			ckreturn(pkgexecl(script_in, PROC_STDOUT,
20665c51f124SMoriah Waterland 				PROC_USER, PROC_GRP, SHELL, script,
20675c51f124SMoriah Waterland 				NULL), ERR_PREINSTALL);
20685c51f124SMoriah Waterland 		}
20695c51f124SMoriah Waterland 
20705c51f124SMoriah Waterland 		clr_ulimit();
20715c51f124SMoriah Waterland 		(void) remove(script);	/* no longer needed. */
20725c51f124SMoriah Waterland 	}
20735c51f124SMoriah Waterland 
20745c51f124SMoriah Waterland 	/*
20755c51f124SMoriah Waterland 	 * Check delivered package for a postinstall script while
20765c51f124SMoriah Waterland 	 * we're still on volume 1.
20775c51f124SMoriah Waterland 	 */
20785c51f124SMoriah Waterland 
20795c51f124SMoriah Waterland 	(void) snprintf(script, sizeof (script),
20805c51f124SMoriah Waterland 			"%s/install/postinstall", instdir);
20815c51f124SMoriah Waterland 	if (access(script, F_OK) == 0) {
20825c51f124SMoriah Waterland 		(void) snprintf(script, sizeof (script),
20835c51f124SMoriah Waterland 					"%s/postinstall", pkgbin);
20845c51f124SMoriah Waterland 	} else {
20855c51f124SMoriah Waterland 		script[0] = '\0';
20865c51f124SMoriah Waterland 	}
20875c51f124SMoriah Waterland 
20885c51f124SMoriah Waterland 	/* update the lock - at the install phase */
20895c51f124SMoriah Waterland 
20905c51f124SMoriah Waterland 	lockupd("install");
20915c51f124SMoriah Waterland 
20925c51f124SMoriah Waterland 	/*
20935c51f124SMoriah Waterland 	 * install package one part (volume) at a time
20945c51f124SMoriah Waterland 	 */
20955c51f124SMoriah Waterland 
20965c51f124SMoriah Waterland 	part = 1;
20975c51f124SMoriah Waterland 	while (part <= nparts) {
20985c51f124SMoriah Waterland 		if ((part > 1) && pkgdev.cdevice) {
20995c51f124SMoriah Waterland 			unpack();
21005c51f124SMoriah Waterland 		}
21015c51f124SMoriah Waterland 
21025c51f124SMoriah Waterland 		instvol(extlist, srcinst, part, nparts,
21036e1ae2a3SGary Pennington 			pkgserver, &cfTmpVfp, &updated, zoneName);
21045c51f124SMoriah Waterland 
21055c51f124SMoriah Waterland 		if (part++ >= nparts) {
21065c51f124SMoriah Waterland 			break;
21075c51f124SMoriah Waterland 		}
21085c51f124SMoriah Waterland 	}
21095c51f124SMoriah Waterland 
21105c51f124SMoriah Waterland 	z_destroyMountTable();
21115c51f124SMoriah Waterland 
21125c51f124SMoriah Waterland 	/*
21135c51f124SMoriah Waterland 	 * Now that all install class action scripts have been used, we
21145c51f124SMoriah Waterland 	 * delete them from the package directory.
21155c51f124SMoriah Waterland 	 */
21165c51f124SMoriah Waterland 	rm_icas(pkgbin);
21175c51f124SMoriah Waterland 
2118*4656d474SGarrett D'Amore 	if (globalZoneOnly) {
21195c51f124SMoriah Waterland 		boolean_t   b;
21205c51f124SMoriah Waterland 		b = pkgAddPackageToGzonlyList(pkginst, get_inst_root());
21215c51f124SMoriah Waterland 		if (b == B_FALSE) {
21225c51f124SMoriah Waterland 			progerr(ERR_PKGINSTALL_GZONLY_ADD, pkginst);
21235c51f124SMoriah Waterland 			ckreturn(1, NULL);
21245c51f124SMoriah Waterland 		}
21255c51f124SMoriah Waterland 	}
21265c51f124SMoriah Waterland 
21275c51f124SMoriah Waterland 	/*
21285c51f124SMoriah Waterland 	 * Execute postinstall script, if any
21295c51f124SMoriah Waterland 	 * Don't execute postinstall script if we are only updating the DB.
21305c51f124SMoriah Waterland 	 */
21315c51f124SMoriah Waterland 
21325c51f124SMoriah Waterland 	echoDebug(DBG_PKGINSTALL_INSDONE, is_depend_pkginfo_DB(),
21335c51f124SMoriah Waterland 		is_depend_pkginfo_DB(), saveSpoolInstall,
21345c51f124SMoriah Waterland 		updated ? updated : "",
21355c51f124SMoriah Waterland 		script ? script : "",
21365c51f124SMoriah Waterland 		script ? access(script, F_OK) : -1);
21375c51f124SMoriah Waterland 
21385c51f124SMoriah Waterland 	/* update the lock - at the postinstall script */
21395c51f124SMoriah Waterland 	lockupd("postinstall");
21405c51f124SMoriah Waterland 
21415c51f124SMoriah Waterland 	if ((script == (char *)NULL) || (*script == '\0')) {
21425c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POIS_NOPATH, pkginst,
21435c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
21445c51f124SMoriah Waterland 	} else if (access(script, F_OK) != 0) {
21455c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POIS_NONE, pkginst, script,
21465c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
21475c51f124SMoriah Waterland 	} else if (is_depend_pkginfo_DB()) {
21485c51f124SMoriah Waterland 		echoDebug(DBG_PKGINSTALL_POIS_DBUPD, pkginst, script,
21495c51f124SMoriah Waterland 			zoneName ? zoneName : "global");
21506e1ae2a3SGary Pennington 	} else if ((saveSpoolInstall != 0) && (updated == (char *)NULL)) {
21515c51f124SMoriah Waterland 		/*
21525c51f124SMoriah Waterland 		 * fresh installing into non-global zone, no object was
21536e1ae2a3SGary Pennington 		 * updated (installed/verified in area), so do not run
21546e1ae2a3SGary Pennington 		 * the postinstall script.
21555c51f124SMoriah Waterland 		 */
21566e1ae2a3SGary Pennington 		echoDebug(DBG_PKGINSTALL_POIS_NOUPDATING,
21575c51f124SMoriah Waterland 			zoneName ? zoneName : "global", pkginst, script);
21585c51f124SMoriah Waterland 	} else {
21595c51f124SMoriah Waterland 		/* script present and ok to run: run the script */
21605c51f124SMoriah Waterland 		set_ulimit("postinstall", ERR_POSTINSTALL);
21615c51f124SMoriah Waterland 		if (zoneName == (char *)NULL) {
21625c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXEPIC_GZ);
21635c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXEPIC_GZ, pkginst, script);
21645c51f124SMoriah Waterland 		} else {
21655c51f124SMoriah Waterland 			echo(MSG_PKGINSTALL_EXEPIC_LZ, zoneName);
21665c51f124SMoriah Waterland 			echoDebug(DBG_PKGINSTALL_EXEPIC_LZ, pkginst, script,
21675c51f124SMoriah Waterland 				zoneName);
21685c51f124SMoriah Waterland 		}
21695c51f124SMoriah Waterland 		putparam("PKG_PROC_SCRIPT", "postinstall");
21705c51f124SMoriah Waterland 		putparam("TMPDIR", tmpdir);
21715c51f124SMoriah Waterland 		if (pkgverbose) {
21725c51f124SMoriah Waterland 			ckreturn(pkgexecl(script_in, PROC_STDOUT,
21735c51f124SMoriah Waterland 				PROC_USER, PROC_GRP, SHELL, "-x",
21745c51f124SMoriah Waterland 				script, NULL), ERR_POSTINSTALL);
21755c51f124SMoriah Waterland 		} else {
21765c51f124SMoriah Waterland 			ckreturn(pkgexecl(script_in, PROC_STDOUT,
21775c51f124SMoriah Waterland 				PROC_USER, PROC_GRP, SHELL, script,
21785c51f124SMoriah Waterland 				NULL), ERR_POSTINSTALL);
21795c51f124SMoriah Waterland 		}
21805c51f124SMoriah Waterland 
21815c51f124SMoriah Waterland 		clr_ulimit();
21825c51f124SMoriah Waterland 		(void) remove(script);	/* no longer needed */
21835c51f124SMoriah Waterland 	}
21845c51f124SMoriah Waterland 
21855c51f124SMoriah Waterland 	if (!warnflag && !failflag) {
21865c51f124SMoriah Waterland 		(void) remove(rlockfile);
21875c51f124SMoriah Waterland 		(void) remove(ilockfile);
21885c51f124SMoriah Waterland 		(void) remove(savlog);
21895c51f124SMoriah Waterland 	}
21905c51f124SMoriah Waterland 
21915c51f124SMoriah Waterland 	/* release the generic package lock */
21925c51f124SMoriah Waterland 
21935c51f124SMoriah Waterland 	(void) unlockinst();
21945c51f124SMoriah Waterland 
219562224350SCasper H.S. Dik 	pkgcloseserver(pkgserver);
219662224350SCasper H.S. Dik 
21975c51f124SMoriah Waterland 	quit(0);
21985c51f124SMoriah Waterland 	/* LINTED: no return */
21995c51f124SMoriah Waterland }
22005c51f124SMoriah Waterland 
22015c51f124SMoriah Waterland /*
22025c51f124SMoriah Waterland  * This function merges the environment data in the response file with the
22035c51f124SMoriah Waterland  * current environment.
22045c51f124SMoriah Waterland  */
22055c51f124SMoriah Waterland static int
22065c51f124SMoriah Waterland merg_respfile()
22075c51f124SMoriah Waterland {
22085c51f124SMoriah Waterland 	int retcode = 0;
22095c51f124SMoriah Waterland 	char *resppath = get_respfile();
22105c51f124SMoriah Waterland 	char *locbasedir;
22115c51f124SMoriah Waterland 	char param[MAX_PKG_PARAM_LENGTH], *value;
22125c51f124SMoriah Waterland 	FILE *fp;
22135c51f124SMoriah Waterland 
22145c51f124SMoriah Waterland 	if ((fp = fopen(resppath, "r")) == NULL) {
22155c51f124SMoriah Waterland 		progerr(ERR_RESPONSE, resppath);
22165c51f124SMoriah Waterland 		return (99);
22175c51f124SMoriah Waterland 	}
22185c51f124SMoriah Waterland 
22195c51f124SMoriah Waterland 	param[0] = '\0';
22205c51f124SMoriah Waterland 
22215c51f124SMoriah Waterland 	while (value = fpkgparam(fp, param)) {
22225c51f124SMoriah Waterland 		if (!isupper(param[0])) {
22235c51f124SMoriah Waterland 			param[0] = '\0';
22245c51f124SMoriah Waterland 			continue;
22255c51f124SMoriah Waterland 		}
22265c51f124SMoriah Waterland 
22275c51f124SMoriah Waterland 		if (rdonly(param)) {
22285c51f124SMoriah Waterland 			progerr(ERR_RDONLY, param);
22295c51f124SMoriah Waterland 			param[0] = '\0';
22305c51f124SMoriah Waterland 			continue;
22315c51f124SMoriah Waterland 		}
22325c51f124SMoriah Waterland 
22335c51f124SMoriah Waterland 		/*
22345c51f124SMoriah Waterland 		 * If this is an update, and the response file
22355c51f124SMoriah Waterland 		 * specifies the BASEDIR, make sure it matches the
22365c51f124SMoriah Waterland 		 * existing installation base. If it doesn't, we have
22375c51f124SMoriah Waterland 		 * to quit.
22385c51f124SMoriah Waterland 		 */
22395c51f124SMoriah Waterland 		if (update && strcmp("BASEDIR", param) == 0) {
22405c51f124SMoriah Waterland 			locbasedir = getenv("BASEDIR");
22415c51f124SMoriah Waterland 			if (locbasedir && strcmp(value, locbasedir) != 0) {
22425c51f124SMoriah Waterland 				char *dotptr;
22435c51f124SMoriah Waterland 				/* Get srcinst down to a name. */
22445c51f124SMoriah Waterland 				if (dotptr = strchr(srcinst, '.'))
22455c51f124SMoriah Waterland 					*dotptr = '\000';
22465c51f124SMoriah Waterland 				progerr(ERR_NEWBD, srcinst,
22475c51f124SMoriah Waterland 					locbasedir, value);
22485c51f124SMoriah Waterland 				retcode = 99;
22495c51f124SMoriah Waterland 			}
22505c51f124SMoriah Waterland 		}
22515c51f124SMoriah Waterland 
22525c51f124SMoriah Waterland 		putparam(param, value);
22535c51f124SMoriah Waterland 		param[0] = '\0';
22545c51f124SMoriah Waterland 	}
22555c51f124SMoriah Waterland 	(void) fclose(fp);
22565c51f124SMoriah Waterland 
22575c51f124SMoriah Waterland 	return (retcode);
22585c51f124SMoriah Waterland }
22595c51f124SMoriah Waterland 
22605c51f124SMoriah Waterland /*
22615c51f124SMoriah Waterland  * This scans the installed pkginfo file for the current BASEDIR. If this
22625c51f124SMoriah Waterland  * BASEDIR is different from the current BASEDIR, there will definitely be
22635c51f124SMoriah Waterland  * problems.
22645c51f124SMoriah Waterland  */
22655c51f124SMoriah Waterland static int
22665c51f124SMoriah Waterland ck_instbase(void)
22675c51f124SMoriah Waterland {
22685c51f124SMoriah Waterland 	int retcode = 0;
22695c51f124SMoriah Waterland 	char param[MAX_PKG_PARAM_LENGTH], *value;
22705c51f124SMoriah Waterland 	char pkginfo_path[PATH_MAX];
22715c51f124SMoriah Waterland 	FILE *fp;
22725c51f124SMoriah Waterland 
22735c51f124SMoriah Waterland 	/* Open the old pkginfo file. */
22745c51f124SMoriah Waterland 	(void) snprintf(pkginfo_path, sizeof (pkginfo_path),
22755c51f124SMoriah Waterland 			"%s/%s", pkgloc, PKGINFO);
22765c51f124SMoriah Waterland 	if ((fp = fopen(pkginfo_path, "r")) == NULL) {
22775c51f124SMoriah Waterland 		progerr(ERR_PKGINFO, pkginfo_path);
22785c51f124SMoriah Waterland 		return (99);
22795c51f124SMoriah Waterland 	}
22805c51f124SMoriah Waterland 
22815c51f124SMoriah Waterland 	param[0] = '\000';
22825c51f124SMoriah Waterland 
22835c51f124SMoriah Waterland 	while (value = fpkgparam(fp, param)) {
22845c51f124SMoriah Waterland 		if (strcmp("BASEDIR", param) == 0) {
22855c51f124SMoriah Waterland 			if (adm.basedir && *(adm.basedir) &&
22865c51f124SMoriah Waterland 				strchr("/$", *(adm.basedir))) {
22875c51f124SMoriah Waterland 				char *dotptr;
22885c51f124SMoriah Waterland 
22895c51f124SMoriah Waterland 				/*
22905c51f124SMoriah Waterland 				 * Get srcinst down to a name.
22915c51f124SMoriah Waterland 				 */
22925c51f124SMoriah Waterland 				if (dotptr = strchr(srcinst, '.'))
22935c51f124SMoriah Waterland 					*dotptr = '\000';
22945c51f124SMoriah Waterland 				if (strcmp(value,
22955c51f124SMoriah Waterland 					adm.basedir) != 0) {
22965c51f124SMoriah Waterland 					progerr(ERR_ADMBD, srcinst,
22975c51f124SMoriah Waterland 						value, adm.basedir);
22985c51f124SMoriah Waterland 					retcode = 4;
22995c51f124SMoriah Waterland 					break;
23005c51f124SMoriah Waterland 				}
23015c51f124SMoriah Waterland 			} else if (ADM(basedir, "ask"))
23025c51f124SMoriah Waterland 				/*
23035c51f124SMoriah Waterland 				 * If it's going to ask later, let it know
23045c51f124SMoriah Waterland 				 * that it *must* agree with the BASEDIR we
23055c51f124SMoriah Waterland 				 * just picked up.
23065c51f124SMoriah Waterland 				 */
23075c51f124SMoriah Waterland 				adm.basedir = "update";
23085c51f124SMoriah Waterland 
23095c51f124SMoriah Waterland 			putparam(param, value);
23105c51f124SMoriah Waterland 			break;
23115c51f124SMoriah Waterland 		}
23125c51f124SMoriah Waterland 
23135c51f124SMoriah Waterland 		param[0] = '\0';
23145c51f124SMoriah Waterland 	}
23155c51f124SMoriah Waterland 	(void) fclose(fp);
23165c51f124SMoriah Waterland 
23175c51f124SMoriah Waterland 	return (retcode);
23185c51f124SMoriah Waterland }
23195c51f124SMoriah Waterland 
23205c51f124SMoriah Waterland /*
23215c51f124SMoriah Waterland  * Since this is an overwrite of a different version of the package, none of
23225c51f124SMoriah Waterland  * the old files should remain, so we rename them.
23235c51f124SMoriah Waterland  */
23245c51f124SMoriah Waterland static int
23255c51f124SMoriah Waterland mv_pkgdirs(void)
23265c51f124SMoriah Waterland {
23275c51f124SMoriah Waterland 	/*
23285c51f124SMoriah Waterland 	 * If we're not in dryrun mode and we can find an old set of package
23295c51f124SMoriah Waterland 	 * files over which the new ones will be written, do the rename.
23305c51f124SMoriah Waterland 	 */
23315c51f124SMoriah Waterland 	if (!in_dryrun_mode() && pkgloc[0] && !access(pkgloc, F_OK)) {
23325c51f124SMoriah Waterland 		(void) snprintf(pkgloc_sav, sizeof (pkgloc_sav),
23335c51f124SMoriah Waterland 			"%s/.save.%s", get_PKGLOC(),
23345c51f124SMoriah Waterland 			pkginst);
23355c51f124SMoriah Waterland 		if (pkgloc_sav[0] && !access(pkgloc_sav, F_OK)) {
23365c51f124SMoriah Waterland 			(void) rrmdir(pkgloc_sav);
23375c51f124SMoriah Waterland 		}
23385c51f124SMoriah Waterland 
23395c51f124SMoriah Waterland 		if (rename(pkgloc, pkgloc_sav) == -1) {
23405c51f124SMoriah Waterland 			progerr(ERR_PKGBINREN, pkgloc, pkgloc_sav);
23415c51f124SMoriah Waterland 			return (99);
23425c51f124SMoriah Waterland 		}
23435c51f124SMoriah Waterland 	}
23445c51f124SMoriah Waterland 
23455c51f124SMoriah Waterland 	return (0);
23465c51f124SMoriah Waterland }
23475c51f124SMoriah Waterland 
23485c51f124SMoriah Waterland /*
23495c51f124SMoriah Waterland  * Name:	merg_pkginfos
23505c51f124SMoriah Waterland  * Description:	This function scans the installed pkginfo and merges that
23515c51f124SMoriah Waterland  *		environment with the installing environment according to
23525c51f124SMoriah Waterland  *		the following rules:
23535c51f124SMoriah Waterland  *
23545c51f124SMoriah Waterland  *		1. CLASSES is a union of the installed and installing CLASSES
23555c51f124SMoriah Waterland  *			lists.
23565c51f124SMoriah Waterland  *		2. The installed BASEDIR takes precedence. If it doesn't agree
23575c51f124SMoriah Waterland  *		   with an administratively imposed BASEDIR, an ERROR is issued.
23585c51f124SMoriah Waterland  *		3. All other installing parameters are preserved.
23595c51f124SMoriah Waterland  *		4. All installed parameters are added if they do not overwrite
23605c51f124SMoriah Waterland  *		   an existing installing parameter.
23615c51f124SMoriah Waterland  *
23625c51f124SMoriah Waterland  *		The current environment contains the pkginfo settings for the
23635c51f124SMoriah Waterland  *		new package to be installed or to be updated.
23645c51f124SMoriah Waterland  *
23655c51f124SMoriah Waterland  * Arguments:	pclass - returned list of current classes involved in install
23665c51f124SMoriah Waterland  *		mpclass - pointer to returned list of current install classes
23675c51f124SMoriah Waterland  * Returns:	int
23685c51f124SMoriah Waterland  *		== 0 - all OK
23695c51f124SMoriah Waterland  *		!= 0 - an error code if a fatal error occurred
23705c51f124SMoriah Waterland  */
23715c51f124SMoriah Waterland 
23725c51f124SMoriah Waterland static int
23735c51f124SMoriah Waterland merg_pkginfos(struct cl_attr **pclass, struct cl_attr ***mpclass)
23745c51f124SMoriah Waterland {
23755c51f124SMoriah Waterland 	FILE	*fp;
23765c51f124SMoriah Waterland 	char	SUNW_PKG_ALLZONES[MAX_PKG_PARAM_LENGTH] = {'\0'};
23775c51f124SMoriah Waterland 	char	SUNW_PKG_HOLLOW[MAX_PKG_PARAM_LENGTH] = {'\0'};
23785c51f124SMoriah Waterland 	char	SUNW_PKG_THISZONE[MAX_PKG_PARAM_LENGTH] = {'\0'};
23795c51f124SMoriah Waterland 	char	*newValue;
23805c51f124SMoriah Waterland 	char	*oldValue;
23815c51f124SMoriah Waterland 	char	*pkgName;
23825c51f124SMoriah Waterland 	char	*pkgVersion;
23835c51f124SMoriah Waterland 	char	param[MAX_PKG_PARAM_LENGTH];
23845c51f124SMoriah Waterland 	char	pkginfo_path[PATH_MAX];
23855c51f124SMoriah Waterland 	int	retcode = 0;
23865c51f124SMoriah Waterland 
23875c51f124SMoriah Waterland 	/* obtain the name of the package (for error messages) */
23885c51f124SMoriah Waterland 
23895c51f124SMoriah Waterland 	pkgName = getenv("PKG");
23905c51f124SMoriah Waterland 	if (pkgName == NULL) {
23915c51f124SMoriah Waterland 		pkgName = "*current*";	/* default name */
23925c51f124SMoriah Waterland 	}
23935c51f124SMoriah Waterland 
23945c51f124SMoriah Waterland 	/* obtain the version of the package (for error messages) */
23955c51f124SMoriah Waterland 
23965c51f124SMoriah Waterland 	pkgVersion = getenv("VERSION");
23975c51f124SMoriah Waterland 	if (pkgVersion == NULL) {
23985c51f124SMoriah Waterland 		pkgVersion = "*current*";	/* default version */
23995c51f124SMoriah Waterland 	}
24005c51f124SMoriah Waterland 
24015c51f124SMoriah Waterland 	/* open installed package pkginfo file */
24025c51f124SMoriah Waterland 
24035c51f124SMoriah Waterland 	(void) snprintf(pkginfo_path, sizeof (pkginfo_path),
24045c51f124SMoriah Waterland 			"%s/%s", pkgloc, PKGINFO);
24055c51f124SMoriah Waterland 	if ((fp = fopen(pkginfo_path, "r")) == NULL) {
24065c51f124SMoriah Waterland 		progerr(ERR_PKGINFO, pkginfo_path);
24075c51f124SMoriah Waterland 		return (99);
24085c51f124SMoriah Waterland 	}
24095c51f124SMoriah Waterland 
24105c51f124SMoriah Waterland 	/* entry debugging info */
24115c51f124SMoriah Waterland 
24125c51f124SMoriah Waterland 	echoDebug(DBG_MERGINFOS_ENTRY, pkginfo_path);
24135c51f124SMoriah Waterland 
24145c51f124SMoriah Waterland 	/*
24155c51f124SMoriah Waterland 	 * cycle through the currently installed package's pkginfo parameters
24165c51f124SMoriah Waterland 	 * and let the currently installed package's settings survive if the
24175c51f124SMoriah Waterland 	 * update to the package does not provide an overriding value
24185c51f124SMoriah Waterland 	 */
24195c51f124SMoriah Waterland 
24205c51f124SMoriah Waterland 	for (param[0] = '\0'; (oldValue = fpkgparam(fp, param)) != NULL;
24215c51f124SMoriah Waterland 		param[0] = '\0') {
24225c51f124SMoriah Waterland 
24235c51f124SMoriah Waterland 		boolean_t	setZoneAttribute = B_FALSE;
24245c51f124SMoriah Waterland 
24255c51f124SMoriah Waterland 		/* debug info - attribute currently set to value */
24265c51f124SMoriah Waterland 
24275c51f124SMoriah Waterland 		echoDebug(DBG_MERGINFOS_SET_TO, param, oldValue);
24285c51f124SMoriah Waterland 
24295c51f124SMoriah Waterland 		/*
24305c51f124SMoriah Waterland 		 * if zone package attribute is present in the currently
24315c51f124SMoriah Waterland 		 * installed package, then remember the value for the
24325c51f124SMoriah Waterland 		 * specific zone package attribute, and set the flag that
24335c51f124SMoriah Waterland 		 * indicates a zone package attribute is being processed.
24345c51f124SMoriah Waterland 		 */
24355c51f124SMoriah Waterland 
24365c51f124SMoriah Waterland 		if (strcmp(param, PKG_THISZONE_VARIABLE) == 0) {
24375c51f124SMoriah Waterland 			/* SUNW_PKG_THISZONE currently set */
24385c51f124SMoriah Waterland 			setZoneAttribute = B_TRUE;
24395c51f124SMoriah Waterland 			(void) strlcpy(SUNW_PKG_THISZONE, oldValue,
24405c51f124SMoriah Waterland 					sizeof (SUNW_PKG_THISZONE));
24415c51f124SMoriah Waterland 		} else if (strcmp(param, PKG_ALLZONES_VARIABLE) == 0) {
24425c51f124SMoriah Waterland 			/* SUNW_PKG_ALLZONES currently set */
24435c51f124SMoriah Waterland 			setZoneAttribute = B_TRUE;
24445c51f124SMoriah Waterland 			(void) strlcpy(SUNW_PKG_ALLZONES, oldValue,
24455c51f124SMoriah Waterland 					sizeof (SUNW_PKG_ALLZONES));
24465c51f124SMoriah Waterland 		} else if (strcmp(param, PKG_HOLLOW_VARIABLE) == 0) {
24475c51f124SMoriah Waterland 			/* SUNW_PKG_THISZONE currently set */
24485c51f124SMoriah Waterland 			setZoneAttribute = B_TRUE;
24495c51f124SMoriah Waterland 			(void) strlcpy(SUNW_PKG_HOLLOW, oldValue,
24505c51f124SMoriah Waterland 					sizeof (SUNW_PKG_HOLLOW));
24515c51f124SMoriah Waterland 		}
24525c51f124SMoriah Waterland 
24535c51f124SMoriah Waterland 		/* handle CLASSES currently being set */
24545c51f124SMoriah Waterland 
24555c51f124SMoriah Waterland 		if (strcmp(param, "CLASSES") == 0) {
24565c51f124SMoriah Waterland 			echoDebug(DBG_MERGINFOS_SET_CLASSES, oldValue);
24575c51f124SMoriah Waterland 			/* create a list of the current classes */
24585c51f124SMoriah Waterland 			(void) setlist(&pclass, qstrdup(oldValue));
24595c51f124SMoriah Waterland 			/* set pointer to list of current classes */
24605c51f124SMoriah Waterland 			*mpclass = pclass;
24615c51f124SMoriah Waterland 			continue;
24625c51f124SMoriah Waterland 		}
24635c51f124SMoriah Waterland 
24645c51f124SMoriah Waterland 		/* handle BASEDIR currently being set */
24655c51f124SMoriah Waterland 
24665c51f124SMoriah Waterland 		if (strcmp("BASEDIR", param) == 0) {
24675c51f124SMoriah Waterland 			if (adm.basedir && *(adm.basedir) &&
24685c51f124SMoriah Waterland 				strchr("/$", *(adm.basedir))) {
24695c51f124SMoriah Waterland 				char *dotptr;
24705c51f124SMoriah Waterland 
24715c51f124SMoriah Waterland 				/* Get srcinst down to a* name */
24725c51f124SMoriah Waterland 
24735c51f124SMoriah Waterland 				if (dotptr = strchr(srcinst, '.')) {
24745c51f124SMoriah Waterland 					*dotptr = '\000';
24755c51f124SMoriah Waterland 				}
24765c51f124SMoriah Waterland 				if (strcmp(oldValue, adm.basedir) != 0) {
24775c51f124SMoriah Waterland 					progerr(ERR_ADMBD, srcinst,
24785c51f124SMoriah Waterland 						oldValue, adm.basedir);
24795c51f124SMoriah Waterland 					/* administration */
24805c51f124SMoriah Waterland 					retcode = 4;
24815c51f124SMoriah Waterland 					break;
24825c51f124SMoriah Waterland 				}
24835c51f124SMoriah Waterland 			} else if (ADM(basedir, "ask")) {
24845c51f124SMoriah Waterland 				/*
24855c51f124SMoriah Waterland 				 * If it's going to ask
24865c51f124SMoriah Waterland 				 * later, let it know that it
24875c51f124SMoriah Waterland 				 * *must* agree with the
24885c51f124SMoriah Waterland 				 * BASEDIR we just picked up.
24895c51f124SMoriah Waterland 				 */
24905c51f124SMoriah Waterland 				adm.basedir = "update";
24915c51f124SMoriah Waterland 				echoDebug(DBG_MERGINFOS_ASK_BASEDIR);
24925c51f124SMoriah Waterland 			}
24935c51f124SMoriah Waterland 
24945c51f124SMoriah Waterland 			echoDebug(DBG_MERGINFOS_SET_BASEDIR, oldValue);
24955c51f124SMoriah Waterland 			putparam(param, oldValue);
24965c51f124SMoriah Waterland 			continue;
24975c51f124SMoriah Waterland 		}
24985c51f124SMoriah Waterland 
24995c51f124SMoriah Waterland 		/*
25005c51f124SMoriah Waterland 		 * determine if there is a new value for this attribute.
25015c51f124SMoriah Waterland 		 */
25025c51f124SMoriah Waterland 
25035c51f124SMoriah Waterland 		newValue = getenv(param);
25045c51f124SMoriah Waterland 
25055c51f124SMoriah Waterland 		/*
2506*4656d474SGarrett D'Amore 		 * If there is no new value, and a zone attribute
25075c51f124SMoriah Waterland 		 * is being changed, it is the same as setting the zone package
25085c51f124SMoriah Waterland 		 * attribute to 'false' - make sure current setting is 'false'.
25095c51f124SMoriah Waterland 		 */
25105c51f124SMoriah Waterland 
2511*4656d474SGarrett D'Amore 		if ((newValue == NULL) &&
25125c51f124SMoriah Waterland 		    (setZoneAttribute == B_TRUE) &&
25135c51f124SMoriah Waterland 		    (strcasecmp(oldValue, "false") != 0)) {
25145c51f124SMoriah Waterland 
25155c51f124SMoriah Waterland 			/* unset existing non-"false" zone pkg attr */
25165c51f124SMoriah Waterland 			progerr(ERR_MERGINFOS_UNSET_ZONEATTR,
25175c51f124SMoriah Waterland 				pkgName, pkgVersion, param, oldValue);
25185c51f124SMoriah Waterland 			retcode = 1;
25195c51f124SMoriah Waterland 			break;
25205c51f124SMoriah Waterland 		}
25215c51f124SMoriah Waterland 
25225c51f124SMoriah Waterland 		/* retain old value if no new value specified */
25235c51f124SMoriah Waterland 
25245c51f124SMoriah Waterland 		if (newValue == NULL) {
25255c51f124SMoriah Waterland 			/* no new value - retain the old value */
25265c51f124SMoriah Waterland 			echoDebug(DBG_MERGINFOS_RETAIN_OLD, param, oldValue);
25275c51f124SMoriah Waterland 			putparam(param, oldValue);
25285c51f124SMoriah Waterland 			continue;
25295c51f124SMoriah Waterland 		}
25305c51f124SMoriah Waterland 
25315c51f124SMoriah Waterland 		/* note if the old and new values are the same */
25325c51f124SMoriah Waterland 
25335c51f124SMoriah Waterland 		if (strcmp(newValue, oldValue) == 0) {
25345c51f124SMoriah Waterland 			/* set existing package parameter to same value */
25355c51f124SMoriah Waterland 			echoDebug(DBG_MERGINFOS_SET_DUPLICATE, param, oldValue);
25365c51f124SMoriah Waterland 			continue;
25375c51f124SMoriah Waterland 		}
25385c51f124SMoriah Waterland 
25395c51f124SMoriah Waterland 		/*
2540*4656d474SGarrett D'Amore 		 * Check if old and new values differ.
25415c51f124SMoriah Waterland 		 * Error if zone parameter
25425c51f124SMoriah Waterland 		 */
25435c51f124SMoriah Waterland 
2544*4656d474SGarrett D'Amore 		if (setZoneAttribute == B_TRUE) {
25455c51f124SMoriah Waterland 			/* illegal change to zone attribute */
25465c51f124SMoriah Waterland 
25475c51f124SMoriah Waterland 			progerr(ERR_MERGINFOS_CHANGE_ZONEATTR, pkgName,
25485c51f124SMoriah Waterland 				pkgVersion, param, oldValue, newValue);
25495c51f124SMoriah Waterland 
25505c51f124SMoriah Waterland 			/* set return code to "fatal error" */
25515c51f124SMoriah Waterland 			retcode = 1;
25525c51f124SMoriah Waterland 			break;
25535c51f124SMoriah Waterland 		}
25545c51f124SMoriah Waterland 
25555c51f124SMoriah Waterland 		/* note valid change to existing package parameter */
25565c51f124SMoriah Waterland 
25575c51f124SMoriah Waterland 		echoDebug(DBG_MERGINFOS_SET_CHANGE, param,
25585c51f124SMoriah Waterland 				oldValue, newValue);
25595c51f124SMoriah Waterland 	}
25605c51f124SMoriah Waterland 
25615c51f124SMoriah Waterland 	/* close handle on currently installed package's pkginfo file */
25625c51f124SMoriah Waterland 
25635c51f124SMoriah Waterland 	(void) fclose(fp);
25645c51f124SMoriah Waterland 
25655c51f124SMoriah Waterland 	/* return error if not successful up to this point */
25665c51f124SMoriah Waterland 
25675c51f124SMoriah Waterland 	if (retcode != 0) {
25685c51f124SMoriah Waterland 		echoDebug(DBG_MERGINFOS_EXIT, pkginfo_path, retcode);
25695c51f124SMoriah Waterland 
25705c51f124SMoriah Waterland 		return (retcode);
25715c51f124SMoriah Waterland 	}
25725c51f124SMoriah Waterland 
25735c51f124SMoriah Waterland 	/*
25745c51f124SMoriah Waterland 	 * verify that no zone attribute has been
25755c51f124SMoriah Waterland 	 * set to an invalid value
25765c51f124SMoriah Waterland 	 */
25775c51f124SMoriah Waterland 
25785c51f124SMoriah Waterland 	/* SUNW_PKG_ALLZONES */
25795c51f124SMoriah Waterland 
25805c51f124SMoriah Waterland 	newValue = getenv(PKG_ALLZONES_VARIABLE);
25815c51f124SMoriah Waterland 
25825c51f124SMoriah Waterland 	/*
25835c51f124SMoriah Waterland 	 * complain if setting SUNW_PKG_ALLZONES to other than "false"
25845c51f124SMoriah Waterland 	 */
25855c51f124SMoriah Waterland 
25865c51f124SMoriah Waterland 
25875c51f124SMoriah Waterland 	if ((newValue != NULL) && (*SUNW_PKG_ALLZONES == '\0') &&
25885c51f124SMoriah Waterland 	    (strcasecmp(newValue, "false") != 0)) {
25895c51f124SMoriah Waterland 		/* change ALLZONES from "true" to "false" (unset) */
25905c51f124SMoriah Waterland 		progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName,
25915c51f124SMoriah Waterland 		    pkgVersion, PKG_ALLZONES_VARIABLE, newValue);
25925c51f124SMoriah Waterland 		return (1);
25935c51f124SMoriah Waterland 	}
25945c51f124SMoriah Waterland 
25955c51f124SMoriah Waterland 	/* SUNW_PKG_THISZONE */
25965c51f124SMoriah Waterland 
25975c51f124SMoriah Waterland 	newValue = getenv(PKG_THISZONE_VARIABLE);
25985c51f124SMoriah Waterland 
25995c51f124SMoriah Waterland 	/*
26005c51f124SMoriah Waterland 	 * complain if setting SUNW_PKG_THISZONE to other than "false"
26015c51f124SMoriah Waterland 	 */
26025c51f124SMoriah Waterland 
26035c51f124SMoriah Waterland 	if ((newValue != NULL) && (*SUNW_PKG_THISZONE == '\0') &&
26045c51f124SMoriah Waterland 	    (strcasecmp(newValue, "false") != 0)) {
26055c51f124SMoriah Waterland 		/* change THISZONE from "true" to "false" (unset) */
26065c51f124SMoriah Waterland 		progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName,
26075c51f124SMoriah Waterland 		    pkgVersion, PKG_THISZONE_VARIABLE, newValue);
26085c51f124SMoriah Waterland 		return (1);
26095c51f124SMoriah Waterland 	}
26105c51f124SMoriah Waterland 
26115c51f124SMoriah Waterland 	/* SUNW_PKG_HOLLOW */
26125c51f124SMoriah Waterland 
26135c51f124SMoriah Waterland 	newValue = getenv(PKG_HOLLOW_VARIABLE);
26145c51f124SMoriah Waterland 
26155c51f124SMoriah Waterland 	/* complain if setting SUNW_PKG_HOLLOW to other than "false" */
26165c51f124SMoriah Waterland 
26175c51f124SMoriah Waterland 	if ((newValue != NULL) && (*SUNW_PKG_HOLLOW == '\0') &&
26185c51f124SMoriah Waterland 	    (strcasecmp(newValue, "false") != 0)) {
26195c51f124SMoriah Waterland 		/* change HOLLOW from "true" to 'false" (unset) */
26205c51f124SMoriah Waterland 		progerr(ERR_MERGINFOS_SET_ZONEATTR, pkgName,
26215c51f124SMoriah Waterland 		    pkgVersion, PKG_HOLLOW_VARIABLE, newValue);
26225c51f124SMoriah Waterland 		return (1);
26235c51f124SMoriah Waterland 	}
26245c51f124SMoriah Waterland 
26255c51f124SMoriah Waterland 	echoDebug(DBG_MERGINFOS_EXIT, pkginfo_path, 0);
26265c51f124SMoriah Waterland 
26275c51f124SMoriah Waterland 	return (0);
26285c51f124SMoriah Waterland }
26295c51f124SMoriah Waterland 
26305c51f124SMoriah Waterland static void
26315c51f124SMoriah Waterland set_dryrun_dir_loc(void)
26325c51f124SMoriah Waterland {
26335c51f124SMoriah Waterland 	/* Set pkg location to the dryrun directory */
26345c51f124SMoriah Waterland 	set_PKGLOC(pkgdrtarg);
26355c51f124SMoriah Waterland 	(void) snprintf(pkgloc, sizeof (pkgloc),
26365c51f124SMoriah Waterland 			"%s/%s", get_PKGLOC(), pkginst);
26375c51f124SMoriah Waterland 	(void) snprintf(pkgbin, sizeof (pkgbin),
26385c51f124SMoriah Waterland 			"%s/install", pkgloc);
26395c51f124SMoriah Waterland 	(void) snprintf(pkgsav, sizeof (pkgsav),
26405c51f124SMoriah Waterland 			"%s/save", pkgloc);
26415c51f124SMoriah Waterland 	(void) snprintf(ilockfile, sizeof (ilockfile),
26425c51f124SMoriah Waterland 			"%s/!I-Lock!", pkgloc);
26435c51f124SMoriah Waterland 	(void) snprintf(rlockfile, sizeof (rlockfile),
26445c51f124SMoriah Waterland 			"%s/!R-Lock!", pkgloc);
26455c51f124SMoriah Waterland 	(void) snprintf(savlog, sizeof (savlog),
26465c51f124SMoriah Waterland 			"%s/logs/%s", get_PKGADM(), pkginst);
26475c51f124SMoriah Waterland }
26485c51f124SMoriah Waterland 
26495c51f124SMoriah Waterland /*
26505c51f124SMoriah Waterland  * If we are updating a pkg, then we need to copy the "old" pkgloc so that
26515c51f124SMoriah Waterland  * any scripts that got removed in the new version aren't left around.  So we
26525c51f124SMoriah Waterland  * copy it here to .save.pkgloc, then in quit() we can restore our state, or
26535c51f124SMoriah Waterland  * remove it.
26545c51f124SMoriah Waterland  */
26555c51f124SMoriah Waterland static int
26565c51f124SMoriah Waterland cp_pkgdirs(void)
26575c51f124SMoriah Waterland {
26585c51f124SMoriah Waterland 	if (in_dryrun_mode()) {
26595c51f124SMoriah Waterland 		set_dryrun_dir_loc();
26605c51f124SMoriah Waterland 	}
26615c51f124SMoriah Waterland 
26625c51f124SMoriah Waterland 	/*
26635c51f124SMoriah Waterland 	 * If we're not in dryrun mode and we can find an old set of package
26645c51f124SMoriah Waterland 	 * files over which the new ones will be written, do the copy.
26655c51f124SMoriah Waterland 	 */
26665c51f124SMoriah Waterland 	if (!in_dryrun_mode() && pkgloc[0] && !access(pkgloc, F_OK)) {
26675c51f124SMoriah Waterland 		int status;
26685c51f124SMoriah Waterland 		int r;
26695c51f124SMoriah Waterland 
26705c51f124SMoriah Waterland 		(void) snprintf(pkgloc_sav, sizeof (pkgloc_sav), "%s/.save.%s",
26715c51f124SMoriah Waterland 			get_PKGLOC(), pkginst);
26725c51f124SMoriah Waterland 
26735c51f124SMoriah Waterland 		/*
26745c51f124SMoriah Waterland 		 * Even though it takes a while, we use a recursive copy here
26755c51f124SMoriah Waterland 		 * because if the current pkgadd fails for any reason, we
26765c51f124SMoriah Waterland 		 * don't want to lose this data.
26775c51f124SMoriah Waterland 		 */
26785c51f124SMoriah Waterland 		r = e_ExecCmdList(&status, (char **)NULL, (char *)NULL,
26795c51f124SMoriah Waterland 			"/usr/bin/cp", "cp", "-r", pkgloc, pkgloc_sav,
26805c51f124SMoriah Waterland 			(char *)NULL);
26815c51f124SMoriah Waterland 
26825c51f124SMoriah Waterland 		if ((r != 0) || (status == -1) || (WEXITSTATUS(status) != 0)) {
26835c51f124SMoriah Waterland 			progerr(ERR_PKGBINCP, pkgloc, pkgloc_sav);
26845c51f124SMoriah Waterland 			return (99);
26855c51f124SMoriah Waterland 		}
26865c51f124SMoriah Waterland 	}
26875c51f124SMoriah Waterland 
26885c51f124SMoriah Waterland 	return (0);
26895c51f124SMoriah Waterland }
26905c51f124SMoriah Waterland 
26915c51f124SMoriah Waterland /*
26925c51f124SMoriah Waterland  * This implements the pkgask function. It just executes the request script
26935c51f124SMoriah Waterland  * and stores the results in a response file.
26945c51f124SMoriah Waterland  */
26955c51f124SMoriah Waterland static void
26965c51f124SMoriah Waterland do_pkgask(boolean_t a_run_request_as_root)
26975c51f124SMoriah Waterland {
26985c51f124SMoriah Waterland 	if (pkgdev.cdevice) {
26995c51f124SMoriah Waterland 		unpack();
27005c51f124SMoriah Waterland 		if (!suppressCopyright) {
27015c51f124SMoriah Waterland 			copyright();
27025c51f124SMoriah Waterland 		}
27035c51f124SMoriah Waterland 	}
27045c51f124SMoriah Waterland 	(void) snprintf(path, sizeof (path), "%s/%s", instdir, REQUEST_FILE);
27055c51f124SMoriah Waterland 	if (access(path, F_OK)) {
27065c51f124SMoriah Waterland 		progerr(ERR_NOREQUEST);
27075c51f124SMoriah Waterland 		quit(1);
27085c51f124SMoriah Waterland 		/*NOTREACHED*/
27095c51f124SMoriah Waterland 	}
27105c51f124SMoriah Waterland 
27115c51f124SMoriah Waterland 	(void) set_respfile(respfile, srcinst, RESP_WR);
27125c51f124SMoriah Waterland 
27135c51f124SMoriah Waterland 	if (is_a_respfile()) {
27145c51f124SMoriah Waterland 		ckreturn(reqexec(update, path, non_abi_scripts,
27155c51f124SMoriah Waterland 			a_run_request_as_root), ERR_REQUEST);
27165c51f124SMoriah Waterland 	} else {
27175c51f124SMoriah Waterland 		failflag++;
27185c51f124SMoriah Waterland 	}
27195c51f124SMoriah Waterland 
27205c51f124SMoriah Waterland 	if (warnflag || failflag) {
27215c51f124SMoriah Waterland 		(void) remove(respfile);
27225c51f124SMoriah Waterland 		echo("\nResponse file <%s> was not created.",
27235c51f124SMoriah Waterland 			get_respfile());
27245c51f124SMoriah Waterland 	} else {
27255c51f124SMoriah Waterland 		echo("\nResponse file <%s> was created.",
27265c51f124SMoriah Waterland 			get_respfile());
27275c51f124SMoriah Waterland 	}
27285c51f124SMoriah Waterland 
27295c51f124SMoriah Waterland 	quit(0);
27305c51f124SMoriah Waterland 	/*NOTREACHED*/
27315c51f124SMoriah Waterland }
27325c51f124SMoriah Waterland 
27335c51f124SMoriah Waterland /*
27345c51f124SMoriah Waterland  * This function runs a check utility and acts appropriately based upon the
27355c51f124SMoriah Waterland  * return code. It deals appropriately with the dryrun file if it is present.
27365c51f124SMoriah Waterland  */
27375c51f124SMoriah Waterland static void
27385c51f124SMoriah Waterland ck_w_dryrun(int (*func)(), int type)
27395c51f124SMoriah Waterland {
27405c51f124SMoriah Waterland 	int n;
27415c51f124SMoriah Waterland 
27425c51f124SMoriah Waterland 	n = func();
27435c51f124SMoriah Waterland 	if (in_dryrun_mode())
27445c51f124SMoriah Waterland 		set_dr_info(type, !n);
27455c51f124SMoriah Waterland 
27465c51f124SMoriah Waterland 	if (n) {
27475c51f124SMoriah Waterland 		quit(n);
27485c51f124SMoriah Waterland 		/*NOTREACHED*/
27495c51f124SMoriah Waterland 	}
27505c51f124SMoriah Waterland }
27515c51f124SMoriah Waterland 
27525c51f124SMoriah Waterland /*
27535c51f124SMoriah Waterland  * This function deletes all install class action scripts from the package
27545c51f124SMoriah Waterland  * directory on the root filesystem.
27555c51f124SMoriah Waterland  */
27565c51f124SMoriah Waterland static void
27575c51f124SMoriah Waterland rm_icas(char *cas_dir)
27585c51f124SMoriah Waterland {
27595c51f124SMoriah Waterland 	DIR	*pdirfp;
27605c51f124SMoriah Waterland 	struct	dirent *dp;
27615c51f124SMoriah Waterland 	char path[PATH_MAX];
27625c51f124SMoriah Waterland 
27635c51f124SMoriah Waterland 	if ((pdirfp = opendir(cas_dir)) == NULL)
27645c51f124SMoriah Waterland 		return;
27655c51f124SMoriah Waterland 
27665c51f124SMoriah Waterland 	while ((dp = readdir(pdirfp)) != NULL) {
27675c51f124SMoriah Waterland 		if (dp->d_name[0] == '.')
27685c51f124SMoriah Waterland 			continue;
27695c51f124SMoriah Waterland 
27705c51f124SMoriah Waterland 		if (dp->d_name[0] == 'i' && dp->d_name[1] == '.') {
27715c51f124SMoriah Waterland 			(void) snprintf(path, sizeof (path),
27725c51f124SMoriah Waterland 				"%s/%s", cas_dir, dp->d_name);
27735c51f124SMoriah Waterland 			(void) remove(path);
27745c51f124SMoriah Waterland 		}
27755c51f124SMoriah Waterland 	}
27765c51f124SMoriah Waterland 	(void) closedir(pdirfp);
27775c51f124SMoriah Waterland }
27785c51f124SMoriah Waterland 
27795c51f124SMoriah Waterland void
27805c51f124SMoriah Waterland ckreturn(int retcode, char *msg)
27815c51f124SMoriah Waterland {
27825c51f124SMoriah Waterland 	switch (retcode) {
27835c51f124SMoriah Waterland 		case 2:
27845c51f124SMoriah Waterland 		case 12:
27855c51f124SMoriah Waterland 		case 22:
27865c51f124SMoriah Waterland 		warnflag++;
27875c51f124SMoriah Waterland 		if (msg) {
27885c51f124SMoriah Waterland 			progerr("%s", msg);
27895c51f124SMoriah Waterland 		}
27905c51f124SMoriah Waterland 		/*FALLTHRU*/
27915c51f124SMoriah Waterland 		case 10:
27925c51f124SMoriah Waterland 		case 20:
27935c51f124SMoriah Waterland 		if (retcode >= 10 && retcode < 20) {
27945c51f124SMoriah Waterland 			dreboot++;
27955c51f124SMoriah Waterland 		}
27965c51f124SMoriah Waterland 		if (retcode >= 20) {
27975c51f124SMoriah Waterland 			ireboot++;
27985c51f124SMoriah Waterland 		}
27995c51f124SMoriah Waterland 		/*FALLTHRU*/
28005c51f124SMoriah Waterland 		case 0:
28015c51f124SMoriah Waterland 		break; /* okay */
28025c51f124SMoriah Waterland 
28035c51f124SMoriah Waterland 		case -1:
28045c51f124SMoriah Waterland 		retcode = 99;
28055c51f124SMoriah Waterland 		/*FALLTHRU*/
28065c51f124SMoriah Waterland 		case 99:
28075c51f124SMoriah Waterland 		case 1:
28085c51f124SMoriah Waterland 		case 11:
28095c51f124SMoriah Waterland 		case 21:
28105c51f124SMoriah Waterland 		case 4:
28115c51f124SMoriah Waterland 		case 14:
28125c51f124SMoriah Waterland 		case 24:
28135c51f124SMoriah Waterland 		case 5:
28145c51f124SMoriah Waterland 		case 15:
28155c51f124SMoriah Waterland 		case 25:
28165c51f124SMoriah Waterland 		if (msg) {
28175c51f124SMoriah Waterland 			progerr("%s", msg);
28185c51f124SMoriah Waterland 		}
28195c51f124SMoriah Waterland 		/*FALLTHRU*/
28205c51f124SMoriah Waterland 		case 3:
28215c51f124SMoriah Waterland 		case 13:
28225c51f124SMoriah Waterland 		case 23:
28235c51f124SMoriah Waterland 		quit(retcode);
28245c51f124SMoriah Waterland 		/*NOTREACHED*/
28255c51f124SMoriah Waterland 		default:
28265c51f124SMoriah Waterland 		if (msg) {
28275c51f124SMoriah Waterland 			progerr("%s", msg);
28285c51f124SMoriah Waterland 		}
28295c51f124SMoriah Waterland 		quit(1);
28305c51f124SMoriah Waterland 		/*NOTREACHED*/
28315c51f124SMoriah Waterland 	}
28325c51f124SMoriah Waterland }
28335c51f124SMoriah Waterland 
28345c51f124SMoriah Waterland static void
28355c51f124SMoriah Waterland copyright(void)
28365c51f124SMoriah Waterland {
28375c51f124SMoriah Waterland 	FILE	*fp;
28385c51f124SMoriah Waterland 	char	line[LSIZE];
28395c51f124SMoriah Waterland 	char	path[PATH_MAX];
28405c51f124SMoriah Waterland 
28415c51f124SMoriah Waterland 	/* Compose full path for copyright file */
28425c51f124SMoriah Waterland 	(void) snprintf(path, sizeof (path), "%s/%s", instdir, COPYRIGHT_FILE);
28435c51f124SMoriah Waterland 
28445c51f124SMoriah Waterland 	if ((fp = fopen(path, "r")) == NULL) {
28455c51f124SMoriah Waterland 		if (getenv("VENDOR") != NULL)
28465c51f124SMoriah Waterland 			echo(getenv("VENDOR"));
28475c51f124SMoriah Waterland 	} else {
28485c51f124SMoriah Waterland 		while (fgets(line, LSIZE, fp))
28495c51f124SMoriah Waterland 			(void) fprintf(stdout, "%s", line); /* bug #1083713 */
28505c51f124SMoriah Waterland 		(void) fclose(fp);
28515c51f124SMoriah Waterland 	}
28525c51f124SMoriah Waterland }
28535c51f124SMoriah Waterland 
28545c51f124SMoriah Waterland static int
28555c51f124SMoriah Waterland rdonly(char *p)
28565c51f124SMoriah Waterland {
28575c51f124SMoriah Waterland 	int	i;
28585c51f124SMoriah Waterland 
28595c51f124SMoriah Waterland 	for (i = 0; ro_params[i]; i++) {
28605c51f124SMoriah Waterland 		if (strcmp(p, ro_params[i]) == 0)
28615c51f124SMoriah Waterland 			return (1);
28625c51f124SMoriah Waterland 	}
28635c51f124SMoriah Waterland 	return (0);
28645c51f124SMoriah Waterland }
28655c51f124SMoriah Waterland 
28665c51f124SMoriah Waterland static void
28675c51f124SMoriah Waterland unpack(void)
28685c51f124SMoriah Waterland {
28695c51f124SMoriah Waterland 	/*
28705c51f124SMoriah Waterland 	 * read in next part from stream, even if we decide
28715c51f124SMoriah Waterland 	 * later that we don't need it
28725c51f124SMoriah Waterland 	 */
28735c51f124SMoriah Waterland 	if (dparts < 1) {
28745c51f124SMoriah Waterland 		progerr(ERR_DSTREAMCNT);
28755c51f124SMoriah Waterland 		quit(99);
28765c51f124SMoriah Waterland 		/*NOTREACHED*/
28775c51f124SMoriah Waterland 	}
28785c51f124SMoriah Waterland 	if ((access(instdir, F_OK) == 0) && rrmdir(instdir)) {
28795c51f124SMoriah Waterland 		progerr(ERR_RMDIR, instdir);
28805c51f124SMoriah Waterland 		quit(99);
28815c51f124SMoriah Waterland 		/*NOTREACHED*/
28825c51f124SMoriah Waterland 	}
28835c51f124SMoriah Waterland 	if (mkdir(instdir, 0755)) {
28845c51f124SMoriah Waterland 		progerr(ERR_MKDIR, instdir);
28855c51f124SMoriah Waterland 		quit(99);
28865c51f124SMoriah Waterland 		/*NOTREACHED*/
28875c51f124SMoriah Waterland 	}
28885c51f124SMoriah Waterland 	if (chdir(instdir)) {
28895c51f124SMoriah Waterland 		progerr(ERR_CHDIR, instdir);
28905c51f124SMoriah Waterland 		quit(99);
28915c51f124SMoriah Waterland 		/*NOTREACHED*/
28925c51f124SMoriah Waterland 	}
28935c51f124SMoriah Waterland 	if (!ds_fd_open()) {
28945c51f124SMoriah Waterland 		dparts = ds_findpkg(pkgdev.cdevice, srcinst);
28955c51f124SMoriah Waterland 		if (dparts < 1) {
28965c51f124SMoriah Waterland 			progerr(ERR_DSARCH, srcinst);
28975c51f124SMoriah Waterland 			quit(99);
28985c51f124SMoriah Waterland 			/*NOTREACHED*/
28995c51f124SMoriah Waterland 		}
29005c51f124SMoriah Waterland 	}
29015c51f124SMoriah Waterland 
29025c51f124SMoriah Waterland 	dparts--;
29035c51f124SMoriah Waterland 
29045c51f124SMoriah Waterland 	if (ds_next(pkgdev.cdevice, instdir)) {
29055c51f124SMoriah Waterland 		progerr(ERR_DSTREAM);
29065c51f124SMoriah Waterland 		quit(99);
29075c51f124SMoriah Waterland 		/*NOTREACHED*/
29085c51f124SMoriah Waterland 	}
29095c51f124SMoriah Waterland 	if (chdir(get_PKGADM())) {
29105c51f124SMoriah Waterland 		progerr(ERR_CHDIR, get_PKGADM());
29115c51f124SMoriah Waterland 		quit(99);
29125c51f124SMoriah Waterland 		/*NOTREACHED*/
29135c51f124SMoriah Waterland 	}
29145c51f124SMoriah Waterland 	ds_close(1);
29155c51f124SMoriah Waterland }
29165c51f124SMoriah Waterland 
29175c51f124SMoriah Waterland static void
29185c51f124SMoriah Waterland usage(void)
29195c51f124SMoriah Waterland {
29205c51f124SMoriah Waterland 	(void) fprintf(stderr, ERR_USAGE_PKGINSTALL);
29215c51f124SMoriah Waterland 	exit(1);
29225c51f124SMoriah Waterland 	/*NOTREACHED*/
29235c51f124SMoriah Waterland }
2924