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 1995 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
28*9781SMoriah.Waterland@Sun.COM
29*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
30*9781SMoriah.Waterland@Sun.COM #include <errno.h>
31*9781SMoriah.Waterland@Sun.COM #include <string.h>
32*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
33*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
34*9781SMoriah.Waterland@Sun.COM #include <locale.h>
35*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
36*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
37*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
38*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
39*9781SMoriah.Waterland@Sun.COM
40*9781SMoriah.Waterland@Sun.COM #define ERR_INVALID_CAS "%d is an invalid class action script type."
41*9781SMoriah.Waterland@Sun.COM #define ERR_NO_NONE "Cannot find the default archive install script."
42*9781SMoriah.Waterland@Sun.COM #define ERR_NO_PATH "No paths for finding class action scripts."
43*9781SMoriah.Waterland@Sun.COM
44*9781SMoriah.Waterland@Sun.COM /* setlist.c */
45*9781SMoriah.Waterland@Sun.COM extern struct cl_attr **cl_Classes;
46*9781SMoriah.Waterland@Sun.COM extern int cl_NClasses;
47*9781SMoriah.Waterland@Sun.COM extern char *cl_nam(int idx);
48*9781SMoriah.Waterland@Sun.COM
49*9781SMoriah.Waterland@Sun.COM static int pkg_has_arch;
50*9781SMoriah.Waterland@Sun.COM
51*9781SMoriah.Waterland@Sun.COM /* Return the install class action script associated with this class index */
52*9781SMoriah.Waterland@Sun.COM char *
cl_iscript(int idx)53*9781SMoriah.Waterland@Sun.COM cl_iscript(int idx)
54*9781SMoriah.Waterland@Sun.COM {
55*9781SMoriah.Waterland@Sun.COM if (cl_Classes && idx >= 0 && idx < cl_NClasses)
56*9781SMoriah.Waterland@Sun.COM return (cl_Classes[idx]->inst_script);
57*9781SMoriah.Waterland@Sun.COM return (NULL);
58*9781SMoriah.Waterland@Sun.COM }
59*9781SMoriah.Waterland@Sun.COM
60*9781SMoriah.Waterland@Sun.COM /*
61*9781SMoriah.Waterland@Sun.COM * This resets an input class action script pointer and the various
62*9781SMoriah.Waterland@Sun.COM * codes that are associated with special treatment available to a class
63*9781SMoriah.Waterland@Sun.COM * action script. It returns 1 if there was a script there in the first
64*9781SMoriah.Waterland@Sun.COM * place and 0 if there wasn't.
65*9781SMoriah.Waterland@Sun.COM */
66*9781SMoriah.Waterland@Sun.COM int
cl_deliscript(int idx)67*9781SMoriah.Waterland@Sun.COM cl_deliscript(int idx)
68*9781SMoriah.Waterland@Sun.COM {
69*9781SMoriah.Waterland@Sun.COM if (cl_Classes && idx >= 0 && idx < cl_NClasses)
70*9781SMoriah.Waterland@Sun.COM if (cl_Classes[idx]->inst_script) {
71*9781SMoriah.Waterland@Sun.COM free(cl_Classes[idx]->inst_script);
72*9781SMoriah.Waterland@Sun.COM cl_Classes[idx]->inst_script = NULL;
73*9781SMoriah.Waterland@Sun.COM cl_Classes[idx]->src_verify = DEFAULT;
74*9781SMoriah.Waterland@Sun.COM cl_Classes[idx]->dst_verify = DEFAULT;
75*9781SMoriah.Waterland@Sun.COM cl_Classes[idx]->relpath_2_CAS = DEFAULT;
76*9781SMoriah.Waterland@Sun.COM
77*9781SMoriah.Waterland@Sun.COM } else
78*9781SMoriah.Waterland@Sun.COM return (0);
79*9781SMoriah.Waterland@Sun.COM return (1);
80*9781SMoriah.Waterland@Sun.COM }
81*9781SMoriah.Waterland@Sun.COM
82*9781SMoriah.Waterland@Sun.COM /* Return the remove class action script associated with this class index */
83*9781SMoriah.Waterland@Sun.COM char *
cl_rscript(int idx)84*9781SMoriah.Waterland@Sun.COM cl_rscript(int idx)
85*9781SMoriah.Waterland@Sun.COM {
86*9781SMoriah.Waterland@Sun.COM if (cl_Classes && idx >= 0 && idx < cl_NClasses)
87*9781SMoriah.Waterland@Sun.COM return (cl_Classes[idx]->rem_script);
88*9781SMoriah.Waterland@Sun.COM return (NULL);
89*9781SMoriah.Waterland@Sun.COM }
90*9781SMoriah.Waterland@Sun.COM
91*9781SMoriah.Waterland@Sun.COM /*
92*9781SMoriah.Waterland@Sun.COM * This scans the admin directories for the class acton scripts associated
93*9781SMoriah.Waterland@Sun.COM * with the classes to be installed. It will look for install or remove
94*9781SMoriah.Waterland@Sun.COM * scripts and place appropriate pointers into the cl_Classes list. There's
95*9781SMoriah.Waterland@Sun.COM * no reason why it couldn't look for both except that I haven't seen a
96*9781SMoriah.Waterland@Sun.COM * need for it yet.
97*9781SMoriah.Waterland@Sun.COM */
98*9781SMoriah.Waterland@Sun.COM void
find_CAS(int CAS_type,char * pkgbin,char * instdir)99*9781SMoriah.Waterland@Sun.COM find_CAS(int CAS_type, char *pkgbin, char *instdir)
100*9781SMoriah.Waterland@Sun.COM {
101*9781SMoriah.Waterland@Sun.COM int i;
102*9781SMoriah.Waterland@Sun.COM char path[PATH_MAX];
103*9781SMoriah.Waterland@Sun.COM
104*9781SMoriah.Waterland@Sun.COM if (instdir == NULL || pkgbin == NULL) {
105*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NO_PATH));
106*9781SMoriah.Waterland@Sun.COM quit(99);
107*9781SMoriah.Waterland@Sun.COM }
108*9781SMoriah.Waterland@Sun.COM
109*9781SMoriah.Waterland@Sun.COM if (CAS_type == I_ONLY) {
110*9781SMoriah.Waterland@Sun.COM for (i = 0; i < cl_NClasses; i++) {
111*9781SMoriah.Waterland@Sun.COM /*
112*9781SMoriah.Waterland@Sun.COM * Locate appropriate installation class action
113*9781SMoriah.Waterland@Sun.COM * script, if any; look on media for script,
114*9781SMoriah.Waterland@Sun.COM * since it might be on the system due to a
115*9781SMoriah.Waterland@Sun.COM * previous installation.
116*9781SMoriah.Waterland@Sun.COM */
117*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/install/i.%s", instdir,
118*9781SMoriah.Waterland@Sun.COM cl_nam(i));
119*9781SMoriah.Waterland@Sun.COM if (access(path, R_OK) == 0) {
120*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/i.%s", pkgbin,
121*9781SMoriah.Waterland@Sun.COM cl_nam(i));
122*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->inst_script = qstrdup(path);
123*9781SMoriah.Waterland@Sun.COM continue;
124*9781SMoriah.Waterland@Sun.COM }
125*9781SMoriah.Waterland@Sun.COM
126*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/i.%s", PKGSCR, cl_nam(i));
127*9781SMoriah.Waterland@Sun.COM if (access(path, R_OK) == 0) {
128*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->inst_script = qstrdup(path);
129*9781SMoriah.Waterland@Sun.COM continue;
130*9781SMoriah.Waterland@Sun.COM }
131*9781SMoriah.Waterland@Sun.COM
132*9781SMoriah.Waterland@Sun.COM /*
133*9781SMoriah.Waterland@Sun.COM * Provide CAS to uncompress and distribute a
134*9781SMoriah.Waterland@Sun.COM * compressed cpio archive for those older packages
135*9781SMoriah.Waterland@Sun.COM * that don't include their own. This is the first
136*9781SMoriah.Waterland@Sun.COM * point at which we know, it's an old package
137*9781SMoriah.Waterland@Sun.COM * without all the various pkginfo items set.
138*9781SMoriah.Waterland@Sun.COM * The default script is provided for all classes
139*9781SMoriah.Waterland@Sun.COM * in an old package which do not have their own
140*9781SMoriah.Waterland@Sun.COM * class action script. These are the criteria used
141*9781SMoriah.Waterland@Sun.COM * by the script that packs the archives.
142*9781SMoriah.Waterland@Sun.COM */
143*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/%s", PKGSCR, DEF_NONE_SCR);
144*9781SMoriah.Waterland@Sun.COM if (pkg_has_arch &&
145*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->inst_script == NULL) {
146*9781SMoriah.Waterland@Sun.COM
147*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->src_verify = NOVERIFY;
148*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->dst_verify = QKVERIFY;
149*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->relpath_2_CAS = REL_2_CAS;
150*9781SMoriah.Waterland@Sun.COM
151*9781SMoriah.Waterland@Sun.COM if (access(path, R_OK) == 0) {
152*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->inst_script =
153*9781SMoriah.Waterland@Sun.COM qstrdup(path);
154*9781SMoriah.Waterland@Sun.COM continue;
155*9781SMoriah.Waterland@Sun.COM } else {
156*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NO_NONE));
157*9781SMoriah.Waterland@Sun.COM quit(99);
158*9781SMoriah.Waterland@Sun.COM }
159*9781SMoriah.Waterland@Sun.COM
160*9781SMoriah.Waterland@Sun.COM }
161*9781SMoriah.Waterland@Sun.COM }
162*9781SMoriah.Waterland@Sun.COM } else if (CAS_type == R_ONLY) {
163*9781SMoriah.Waterland@Sun.COM for (i = 0; i < cl_NClasses; i++) {
164*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/install/r.%s", instdir,
165*9781SMoriah.Waterland@Sun.COM cl_nam(i));
166*9781SMoriah.Waterland@Sun.COM if (access(path, R_OK) == 0) {
167*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/r.%s", pkgbin,
168*9781SMoriah.Waterland@Sun.COM cl_nam(i));
169*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->rem_script = qstrdup(path);
170*9781SMoriah.Waterland@Sun.COM continue;
171*9781SMoriah.Waterland@Sun.COM }
172*9781SMoriah.Waterland@Sun.COM
173*9781SMoriah.Waterland@Sun.COM (void) sprintf(path, "%s/r.%s", PKGSCR, cl_nam(i));
174*9781SMoriah.Waterland@Sun.COM if (access(path, R_OK) == 0) {
175*9781SMoriah.Waterland@Sun.COM cl_Classes[i]->rem_script = qstrdup(path);
176*9781SMoriah.Waterland@Sun.COM continue;
177*9781SMoriah.Waterland@Sun.COM }
178*9781SMoriah.Waterland@Sun.COM }
179*9781SMoriah.Waterland@Sun.COM } else {
180*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_INVALID_CAS), CAS_type);
181*9781SMoriah.Waterland@Sun.COM quit(99);
182*9781SMoriah.Waterland@Sun.COM }
183*9781SMoriah.Waterland@Sun.COM }
184*9781SMoriah.Waterland@Sun.COM
185*9781SMoriah.Waterland@Sun.COM /*
186*9781SMoriah.Waterland@Sun.COM * This function deals with the special case of an old WOS package
187*9781SMoriah.Waterland@Sun.COM * with a compressed cpio'd file set but no class action script.
188*9781SMoriah.Waterland@Sun.COM * We find out it doesn't have a CAS later in find_CAS() and deal
189*9781SMoriah.Waterland@Sun.COM * with it then. The only reason for this variable is to let
190*9781SMoriah.Waterland@Sun.COM * findscripts() know to get the default script if it can't find it in
191*9781SMoriah.Waterland@Sun.COM * the usual places.
192*9781SMoriah.Waterland@Sun.COM */
193*9781SMoriah.Waterland@Sun.COM void
is_WOS_arch(void)194*9781SMoriah.Waterland@Sun.COM is_WOS_arch(void)
195*9781SMoriah.Waterland@Sun.COM {
196*9781SMoriah.Waterland@Sun.COM pkg_has_arch++;
197*9781SMoriah.Waterland@Sun.COM }
198