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