xref: /onnv-gate/usr/src/cmd/svr4pkg/pkgadd/presvr4.c (revision 9781:ccf49524d5dc)
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 2009 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 /*
32*9781SMoriah.Waterland@Sun.COM  * system includes
33*9781SMoriah.Waterland@Sun.COM  */
34*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
35*9781SMoriah.Waterland@Sun.COM #include <signal.h>
36*9781SMoriah.Waterland@Sun.COM #include <string.h>
37*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
38*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
39*9781SMoriah.Waterland@Sun.COM #include <limits.h>
40*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>
41*9781SMoriah.Waterland@Sun.COM #include <sys/utsname.h>
42*9781SMoriah.Waterland@Sun.COM #include <pkginfo.h>
43*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
44*9781SMoriah.Waterland@Sun.COM #include <pkgdev.h>
45*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
46*9781SMoriah.Waterland@Sun.COM #include <locale.h>
47*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
48*9781SMoriah.Waterland@Sun.COM 
49*9781SMoriah.Waterland@Sun.COM /*
50*9781SMoriah.Waterland@Sun.COM  * consolidation pkg command library includes
51*9781SMoriah.Waterland@Sun.COM  */
52*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
53*9781SMoriah.Waterland@Sun.COM #include <messages.h>
54*9781SMoriah.Waterland@Sun.COM 
55*9781SMoriah.Waterland@Sun.COM /*
56*9781SMoriah.Waterland@Sun.COM  * local pkg command library includes
57*9781SMoriah.Waterland@Sun.COM  */
58*9781SMoriah.Waterland@Sun.COM #include <install.h>
59*9781SMoriah.Waterland@Sun.COM #include <libinst.h>
60*9781SMoriah.Waterland@Sun.COM #include <libadm.h>
61*9781SMoriah.Waterland@Sun.COM 
62*9781SMoriah.Waterland@Sun.COM /*
63*9781SMoriah.Waterland@Sun.COM  * pkgadd local includes
64*9781SMoriah.Waterland@Sun.COM  */
65*9781SMoriah.Waterland@Sun.COM #include "quit.h"
66*9781SMoriah.Waterland@Sun.COM 
67*9781SMoriah.Waterland@Sun.COM 
68*9781SMoriah.Waterland@Sun.COM extern struct admin adm;
69*9781SMoriah.Waterland@Sun.COM extern struct pkgdev pkgdev;
70*9781SMoriah.Waterland@Sun.COM extern char	*respfile;
71*9781SMoriah.Waterland@Sun.COM extern char	*tmpdir;
72*9781SMoriah.Waterland@Sun.COM extern int	warnflag;
73*9781SMoriah.Waterland@Sun.COM 
74*9781SMoriah.Waterland@Sun.COM static void	intf_reloc(void);
75*9781SMoriah.Waterland@Sun.COM 
76*9781SMoriah.Waterland@Sun.COM /*
77*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
78*9781SMoriah.Waterland@Sun.COM  * global external (public) functions
79*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
80*9781SMoriah.Waterland@Sun.COM  */
81*9781SMoriah.Waterland@Sun.COM 
82*9781SMoriah.Waterland@Sun.COM int
presvr4(char ** ppkg,int a_nointeract)83*9781SMoriah.Waterland@Sun.COM presvr4(char **ppkg, int a_nointeract)
84*9781SMoriah.Waterland@Sun.COM {
85*9781SMoriah.Waterland@Sun.COM 	int	retcode;
86*9781SMoriah.Waterland@Sun.COM 	char	*tmpcmd, path[PATH_MAX];
87*9781SMoriah.Waterland@Sun.COM 	void	(*tmpfunc)();
88*9781SMoriah.Waterland@Sun.COM 
89*9781SMoriah.Waterland@Sun.COM 	echo(MSG_INSTALLING_PSVR4);
90*9781SMoriah.Waterland@Sun.COM 	if (a_nointeract) {
91*9781SMoriah.Waterland@Sun.COM 		progerr(ERR_NOINT);
92*9781SMoriah.Waterland@Sun.COM 		quit(1);
93*9781SMoriah.Waterland@Sun.COM 		/* NOTREACHED */
94*9781SMoriah.Waterland@Sun.COM 	}
95*9781SMoriah.Waterland@Sun.COM 
96*9781SMoriah.Waterland@Sun.COM 	if (respfile) {
97*9781SMoriah.Waterland@Sun.COM 		progerr(ERR_RESPFILE);
98*9781SMoriah.Waterland@Sun.COM 		quit(1);
99*9781SMoriah.Waterland@Sun.COM 		/* NOTREACHED */
100*9781SMoriah.Waterland@Sun.COM 	}
101*9781SMoriah.Waterland@Sun.COM 
102*9781SMoriah.Waterland@Sun.COM 	/*
103*9781SMoriah.Waterland@Sun.COM 	 * if we were looking for a particular package, verify
104*9781SMoriah.Waterland@Sun.COM 	 * the first media has a /usr/options file on it
105*9781SMoriah.Waterland@Sun.COM 	 * which matches
106*9781SMoriah.Waterland@Sun.COM 	 */
107*9781SMoriah.Waterland@Sun.COM 	psvr4pkg(ppkg);
108*9781SMoriah.Waterland@Sun.COM 
109*9781SMoriah.Waterland@Sun.COM 	/*
110*9781SMoriah.Waterland@Sun.COM 	 * check to see if we can guess (via Rlist) what
111*9781SMoriah.Waterland@Sun.COM 	 * pathnames this package is likely to install;
112*9781SMoriah.Waterland@Sun.COM 	 * if we can, check these against the 'contents'
113*9781SMoriah.Waterland@Sun.COM 	 * file and warn the administrator that these
114*9781SMoriah.Waterland@Sun.COM 	 * pathnames might be modified in some manner
115*9781SMoriah.Waterland@Sun.COM 	 */
116*9781SMoriah.Waterland@Sun.COM 	psvr4cnflct();
117*9781SMoriah.Waterland@Sun.COM 
118*9781SMoriah.Waterland@Sun.COM 	if (chdir(tmpdir)) {
119*9781SMoriah.Waterland@Sun.COM 		progerr(ERR_CHDIR, tmpdir);
120*9781SMoriah.Waterland@Sun.COM 		quit(99);
121*9781SMoriah.Waterland@Sun.COM 		/* NOTREACHED */
122*9781SMoriah.Waterland@Sun.COM 	}
123*9781SMoriah.Waterland@Sun.COM 
124*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(path, sizeof (path), "%s/install/INSTALL",
125*9781SMoriah.Waterland@Sun.COM 			pkgdev.dirname);
126*9781SMoriah.Waterland@Sun.COM 
127*9781SMoriah.Waterland@Sun.COM 	tmpcmd = tempnam(tmpdir, "INSTALL");
128*9781SMoriah.Waterland@Sun.COM 	if (!tmpcmd || copyf(path, tmpcmd, 0L) || chmod(tmpcmd, 0500)) {
129*9781SMoriah.Waterland@Sun.COM 		progerr(ERR_NOCOPY, tmpdir);
130*9781SMoriah.Waterland@Sun.COM 		quit(99);
131*9781SMoriah.Waterland@Sun.COM 		/* NOTREACHED */
132*9781SMoriah.Waterland@Sun.COM 	}
133*9781SMoriah.Waterland@Sun.COM 
134*9781SMoriah.Waterland@Sun.COM 	echo(MSG_EXE_INSTALL_SCRIPT);
135*9781SMoriah.Waterland@Sun.COM 
136*9781SMoriah.Waterland@Sun.COM 	retcode = pkgexecl(NULL, NULL, NULL, NULL, SHELL, "-c", tmpcmd,
137*9781SMoriah.Waterland@Sun.COM 	    pkgdev.bdevice, pkgdev.dirname, NULL);
138*9781SMoriah.Waterland@Sun.COM 
139*9781SMoriah.Waterland@Sun.COM 	echo(retcode ? MSG_FAIL : gettext(MSG_SUCCEED));
140*9781SMoriah.Waterland@Sun.COM 
141*9781SMoriah.Waterland@Sun.COM 	(void) unlink(tmpcmd);
142*9781SMoriah.Waterland@Sun.COM 	(void) chdir("/");
143*9781SMoriah.Waterland@Sun.COM 	(void) pkgumount(&pkgdev);
144*9781SMoriah.Waterland@Sun.COM 
145*9781SMoriah.Waterland@Sun.COM 	psvr4mail(adm.mail, MSG_MAIL, retcode, *ppkg ? *ppkg : MSG_NODENAME);
146*9781SMoriah.Waterland@Sun.COM 
147*9781SMoriah.Waterland@Sun.COM 	/* tell quit to call intf_reloc on exit */
148*9781SMoriah.Waterland@Sun.COM 
149*9781SMoriah.Waterland@Sun.COM 	quitSetIntfReloc(&intf_reloc);
150*9781SMoriah.Waterland@Sun.COM 
151*9781SMoriah.Waterland@Sun.COM 	return (retcode);
152*9781SMoriah.Waterland@Sun.COM }
153*9781SMoriah.Waterland@Sun.COM 
154*9781SMoriah.Waterland@Sun.COM /*
155*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
156*9781SMoriah.Waterland@Sun.COM  * static internal (private) functions
157*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
158*9781SMoriah.Waterland@Sun.COM  */
159*9781SMoriah.Waterland@Sun.COM 
160*9781SMoriah.Waterland@Sun.COM /*
161*9781SMoriah.Waterland@Sun.COM  * When quit() gains control this function will be invoked if quitSetIntfReloc()
162*9781SMoriah.Waterland@Sun.COM  * is called specifying this function - see presvr4() above for details.
163*9781SMoriah.Waterland@Sun.COM  */
164*9781SMoriah.Waterland@Sun.COM 
165*9781SMoriah.Waterland@Sun.COM static void
intf_reloc(void)166*9781SMoriah.Waterland@Sun.COM intf_reloc(void)
167*9781SMoriah.Waterland@Sun.COM {
168*9781SMoriah.Waterland@Sun.COM 	char	path[PATH_MAX];
169*9781SMoriah.Waterland@Sun.COM 
170*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(path, sizeof (path), "%s/intf_reloc", PKGBIN);
171*9781SMoriah.Waterland@Sun.COM 	(void) pkgexecl(NULL, NULL, NULL, NULL, SHELL, "-c", path, NULL);
172*9781SMoriah.Waterland@Sun.COM }
173