1*9781SMoriah.Waterland@Sun.COM /* 2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START 3*9781SMoriah.Waterland@Sun.COM * 4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the 5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License"). 6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License. 7*9781SMoriah.Waterland@Sun.COM * 8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions 11*9781SMoriah.Waterland@Sun.COM * and limitations under the License. 12*9781SMoriah.Waterland@Sun.COM * 13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*9781SMoriah.Waterland@Sun.COM * 19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END 20*9781SMoriah.Waterland@Sun.COM */ 21*9781SMoriah.Waterland@Sun.COM 22*9781SMoriah.Waterland@Sun.COM /* 23*9781SMoriah.Waterland@Sun.COM * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms. 25*9781SMoriah.Waterland@Sun.COM */ 26*9781SMoriah.Waterland@Sun.COM 27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */ 29*9781SMoriah.Waterland@Sun.COM 30*9781SMoriah.Waterland@Sun.COM 31*9781SMoriah.Waterland@Sun.COM #include <stdio.h> 32*9781SMoriah.Waterland@Sun.COM #include <string.h> 33*9781SMoriah.Waterland@Sun.COM #include <stdlib.h> 34*9781SMoriah.Waterland@Sun.COM #include <unistd.h> 35*9781SMoriah.Waterland@Sun.COM #include <valtools.h> 36*9781SMoriah.Waterland@Sun.COM #include <locale.h> 37*9781SMoriah.Waterland@Sun.COM #include <libintl.h> 38*9781SMoriah.Waterland@Sun.COM #include <pkginfo.h> 39*9781SMoriah.Waterland@Sun.COM #include "install.h" 40*9781SMoriah.Waterland@Sun.COM #include <pkglib.h> 41*9781SMoriah.Waterland@Sun.COM #include "libadm.h" 42*9781SMoriah.Waterland@Sun.COM #include "libinst.h" 43*9781SMoriah.Waterland@Sun.COM #include "pkginstall.h" 44*9781SMoriah.Waterland@Sun.COM #include "messages.h" 45*9781SMoriah.Waterland@Sun.COM 46*9781SMoriah.Waterland@Sun.COM extern struct admin adm; 47*9781SMoriah.Waterland@Sun.COM extern char *pkgarch, *pkgvers, *msgtext, *pkgabrv; 48*9781SMoriah.Waterland@Sun.COM extern int opresvr4, maxinst; 49*9781SMoriah.Waterland@Sun.COM 50*9781SMoriah.Waterland@Sun.COM static char newinst[PKGSIZ]; 51*9781SMoriah.Waterland@Sun.COM static char *nextinst(void); 52*9781SMoriah.Waterland@Sun.COM static char *prompt(struct pkginfo *info, int npkgs); 53*9781SMoriah.Waterland@Sun.COM static int same_pkg; /* same PKG, ARCH and VERSION */ 54*9781SMoriah.Waterland@Sun.COM 55*9781SMoriah.Waterland@Sun.COM /* 56*9781SMoriah.Waterland@Sun.COM * This returns the correct package instance based on how many packages are 57*9781SMoriah.Waterland@Sun.COM * already installed. If there are none (npkgs == 0), it just returns the 58*9781SMoriah.Waterland@Sun.COM * package abbreviation. Otherwise, it interacts with the user (or reads the 59*9781SMoriah.Waterland@Sun.COM * admin file) to determine if we should overwrite an instance which is 60*9781SMoriah.Waterland@Sun.COM * already installed, or possibly install a new instance of this package 61*9781SMoriah.Waterland@Sun.COM */ 62*9781SMoriah.Waterland@Sun.COM char * 63*9781SMoriah.Waterland@Sun.COM getinst(int *updatingExisting, struct pkginfo *info, int npkgs, 64*9781SMoriah.Waterland@Sun.COM boolean_t a_preinstallCheck) 65*9781SMoriah.Waterland@Sun.COM { 66*9781SMoriah.Waterland@Sun.COM char *inst; 67*9781SMoriah.Waterland@Sun.COM char *sameinst; 68*9781SMoriah.Waterland@Sun.COM int i; 69*9781SMoriah.Waterland@Sun.COM int nsamearch; 70*9781SMoriah.Waterland@Sun.COM int samearch; 71*9781SMoriah.Waterland@Sun.COM 72*9781SMoriah.Waterland@Sun.COM /* entry debugging info */ 73*9781SMoriah.Waterland@Sun.COM 74*9781SMoriah.Waterland@Sun.COM same_pkg = 0; 75*9781SMoriah.Waterland@Sun.COM 76*9781SMoriah.Waterland@Sun.COM /* 77*9781SMoriah.Waterland@Sun.COM * If this is the first instance of the package, it's called the by 78*9781SMoriah.Waterland@Sun.COM * the package abbreviation. 79*9781SMoriah.Waterland@Sun.COM */ 80*9781SMoriah.Waterland@Sun.COM 81*9781SMoriah.Waterland@Sun.COM if (npkgs == 0) { 82*9781SMoriah.Waterland@Sun.COM return (pkgabrv); 83*9781SMoriah.Waterland@Sun.COM } 84*9781SMoriah.Waterland@Sun.COM 85*9781SMoriah.Waterland@Sun.COM /* 86*9781SMoriah.Waterland@Sun.COM * this package is already installed; determine how to handle the 87*9781SMoriah.Waterland@Sun.COM * new instance of the package to install 88*9781SMoriah.Waterland@Sun.COM */ 89*9781SMoriah.Waterland@Sun.COM 90*9781SMoriah.Waterland@Sun.COM if (ADM(instance, "newonly") || ADM(instance, "quit")) { 91*9781SMoriah.Waterland@Sun.COM /* 92*9781SMoriah.Waterland@Sun.COM * new instance is required, or quit if not new 93*9781SMoriah.Waterland@Sun.COM */ 94*9781SMoriah.Waterland@Sun.COM 95*9781SMoriah.Waterland@Sun.COM msgtext = MSG_NEWONLY; 96*9781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_FALSE) { 97*9781SMoriah.Waterland@Sun.COM ptext(stderr, msgtext, pkgabrv); 98*9781SMoriah.Waterland@Sun.COM } else { 99*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "install-new-only=true\n"); 100*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "ckinstance=4\n"); 101*9781SMoriah.Waterland@Sun.COM } 102*9781SMoriah.Waterland@Sun.COM quit(4); 103*9781SMoriah.Waterland@Sun.COM } 104*9781SMoriah.Waterland@Sun.COM 105*9781SMoriah.Waterland@Sun.COM /* 106*9781SMoriah.Waterland@Sun.COM * package already installed and new instance not required 107*9781SMoriah.Waterland@Sun.COM * see if updating the same instance of the package 108*9781SMoriah.Waterland@Sun.COM */ 109*9781SMoriah.Waterland@Sun.COM 110*9781SMoriah.Waterland@Sun.COM samearch = nsamearch = 0; 111*9781SMoriah.Waterland@Sun.COM sameinst = NULL; 112*9781SMoriah.Waterland@Sun.COM for (i = 0; i < npkgs; i++) { 113*9781SMoriah.Waterland@Sun.COM if (strcmp(info[i].arch, pkgarch) == NULL) { 114*9781SMoriah.Waterland@Sun.COM samearch = i; 115*9781SMoriah.Waterland@Sun.COM nsamearch++; 116*9781SMoriah.Waterland@Sun.COM if (strcmp(info[i].version, pkgvers) == NULL) { 117*9781SMoriah.Waterland@Sun.COM sameinst = info[i].pkginst; 118*9781SMoriah.Waterland@Sun.COM } 119*9781SMoriah.Waterland@Sun.COM } 120*9781SMoriah.Waterland@Sun.COM } 121*9781SMoriah.Waterland@Sun.COM 122*9781SMoriah.Waterland@Sun.COM if (sameinst) { 123*9781SMoriah.Waterland@Sun.COM /* same instance of package */ 124*9781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_FALSE) { 125*9781SMoriah.Waterland@Sun.COM ptext(stderr, MSG_SAME); 126*9781SMoriah.Waterland@Sun.COM } else { 127*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "install-same-instance=true\n"); 128*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "ckinstance=0\n"); 129*9781SMoriah.Waterland@Sun.COM } 130*9781SMoriah.Waterland@Sun.COM 131*9781SMoriah.Waterland@Sun.COM inst = sameinst; /* can't be overwriting a pre-svr4 package */ 132*9781SMoriah.Waterland@Sun.COM same_pkg++; 133*9781SMoriah.Waterland@Sun.COM (*updatingExisting)++; 134*9781SMoriah.Waterland@Sun.COM return (inst); 135*9781SMoriah.Waterland@Sun.COM } 136*9781SMoriah.Waterland@Sun.COM 137*9781SMoriah.Waterland@Sun.COM if (ADM(instance, "overwrite")) { 138*9781SMoriah.Waterland@Sun.COM /* not the same instance of the package */ 139*9781SMoriah.Waterland@Sun.COM if (npkgs == 1) { 140*9781SMoriah.Waterland@Sun.COM samearch = 0; /* use only package we know about */ 141*9781SMoriah.Waterland@Sun.COM } else if (nsamearch != 1) { 142*9781SMoriah.Waterland@Sun.COM /* 143*9781SMoriah.Waterland@Sun.COM * more than one instance of the same ARCH is already 144*9781SMoriah.Waterland@Sun.COM * installed on this machine 145*9781SMoriah.Waterland@Sun.COM */ 146*9781SMoriah.Waterland@Sun.COM msgtext = MSG_OVERWRITE; 147*9781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_FALSE) { 148*9781SMoriah.Waterland@Sun.COM ptext(stderr, msgtext); 149*9781SMoriah.Waterland@Sun.COM } else { 150*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, 151*9781SMoriah.Waterland@Sun.COM "install-ovewrite=true\n"); 152*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "ckinstance=4\n"); 153*9781SMoriah.Waterland@Sun.COM } 154*9781SMoriah.Waterland@Sun.COM quit(4); 155*9781SMoriah.Waterland@Sun.COM } 156*9781SMoriah.Waterland@Sun.COM 157*9781SMoriah.Waterland@Sun.COM inst = info[samearch].pkginst; 158*9781SMoriah.Waterland@Sun.COM if (info[samearch].status == PI_PRESVR4) { 159*9781SMoriah.Waterland@Sun.COM opresvr4++; /* overwriting a pre-svr4 package */ 160*9781SMoriah.Waterland@Sun.COM } 161*9781SMoriah.Waterland@Sun.COM 162*9781SMoriah.Waterland@Sun.COM (*updatingExisting)++; 163*9781SMoriah.Waterland@Sun.COM return (inst); 164*9781SMoriah.Waterland@Sun.COM } 165*9781SMoriah.Waterland@Sun.COM 166*9781SMoriah.Waterland@Sun.COM if (ADM(instance, "unique")) { 167*9781SMoriah.Waterland@Sun.COM if (maxinst <= npkgs) { 168*9781SMoriah.Waterland@Sun.COM /* too many instances */ 169*9781SMoriah.Waterland@Sun.COM msgtext = MSG_UNIQ1; 170*9781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_FALSE) { 171*9781SMoriah.Waterland@Sun.COM ptext(stderr, msgtext, pkgabrv); 172*9781SMoriah.Waterland@Sun.COM } else { 173*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, 174*9781SMoriah.Waterland@Sun.COM "install-too-many-instances=true\n"); 175*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "ckinstance=4\n"); 176*9781SMoriah.Waterland@Sun.COM } 177*9781SMoriah.Waterland@Sun.COM quit(4); 178*9781SMoriah.Waterland@Sun.COM } 179*9781SMoriah.Waterland@Sun.COM inst = nextinst(); 180*9781SMoriah.Waterland@Sun.COM return (inst); 181*9781SMoriah.Waterland@Sun.COM } 182*9781SMoriah.Waterland@Sun.COM 183*9781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_FALSE) { 184*9781SMoriah.Waterland@Sun.COM if (echoGetFlag() == B_FALSE) { 185*9781SMoriah.Waterland@Sun.COM msgtext = MSG_NOINTERACT; 186*9781SMoriah.Waterland@Sun.COM ptext(stderr, msgtext); 187*9781SMoriah.Waterland@Sun.COM quit(5); 188*9781SMoriah.Waterland@Sun.COM } 189*9781SMoriah.Waterland@Sun.COM } else { 190*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "install-new-instance=true\n"); 191*9781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "ckinstance=1\n"); 192*9781SMoriah.Waterland@Sun.COM } 193*9781SMoriah.Waterland@Sun.COM 194*9781SMoriah.Waterland@Sun.COM inst = prompt(info, npkgs); 195*9781SMoriah.Waterland@Sun.COM if (strcmp(inst, "new") == NULL) { 196*9781SMoriah.Waterland@Sun.COM inst = nextinst(); 197*9781SMoriah.Waterland@Sun.COM return (inst); 198*9781SMoriah.Waterland@Sun.COM } 199*9781SMoriah.Waterland@Sun.COM 200*9781SMoriah.Waterland@Sun.COM (*updatingExisting)++; 201*9781SMoriah.Waterland@Sun.COM 202*9781SMoriah.Waterland@Sun.COM /* see if this instance is presvr4 */ 203*9781SMoriah.Waterland@Sun.COM for (i = 0; i < npkgs; i++) { 204*9781SMoriah.Waterland@Sun.COM if (strcmp(inst, info[i].pkginst) == NULL) { 205*9781SMoriah.Waterland@Sun.COM if (info[i].status == PI_PRESVR4) { 206*9781SMoriah.Waterland@Sun.COM opresvr4++; 207*9781SMoriah.Waterland@Sun.COM } 208*9781SMoriah.Waterland@Sun.COM break; 209*9781SMoriah.Waterland@Sun.COM } 210*9781SMoriah.Waterland@Sun.COM } 211*9781SMoriah.Waterland@Sun.COM 212*9781SMoriah.Waterland@Sun.COM return (inst); 213*9781SMoriah.Waterland@Sun.COM } 214*9781SMoriah.Waterland@Sun.COM 215*9781SMoriah.Waterland@Sun.COM /* 216*9781SMoriah.Waterland@Sun.COM * This informs the caller whether the package in question is the same 217*9781SMoriah.Waterland@Sun.COM * version and architecture as an installed package of the same name. 218*9781SMoriah.Waterland@Sun.COM */ 219*9781SMoriah.Waterland@Sun.COM 220*9781SMoriah.Waterland@Sun.COM int 221*9781SMoriah.Waterland@Sun.COM is_samepkg(void) { 222*9781SMoriah.Waterland@Sun.COM return (same_pkg); 223*9781SMoriah.Waterland@Sun.COM } 224*9781SMoriah.Waterland@Sun.COM 225*9781SMoriah.Waterland@Sun.COM static char * 226*9781SMoriah.Waterland@Sun.COM nextinst(void) 227*9781SMoriah.Waterland@Sun.COM { 228*9781SMoriah.Waterland@Sun.COM struct pkginfo info; 229*9781SMoriah.Waterland@Sun.COM int n; 230*9781SMoriah.Waterland@Sun.COM 231*9781SMoriah.Waterland@Sun.COM n = 2; /* requirements say start at 2 */ 232*9781SMoriah.Waterland@Sun.COM 233*9781SMoriah.Waterland@Sun.COM info.pkginst = NULL; 234*9781SMoriah.Waterland@Sun.COM (void) strcpy(newinst, pkgabrv); 235*9781SMoriah.Waterland@Sun.COM while (pkginfo(&info, newinst, NULL, NULL) == 0) { 236*9781SMoriah.Waterland@Sun.COM (void) snprintf(newinst, sizeof (newinst), 237*9781SMoriah.Waterland@Sun.COM "%s.%d", pkgabrv, n++); 238*9781SMoriah.Waterland@Sun.COM } 239*9781SMoriah.Waterland@Sun.COM return (newinst); 240*9781SMoriah.Waterland@Sun.COM } 241*9781SMoriah.Waterland@Sun.COM 242*9781SMoriah.Waterland@Sun.COM static char * 243*9781SMoriah.Waterland@Sun.COM prompt(struct pkginfo *info, int npkgs) 244*9781SMoriah.Waterland@Sun.COM { 245*9781SMoriah.Waterland@Sun.COM CKMENU *menup; 246*9781SMoriah.Waterland@Sun.COM char *inst; 247*9781SMoriah.Waterland@Sun.COM char ans[MAX_INPUT]; 248*9781SMoriah.Waterland@Sun.COM char header[256]; 249*9781SMoriah.Waterland@Sun.COM char temp[256]; 250*9781SMoriah.Waterland@Sun.COM int i; 251*9781SMoriah.Waterland@Sun.COM int n; 252*9781SMoriah.Waterland@Sun.COM 253*9781SMoriah.Waterland@Sun.COM if (maxinst > npkgs) { 254*9781SMoriah.Waterland@Sun.COM /* 255*9781SMoriah.Waterland@Sun.COM * the user may choose to install a completely new 256*9781SMoriah.Waterland@Sun.COM * instance of this package 257*9781SMoriah.Waterland@Sun.COM */ 258*9781SMoriah.Waterland@Sun.COM n = ckyorn(ans, NULL, NULL, MSG_GETINST_HELP1, 259*9781SMoriah.Waterland@Sun.COM MSG_GETINST_PROMPT1); 260*9781SMoriah.Waterland@Sun.COM if (n != 0) { 261*9781SMoriah.Waterland@Sun.COM quit(n); 262*9781SMoriah.Waterland@Sun.COM } 263*9781SMoriah.Waterland@Sun.COM if (strchr("yY", *ans) != NULL) { 264*9781SMoriah.Waterland@Sun.COM return ("new"); 265*9781SMoriah.Waterland@Sun.COM } 266*9781SMoriah.Waterland@Sun.COM } 267*9781SMoriah.Waterland@Sun.COM 268*9781SMoriah.Waterland@Sun.COM (void) snprintf(header, sizeof (header), MSG_GETINST_HEADER, pkgabrv); 269*9781SMoriah.Waterland@Sun.COM menup = allocmenu(header, CKALPHA); 270*9781SMoriah.Waterland@Sun.COM 271*9781SMoriah.Waterland@Sun.COM for (i = 0; i < npkgs; i++) { 272*9781SMoriah.Waterland@Sun.COM (void) snprintf(temp, sizeof (temp), 273*9781SMoriah.Waterland@Sun.COM "%s %s\n(%s) %s", info[i].pkginst, 274*9781SMoriah.Waterland@Sun.COM info[i].name, info[i].arch, info[i].version); 275*9781SMoriah.Waterland@Sun.COM if (setitem(menup, temp)) { 276*9781SMoriah.Waterland@Sun.COM progerr("no memory"); 277*9781SMoriah.Waterland@Sun.COM quit(99); 278*9781SMoriah.Waterland@Sun.COM } 279*9781SMoriah.Waterland@Sun.COM } 280*9781SMoriah.Waterland@Sun.COM 281*9781SMoriah.Waterland@Sun.COM if (npkgs == 1) { 282*9781SMoriah.Waterland@Sun.COM printmenu(menup); 283*9781SMoriah.Waterland@Sun.COM if (n = ckyorn(ans, NULL, NULL, NULL, MSG_GETINST_PROMPT0)) 284*9781SMoriah.Waterland@Sun.COM quit(n); 285*9781SMoriah.Waterland@Sun.COM if (strchr("yY", *ans) == NULL) 286*9781SMoriah.Waterland@Sun.COM quit(3); 287*9781SMoriah.Waterland@Sun.COM (void) strcpy(newinst, info[0].pkginst); 288*9781SMoriah.Waterland@Sun.COM } else { 289*9781SMoriah.Waterland@Sun.COM if (n = ckitem(menup, &inst, 1, NULL, NULL, MSG_GETINST_HELP2, 290*9781SMoriah.Waterland@Sun.COM MSG_GETINST_PROMPT2)) 291*9781SMoriah.Waterland@Sun.COM quit(n); 292*9781SMoriah.Waterland@Sun.COM (void) strcpy(newinst, inst); 293*9781SMoriah.Waterland@Sun.COM } 294*9781SMoriah.Waterland@Sun.COM (void) setitem(menup, 0); /* clear resource usage */ 295*9781SMoriah.Waterland@Sun.COM free(menup); /* clear resource usage */ 296*9781SMoriah.Waterland@Sun.COM 297*9781SMoriah.Waterland@Sun.COM return (newinst); 298*9781SMoriah.Waterland@Sun.COM } 299