4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
43 #include "pkginstall.h"
46 extern struct admin adm
;
47 extern char *pkgarch
, *pkgvers
, *msgtext
, *pkgabrv
;
50 static char newinst
[PKGSIZ
];
51 static char *nextinst(void);
52 static char *prompt(struct pkginfo
*info
, int npkgs
);
53 static int same_pkg
; /* same PKG, ARCH and VERSION */
56 * This returns the correct package instance based on how many packages are
57 * already installed. If there are none (npkgs == 0), it just returns the
58 * package abbreviation. Otherwise, it interacts with the user (or reads the
59 * admin file) to determine if we should overwrite an instance which is
60 * already installed, or possibly install a new instance of this package
63 getinst(int *updatingExisting
, struct pkginfo
*info
, int npkgs
,
64 boolean_t a_preinstallCheck
)
72 /* entry debugging info */
77 * If this is the first instance of the package, it's called the by
78 * the package abbreviation.
86 * this package is already installed; determine how to handle the
87 * new instance of the package to install
90 if (ADM(instance
, "newonly") || ADM(instance
, "quit")) {
92 * new instance is required, or quit if not new
95 msgtext
= MSG_NEWONLY
;
96 if (a_preinstallCheck
== B_FALSE
) {
97 ptext(stderr
, msgtext
, pkgabrv
);
99 (void) fprintf(stdout
, "install-new-only=true\n");
100 (void) fprintf(stdout
, "ckinstance=4\n");
106 * package already installed and new instance not required
107 * see if updating the same instance of the package
110 samearch
= nsamearch
= 0;
112 for (i
= 0; i
< npkgs
; i
++) {
113 if (strcmp(info
[i
].arch
, pkgarch
) == NULL
) {
116 if (strcmp(info
[i
].version
, pkgvers
) == NULL
) {
117 sameinst
= info
[i
].pkginst
;
123 /* same instance of package */
124 if (a_preinstallCheck
== B_FALSE
) {
125 ptext(stderr
, MSG_SAME
);
127 (void) fprintf(stdout
, "install-same-instance=true\n");
128 (void) fprintf(stdout
, "ckinstance=0\n");
133 (*updatingExisting
)++;
137 if (ADM(instance
, "overwrite")) {
138 /* not the same instance of the package */
140 samearch
= 0; /* use only package we know about */
141 } else if (nsamearch
!= 1) {
143 * more than one instance of the same ARCH is already
144 * installed on this machine
146 msgtext
= MSG_OVERWRITE
;
147 if (a_preinstallCheck
== B_FALSE
) {
148 ptext(stderr
, msgtext
);
150 (void) fprintf(stdout
,
151 "install-ovewrite=true\n");
152 (void) fprintf(stdout
, "ckinstance=4\n");
157 inst
= info
[samearch
].pkginst
;
159 (*updatingExisting
)++;
163 if (ADM(instance
, "unique")) {
164 if (maxinst
<= npkgs
) {
165 /* too many instances */
167 if (a_preinstallCheck
== B_FALSE
) {
168 ptext(stderr
, msgtext
, pkgabrv
);
170 (void) fprintf(stdout
,
171 "install-too-many-instances=true\n");
172 (void) fprintf(stdout
, "ckinstance=4\n");
180 if (a_preinstallCheck
== B_FALSE
) {
181 if (echoGetFlag() == B_FALSE
) {
182 msgtext
= MSG_NOINTERACT
;
183 ptext(stderr
, msgtext
);
187 (void) fprintf(stdout
, "install-new-instance=true\n");
188 (void) fprintf(stdout
, "ckinstance=1\n");
191 inst
= prompt(info
, npkgs
);
192 if (strcmp(inst
, "new") == NULL
) {
197 (*updatingExisting
)++;
203 * This informs the caller whether the package in question is the same
204 * version and architecture as an installed package of the same name.
218 n
= 2; /* requirements say start at 2 */
221 (void) strcpy(newinst
, pkgabrv
);
222 while (pkginfo(&info
, newinst
, NULL
, NULL
) == 0) {
223 (void) snprintf(newinst
, sizeof (newinst
),
224 "%s.%d", pkgabrv
, n
++);
230 prompt(struct pkginfo
*info
, int npkgs
)
240 if (maxinst
> npkgs
) {
242 * the user may choose to install a completely new
243 * instance of this package
245 n
= ckyorn(ans
, NULL
, NULL
, MSG_GETINST_HELP1
,
246 MSG_GETINST_PROMPT1
);
250 if (strchr("yY", *ans
) != NULL
) {
255 (void) snprintf(header
, sizeof (header
), MSG_GETINST_HEADER
, pkgabrv
);
256 menup
= allocmenu(header
, CKALPHA
);
258 for (i
= 0; i
< npkgs
; i
++) {
259 (void) snprintf(temp
, sizeof (temp
),
260 "%s %s\n(%s) %s", info
[i
].pkginst
,
261 info
[i
].name
, info
[i
].arch
, info
[i
].version
);
262 if (setitem(menup
, temp
)) {
263 progerr("no memory");
270 if (n
= ckyorn(ans
, NULL
, NULL
, NULL
, MSG_GETINST_PROMPT0
))
272 if (strchr("yY", *ans
) == NULL
)
274 (void) strcpy(newinst
, info
[0].pkginst
);
276 if (n
= ckitem(menup
, &inst
, 1, NULL
, NULL
, MSG_GETINST_HELP2
,
277 MSG_GETINST_PROMPT2
))
279 (void) strcpy(newinst
, inst
);
281 (void) setitem(menup
, 0); /* clear resource usage */
282 free(menup
); /* clear resource usage */