getinst.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
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 *
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 *
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 *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdio.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <string.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdlib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <unistd.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <valtools.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <locale.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <libintl.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <pkginfo.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "install.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <pkglib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "libadm.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "libinst.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkginstall.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "messages.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern struct admin adm;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern char *pkgarch, *pkgvers, *msgtext, *pkgabrv;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int opresvr4, maxinst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char newinst[PKGSIZ];
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
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
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 Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandchar *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandgetinst(int *updatingExisting, struct pkginfo *info, int npkgs,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t a_preinstallCheck)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *inst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *sameinst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int nsamearch;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int samearch;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry debugging info */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland same_pkg = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If this is the first instance of the package, it's called the by
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the package abbreviation.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (npkgs == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this package is already installed; determine how to handle the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * new instance of the package to install
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ADM(instance, "newonly") || ADM(instance, "quit")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * new instance is required, or quit if not new
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland msgtext = MSG_NEWONLY;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_preinstallCheck == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ptext(stderr, msgtext, pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-new-only=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "ckinstance=4\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(4);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * package already installed and new instance not required
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * see if updating the same instance of the package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland samearch = nsamearch = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sameinst = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < npkgs; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(info[i].arch, pkgarch) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland samearch = i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nsamearch++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(info[i].version, pkgvers) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sameinst = info[i].pkginst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (sameinst) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* same instance of package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_preinstallCheck == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ptext(stderr, MSG_SAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-same-instance=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "ckinstance=0\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = sameinst; /* can't be overwriting a pre-svr4 package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland same_pkg++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*updatingExisting)++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ADM(instance, "overwrite")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not the same instance of the package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (npkgs == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland samearch = 0; /* use only package we know about */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (nsamearch != 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * more than one instance of the same ARCH is already
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * installed on this machine
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland msgtext = MSG_OVERWRITE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_preinstallCheck == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ptext(stderr, msgtext);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "install-ovewrite=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "ckinstance=4\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(4);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = info[samearch].pkginst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (info[samearch].status == PI_PRESVR4) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland opresvr4++; /* overwriting a pre-svr4 package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*updatingExisting)++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ADM(instance, "unique")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (maxinst <= npkgs) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* too many instances */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland msgtext = MSG_UNIQ1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_preinstallCheck == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ptext(stderr, msgtext, pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "install-too-many-instances=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "ckinstance=4\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(4);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = nextinst();
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_preinstallCheck == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (echoGetFlag() == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland msgtext = MSG_NOINTERACT;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ptext(stderr, msgtext);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(5);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "install-new-instance=true\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stdout, "ckinstance=1\n");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = prompt(info, npkgs);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(inst, "new") == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland inst = nextinst();
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*updatingExisting)++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
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 if (info[i].status == PI_PRESVR4) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland opresvr4++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
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 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandis_samepkg(void) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (same_pkg);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandnextinst(void)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct pkginfo info;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = 2; /* requirements say start at 2 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info.pkginst = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(newinst, pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (pkginfo(&info, newinst, NULL, NULL) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(newinst, sizeof (newinst),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s.%d", pkgabrv, n++);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (newinst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandprompt(struct pkginfo *info, int npkgs)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland CKMENU *menup;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *inst;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char ans[MAX_INPUT];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char header[256];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char temp[256];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (maxinst > npkgs) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the user may choose to install a completely new
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance of this package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = ckyorn(ans, NULL, NULL, MSG_GETINST_HELP1,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland MSG_GETINST_PROMPT1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(n);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strchr("yY", *ans) != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ("new");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(header, sizeof (header), MSG_GETINST_HEADER, pkgabrv);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland menup = allocmenu(header, CKALPHA);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < npkgs; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(temp, sizeof (temp),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s %s\n(%s) %s", info[i].pkginst,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info[i].name, info[i].arch, info[i].version);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setitem(menup, temp)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr("no memory");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(99);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (npkgs == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland printmenu(menup);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = ckyorn(ans, NULL, NULL, NULL, MSG_GETINST_PROMPT0))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(n);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strchr("yY", *ans) == NULL)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(3);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(newinst, info[0].pkginst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = ckitem(menup, &inst, 1, NULL, NULL, MSG_GETINST_HELP2,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland MSG_GETINST_PROMPT2))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland quit(n);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(newinst, inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) setitem(menup, 0); /* clear resource usage */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(menup); /* clear resource usage */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (newinst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}