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