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