getinst.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern char *pkgarch, *pkgvers, *msgtext, *pkgabrv;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *nextinst(void);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *prompt(struct pkginfo *info, int npkgs);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int same_pkg; /* same PKG, ARCH and VERSION */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the correct package instance based on how many packages are
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already installed. If there are none (npkgs == 0), it just returns the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * package abbreviation. Otherwise, it interacts with the user (or reads the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * admin file) to determine if we should overwrite an instance which is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already installed, or possibly install a new instance of this package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandgetinst(int *updatingExisting, struct pkginfo *info, int npkgs,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry debugging info */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If this is the first instance of the package, it's called the by
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the package abbreviation.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this package is already installed; determine how to handle the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * new instance of the package to install
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ADM(instance, "newonly") || ADM(instance, "quit")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * new instance is required, or quit if not new
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-new-only=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * package already installed and new instance not required
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * see if updating the same instance of the package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < npkgs; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(info[i].arch, pkgarch) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(info[i].version, pkgvers) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* same instance of package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-same-instance=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = sameinst; /* can't be overwriting a pre-svr4 package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not the same instance of the package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland samearch = 0; /* use only package we know about */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * more than one instance of the same ARCH is already
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * installed on this machine
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "install-ovewrite=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland opresvr4++; /* overwriting a pre-svr4 package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* too many instances */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "install-too-many-instances=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-new-instance=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if this instance is presvr4 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < npkgs; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(inst, info[i].pkginst) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This informs the caller whether the package in question is the same
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * version and architecture as an installed package of the same name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (pkginfo(&info, newinst, NULL, NULL) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the user may choose to install a completely new
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance of this package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = ckyorn(ans, NULL, NULL, MSG_GETINST_HELP1,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ("new");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(header, sizeof (header), MSG_GETINST_HEADER, pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < npkgs; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info[i].name, info[i].arch, info[i].version);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = ckyorn(ans, NULL, NULL, NULL, MSG_GETINST_PROMPT0))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = ckitem(menup, &inst, 1, NULL, NULL, MSG_GETINST_HELP2,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) setitem(menup, 0); /* clear resource usage */