summaryrefslogtreecommitdiff
path: root/usr/src/cmd/svr4pkg/libinst/findscripts.c
blob: 767e3d81c527682bbd9aa0bcca05b64bcc0a80ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 1995 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */



#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <libintl.h>
#include <pkglocs.h>
#include <pkglib.h>
#include "libinst.h"

#define	ERR_INVALID_CAS	"%d is an invalid class action script type."
#define	ERR_NO_NONE	"Cannot find the default archive install script."
#define	ERR_NO_PATH	"No paths for finding class action scripts."

/* setlist.c */
extern struct cl_attr **cl_Classes;
extern int cl_NClasses;
extern char *cl_nam(int idx);

static int pkg_has_arch;

/* Return the install class action script associated with this class index */
char *
cl_iscript(int idx)
{
	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
		return (cl_Classes[idx]->inst_script);
	return (NULL);
}

/*
 * This resets an input class action script pointer and the various
 * codes that are associated with special treatment available to a class
 * action script. It returns 1 if there was a script there in the first
 * place and 0 if there wasn't.
 */
int
cl_deliscript(int idx)
{
	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
		if (cl_Classes[idx]->inst_script) {
			free(cl_Classes[idx]->inst_script);
			cl_Classes[idx]->inst_script = NULL;
			cl_Classes[idx]->src_verify = DEFAULT;
			cl_Classes[idx]->dst_verify = DEFAULT;
			cl_Classes[idx]->relpath_2_CAS = DEFAULT;

		} else
			return (0);
	return (1);
}

/* Return the remove class action script associated with this class index */
char *
cl_rscript(int idx)
{
	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
		return (cl_Classes[idx]->rem_script);
	return (NULL);
}

/*
 * This scans the admin directories for the class acton scripts associated
 * with the classes to be installed. It will look for install or remove
 * scripts and place appropriate pointers into the cl_Classes list. There's
 * no reason why it couldn't look for both except that I haven't seen a
 * need for it yet.
 */
void
find_CAS(int CAS_type, char *pkgbin, char *instdir)
{
	int i;
	char path[PATH_MAX];

	if (instdir == NULL || pkgbin == NULL) {
		progerr(gettext(ERR_NO_PATH));
		quit(99);
	}

	if (CAS_type == I_ONLY) {
		for (i = 0; i < cl_NClasses; i++) {
			/*
			 * Locate appropriate installation class action
			 * script, if any; look on media for script,
			 * since it might be on the system due to a
			 * previous installation.
			 */
			(void) sprintf(path, "%s/install/i.%s", instdir,
			    cl_nam(i));
			if (access(path, R_OK) == 0) {
				(void) sprintf(path, "%s/i.%s", pkgbin,
				    cl_nam(i));
				cl_Classes[i]->inst_script = qstrdup(path);
				continue;
			}

			(void) sprintf(path, "%s/i.%s", PKGSCR, cl_nam(i));
			if (access(path, R_OK) == 0) {
				cl_Classes[i]->inst_script = qstrdup(path);
				continue;
			}

			/*
			 * Provide CAS to uncompress and distribute a
			 * compressed cpio archive for those older packages
			 * that don't include their own. This is the first
			 * point at which we know, it's an old package
			 * without all the various pkginfo items set.
			 * The default script is provided for all classes
			 * in an old package which do not have their own
			 * class action script. These are the criteria used
			 * by the script that packs the archives.
			 */
			(void) sprintf(path, "%s/%s", PKGSCR, DEF_NONE_SCR);
			if (pkg_has_arch &&
			    cl_Classes[i]->inst_script == NULL) {

				cl_Classes[i]->src_verify = NOVERIFY;
				cl_Classes[i]->dst_verify = QKVERIFY;
				cl_Classes[i]->relpath_2_CAS = REL_2_CAS;

				if (access(path, R_OK) == 0) {
					cl_Classes[i]->inst_script =
					    qstrdup(path);
					continue;
				} else {
					progerr(gettext(ERR_NO_NONE));
					quit(99);
				}

			}
		}
	} else if (CAS_type == R_ONLY) {
		for (i = 0; i < cl_NClasses; i++) {
			(void) sprintf(path, "%s/install/r.%s", instdir,
			    cl_nam(i));
			if (access(path, R_OK) == 0) {
				(void) sprintf(path, "%s/r.%s", pkgbin,
				    cl_nam(i));
				cl_Classes[i]->rem_script = qstrdup(path);
				continue;
			}

			(void) sprintf(path, "%s/r.%s", PKGSCR, cl_nam(i));
			if (access(path, R_OK) == 0) {
				cl_Classes[i]->rem_script = qstrdup(path);
				continue;
			}
		}
	} else {
		progerr(gettext(ERR_INVALID_CAS), CAS_type);
		quit(99);
	}
}

/*
 * This function deals with the special case of an old WOS package
 * with a compressed cpio'd file set but no class action script.
 * We find out it doesn't have a CAS later in find_CAS() and deal
 * with it then. The only reason for this variable is to let
 * findscripts() know to get the default script if it can't find it in
 * the usual places.
 */
void
is_WOS_arch(void)
{
	pkg_has_arch++;
}