15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland  * CDDL HEADER START
35c51f124SMoriah Waterland  *
45c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland  *
85c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland  * See the License for the specific language governing permissions
115c51f124SMoriah Waterland  * and limitations under the License.
125c51f124SMoriah Waterland  *
135c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland  *
195c51f124SMoriah Waterland  * CDDL HEADER END
205c51f124SMoriah Waterland  */
215c51f124SMoriah Waterland 
225c51f124SMoriah Waterland /*
23*62224350SCasper H.S. Dik  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
245c51f124SMoriah Waterland  * Use is subject to license terms.
255c51f124SMoriah Waterland  */
265c51f124SMoriah Waterland 
275c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
285c51f124SMoriah Waterland /* All Rights Reserved */
295c51f124SMoriah Waterland 
305c51f124SMoriah Waterland 
315c51f124SMoriah Waterland /*
325c51f124SMoriah Waterland  * This module constructs a list of entries from the pkgmap associated
335c51f124SMoriah Waterland  * with this package. When finished, this list is sorted in alphabetical
345c51f124SMoriah Waterland  * order and an accompanying structure list, mergstat, provides
355c51f124SMoriah Waterland  * information about how these new files merge with existing files
365c51f124SMoriah Waterland  * already on the system.
375c51f124SMoriah Waterland  */
385c51f124SMoriah Waterland 
395c51f124SMoriah Waterland #include <stdio.h>
405c51f124SMoriah Waterland #include <string.h>
415c51f124SMoriah Waterland #include <limits.h>
425c51f124SMoriah Waterland #include <stdlib.h>
435c51f124SMoriah Waterland #include <unistd.h>
445c51f124SMoriah Waterland #include <sys/types.h>
455c51f124SMoriah Waterland #include <pkgstrct.h>
465c51f124SMoriah Waterland #include <pkglocs.h>
475c51f124SMoriah Waterland #include <locale.h>
485c51f124SMoriah Waterland #include <libintl.h>
495c51f124SMoriah Waterland #include <install.h>
505c51f124SMoriah Waterland #include <pkglib.h>
515c51f124SMoriah Waterland #include <libadm.h>
525c51f124SMoriah Waterland #include <libinst.h>
535c51f124SMoriah Waterland 
545c51f124SMoriah Waterland /* libinst/ocfile.c */
555c51f124SMoriah Waterland extern int	dbchg;
565c51f124SMoriah Waterland 
575c51f124SMoriah Waterland static int	client_refer(struct cfextra **ext);
585c51f124SMoriah Waterland static int	server_refer(struct cfextra **ext);
595c51f124SMoriah Waterland 
605c51f124SMoriah Waterland int
sortmap(struct cfextra *** extlist,VFP_T * pkgmapVfp,PKGserver pkgserver,VFP_T * tmpvfp,char * a_zoneName)615c51f124SMoriah Waterland sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
62*62224350SCasper H.S. Dik     PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
635c51f124SMoriah Waterland {
645c51f124SMoriah Waterland 	int	i, n, nparts;
655c51f124SMoriah Waterland 	char *db_mrg = "unable to merge package and system information";
665c51f124SMoriah Waterland 
675c51f124SMoriah Waterland 	if (a_zoneName == (char *)NULL) {
685c51f124SMoriah Waterland 		echo(gettext("## Processing package information."));
695c51f124SMoriah Waterland 	} else {
705c51f124SMoriah Waterland 		echo(gettext("## Processing package information in zone <%s>."),
71*62224350SCasper H.S. Dik 		    a_zoneName);
725c51f124SMoriah Waterland 	}
735c51f124SMoriah Waterland 
745c51f124SMoriah Waterland 	/*
755c51f124SMoriah Waterland 	 * The following instruction puts the client-relative basedir
765c51f124SMoriah Waterland 	 * into the environment iff it's a relocatable package and
775c51f124SMoriah Waterland 	 * we're installing to a client. Otherwise, it uses the regular
785c51f124SMoriah Waterland 	 * basedir. The only reason for this is so that mappath() upon
795c51f124SMoriah Waterland 	 * finding $BASEDIR in a path will properly resolve it to the
805c51f124SMoriah Waterland 	 * client-relative path. This way eval_path() can properly
815c51f124SMoriah Waterland 	 * construct the server-relative path.
825c51f124SMoriah Waterland 	 */
835c51f124SMoriah Waterland 	if (is_relocatable() && is_an_inst_root())
845c51f124SMoriah Waterland 		putparam("BASEDIR", get_info_basedir());
855c51f124SMoriah Waterland 
865c51f124SMoriah Waterland 	/*
875c51f124SMoriah Waterland 	 * read the pkgmap provided by this package into
885c51f124SMoriah Waterland 	 * memory; map parameters specified in the pathname
895c51f124SMoriah Waterland 	 * and sort in memory by pathname
905c51f124SMoriah Waterland 	 */
915c51f124SMoriah Waterland 
925c51f124SMoriah Waterland 	vfpRewind(pkgmapVfp);		/* rewind input file */
935c51f124SMoriah Waterland 
945c51f124SMoriah Waterland 	*extlist = pkgobjmap(pkgmapVfp, 2, NULL);
955c51f124SMoriah Waterland 
965c51f124SMoriah Waterland 	if (*extlist == NULL) {
975c51f124SMoriah Waterland 		progerr(gettext("unable to process pkgmap"));
985c51f124SMoriah Waterland 		quit(99);
995c51f124SMoriah Waterland 	}
1005c51f124SMoriah Waterland 
1015c51f124SMoriah Waterland 	/* Make all paths client-relative if necessary. */
1025c51f124SMoriah Waterland 	if (is_an_inst_root()) {
1035c51f124SMoriah Waterland 		(void) client_refer(*extlist);
1045c51f124SMoriah Waterland 	}
1055c51f124SMoriah Waterland 
1065c51f124SMoriah Waterland 	if (a_zoneName == (char *)NULL) {
1075c51f124SMoriah Waterland 		echo(gettext("## Processing system information."));
1085c51f124SMoriah Waterland 	} else {
1095c51f124SMoriah Waterland 		echo(gettext("## Processing system information in zone <%s>."),
110*62224350SCasper H.S. Dik 		    a_zoneName);
1115c51f124SMoriah Waterland 	}
1125c51f124SMoriah Waterland 
1135c51f124SMoriah Waterland 	/*
1145c51f124SMoriah Waterland 	 * calculate the number of parts in this package
1155c51f124SMoriah Waterland 	 * by locating the entry with the largest "volno"
1165c51f124SMoriah Waterland 	 * associated with it
1175c51f124SMoriah Waterland 	 */
1185c51f124SMoriah Waterland 	nparts = 0;
1195c51f124SMoriah Waterland 	if (is_depend_pkginfo_DB() == B_FALSE) {
1205c51f124SMoriah Waterland 		for (i = 0; (*extlist)[i]; i++) {
1215c51f124SMoriah Waterland 			n = (*extlist)[i]->cf_ent.volno;
1225c51f124SMoriah Waterland 			if (n > nparts)
1235c51f124SMoriah Waterland 				nparts = n;
1245c51f124SMoriah Waterland 		}
1255c51f124SMoriah Waterland 
1265c51f124SMoriah Waterland 		vfpTruncate(tmpvfp);
1275c51f124SMoriah Waterland 
128*62224350SCasper H.S. Dik 		dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
1295c51f124SMoriah Waterland 		if (dbchg < 0) {
1305c51f124SMoriah Waterland 			progerr(gettext(db_mrg));
1315c51f124SMoriah Waterland 			quit(99);
1325c51f124SMoriah Waterland 		}
1335c51f124SMoriah Waterland 	}
1345c51f124SMoriah Waterland 
1355c51f124SMoriah Waterland 	/* Restore the original BASEDIR. */
1365c51f124SMoriah Waterland 	if (is_relocatable() && is_an_inst_root())
1375c51f124SMoriah Waterland 		putparam("BASEDIR", get_basedir());
1385c51f124SMoriah Waterland 
1395c51f124SMoriah Waterland 	if (is_an_inst_root()) {
1405c51f124SMoriah Waterland 		(void) server_refer(*extlist);
1415c51f124SMoriah Waterland 	}
1425c51f124SMoriah Waterland 
1435c51f124SMoriah Waterland 	return (nparts);
1445c51f124SMoriah Waterland }
1455c51f124SMoriah Waterland 
1465c51f124SMoriah Waterland static int
client_refer(struct cfextra ** ext)1475c51f124SMoriah Waterland client_refer(struct cfextra **ext)
1485c51f124SMoriah Waterland {
1495c51f124SMoriah Waterland 	int count;
1505c51f124SMoriah Waterland 
1515c51f124SMoriah Waterland 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
1525c51f124SMoriah Waterland 		ext[count]->cf_ent.path = ext[count]->client_path;
1535c51f124SMoriah Waterland 		ext[count]->cf_ent.ainfo.local = ext[count]->client_local;
1545c51f124SMoriah Waterland 	}
1555c51f124SMoriah Waterland 
1565c51f124SMoriah Waterland 	return (1);
1575c51f124SMoriah Waterland }
1585c51f124SMoriah Waterland 
1595c51f124SMoriah Waterland static int
server_refer(struct cfextra ** ext)1605c51f124SMoriah Waterland server_refer(struct cfextra **ext)
1615c51f124SMoriah Waterland {
1625c51f124SMoriah Waterland 	int count;
1635c51f124SMoriah Waterland 
1645c51f124SMoriah Waterland 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
1655c51f124SMoriah Waterland 		ext[count]->cf_ent.path = ext[count]->server_path;
1665c51f124SMoriah Waterland 		ext[count]->cf_ent.ainfo.local = ext[count]->server_local;
1675c51f124SMoriah Waterland 	}
1685c51f124SMoriah Waterland 
1695c51f124SMoriah Waterland 	return (1);
1705c51f124SMoriah Waterland }
171