xref: /onnv-gate/usr/src/cmd/svr4pkg/pkgrm/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 2004 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 #include <stdio.h>
32*9781SMoriah.Waterland@Sun.COM #include <signal.h>
33*9781SMoriah.Waterland@Sun.COM #include <limits.h>
34*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
35*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
36*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>	/* chmod()? definition */
37*9781SMoriah.Waterland@Sun.COM #include <valtools.h>
38*9781SMoriah.Waterland@Sun.COM #include <locale.h>
39*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
40*9781SMoriah.Waterland@Sun.COM #include <pkgdev.h>
41*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
42*9781SMoriah.Waterland@Sun.COM #include "install.h"
43*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
44*9781SMoriah.Waterland@Sun.COM #include "libadm.h"
45*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
46*9781SMoriah.Waterland@Sun.COM 
47*9781SMoriah.Waterland@Sun.COM /*
48*9781SMoriah.Waterland@Sun.COM  * pkgadd local includes
49*9781SMoriah.Waterland@Sun.COM  */
50*9781SMoriah.Waterland@Sun.COM 
51*9781SMoriah.Waterland@Sun.COM #include "quit.h"
52*9781SMoriah.Waterland@Sun.COM 
53*9781SMoriah.Waterland@Sun.COM extern struct	admin adm;
54*9781SMoriah.Waterland@Sun.COM extern struct	pkgdev pkgdev;
55*9781SMoriah.Waterland@Sun.COM extern char	*tmpdir;
56*9781SMoriah.Waterland@Sun.COM extern int	started;
57*9781SMoriah.Waterland@Sun.COM 
58*9781SMoriah.Waterland@Sun.COM static void	intf_reloc(void);
59*9781SMoriah.Waterland@Sun.COM 
60*9781SMoriah.Waterland@Sun.COM #define	PATH_FLAGS	P_EXIST|P_ABSOLUTE|P_BLK
61*9781SMoriah.Waterland@Sun.COM 
62*9781SMoriah.Waterland@Sun.COM #define	MSG_DEVICE	"Removal of a pre-SVR4 package requires the original " \
63*9781SMoriah.Waterland@Sun.COM 			"medium from which the package was installed."
64*9781SMoriah.Waterland@Sun.COM 
65*9781SMoriah.Waterland@Sun.COM #define	ASK_DEVICE	"Enter the alias or pathname for the device to be " \
66*9781SMoriah.Waterland@Sun.COM 			"used (e.g., diskette1 or /dev/diskette)"
67*9781SMoriah.Waterland@Sun.COM 
68*9781SMoriah.Waterland@Sun.COM #define	ASK_INSERT	 "Insert the first volume for package <%s> into %s"
69*9781SMoriah.Waterland@Sun.COM 
70*9781SMoriah.Waterland@Sun.COM #define	ERR_NOCOPY	 "unable to create copy of UNINSTALL script in <%s>"
71*9781SMoriah.Waterland@Sun.COM 
72*9781SMoriah.Waterland@Sun.COM #define	ERR_NOINT	"-n option cannot be used when removing pre-SVR4 " \
73*9781SMoriah.Waterland@Sun.COM 			"packages"
74*9781SMoriah.Waterland@Sun.COM 
75*9781SMoriah.Waterland@Sun.COM #define	ERR_BADDEV	"Unknown or bad device <%s> specified"
76*9781SMoriah.Waterland@Sun.COM 
77*9781SMoriah.Waterland@Sun.COM #define	MSG_MAIL	"An attempt to remove the <%s> pre-SVR4 package on " \
78*9781SMoriah.Waterland@Sun.COM 			"<%s> completed with exit status <%d>."
79*9781SMoriah.Waterland@Sun.COM 
80*9781SMoriah.Waterland@Sun.COM #define	INFO_P4RMOK	"\nPre-SVR4 package reported successful removal.\n"
81*9781SMoriah.Waterland@Sun.COM 
82*9781SMoriah.Waterland@Sun.COM int
presvr4(char * pkg,int a_nointeract)83*9781SMoriah.Waterland@Sun.COM presvr4(char *pkg, int a_nointeract)
84*9781SMoriah.Waterland@Sun.COM {
85*9781SMoriah.Waterland@Sun.COM 	char	alias[PATH_MAX];
86*9781SMoriah.Waterland@Sun.COM 	char	path[PATH_MAX];
87*9781SMoriah.Waterland@Sun.COM 	char	*tmpcmd;
88*9781SMoriah.Waterland@Sun.COM 	int	n, retcode;
89*9781SMoriah.Waterland@Sun.COM 	void	(*tmpfunc)();
90*9781SMoriah.Waterland@Sun.COM 
91*9781SMoriah.Waterland@Sun.COM 	echo(gettext("*** Removing Pre-SVR4 Package ***"));
92*9781SMoriah.Waterland@Sun.COM 	if (a_nointeract != 0) {
93*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOINT));
94*9781SMoriah.Waterland@Sun.COM 		quit(1);
95*9781SMoriah.Waterland@Sun.COM 	}
96*9781SMoriah.Waterland@Sun.COM 
97*9781SMoriah.Waterland@Sun.COM 	/* should accept device alias?? */
98*9781SMoriah.Waterland@Sun.COM 
99*9781SMoriah.Waterland@Sun.COM 	echo(gettext(MSG_DEVICE));
100*9781SMoriah.Waterland@Sun.COM 	for (;;) {
101*9781SMoriah.Waterland@Sun.COM 		if (n = ckstr(alias, NULL, PATH_MAX, NULL, NULL, NULL,
102*9781SMoriah.Waterland@Sun.COM 		    gettext(ASK_DEVICE)))
103*9781SMoriah.Waterland@Sun.COM 			return (n);
104*9781SMoriah.Waterland@Sun.COM 
105*9781SMoriah.Waterland@Sun.COM 		if (devtype(alias, &pkgdev))
106*9781SMoriah.Waterland@Sun.COM 			continue;
107*9781SMoriah.Waterland@Sun.COM 		if (!pkgdev.mount || !pkgdev.bdevice) {
108*9781SMoriah.Waterland@Sun.COM 			logerr(gettext(ERR_BADDEV), alias);
109*9781SMoriah.Waterland@Sun.COM 			continue;
110*9781SMoriah.Waterland@Sun.COM 		}
111*9781SMoriah.Waterland@Sun.COM 		break;
112*9781SMoriah.Waterland@Sun.COM 	}
113*9781SMoriah.Waterland@Sun.COM 	pkgdev.mount = pkgdev.dirname = "/install";
114*9781SMoriah.Waterland@Sun.COM 	pkgdev.rdonly = 1;
115*9781SMoriah.Waterland@Sun.COM 
116*9781SMoriah.Waterland@Sun.COM 	if (n = pkgmount(&pkgdev, pkg, 1, 0, 1))
117*9781SMoriah.Waterland@Sun.COM 		quit(n);
118*9781SMoriah.Waterland@Sun.COM 
119*9781SMoriah.Waterland@Sun.COM 	psvr4pkg(&pkg);
120*9781SMoriah.Waterland@Sun.COM 
121*9781SMoriah.Waterland@Sun.COM 	/*
122*9781SMoriah.Waterland@Sun.COM 	 * check to see if we can guess (via Rlist) what
123*9781SMoriah.Waterland@Sun.COM 	 * pathnames this package is likely to remove;
124*9781SMoriah.Waterland@Sun.COM 	 * if we can, check these against the 'contents'
125*9781SMoriah.Waterland@Sun.COM 	 * file and warn the administrator that these
126*9781SMoriah.Waterland@Sun.COM 	 * pathnames might be modified in some manner
127*9781SMoriah.Waterland@Sun.COM 	 */
128*9781SMoriah.Waterland@Sun.COM 	psvr4cnflct();
129*9781SMoriah.Waterland@Sun.COM 
130*9781SMoriah.Waterland@Sun.COM 	if (chdir(tmpdir)) {
131*9781SMoriah.Waterland@Sun.COM 		progerr(gettext("unable to change directory to <%s>"), tmpdir);
132*9781SMoriah.Waterland@Sun.COM 		quit(99);
133*9781SMoriah.Waterland@Sun.COM 	}
134*9781SMoriah.Waterland@Sun.COM 
135*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(path, sizeof (path), "%s/install/UNINSTALL",
136*9781SMoriah.Waterland@Sun.COM 			"/install");
137*9781SMoriah.Waterland@Sun.COM 	tmpcmd = tempnam(tmpdir, "UNINSTALL");
138*9781SMoriah.Waterland@Sun.COM 	if (!tmpcmd || copyf(path, tmpcmd, 0) || chmod(tmpcmd, 0500)) {
139*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOCOPY), tmpdir);
140*9781SMoriah.Waterland@Sun.COM 		quit(99);
141*9781SMoriah.Waterland@Sun.COM 	}
142*9781SMoriah.Waterland@Sun.COM 
143*9781SMoriah.Waterland@Sun.COM 	started++;
144*9781SMoriah.Waterland@Sun.COM 
145*9781SMoriah.Waterland@Sun.COM 	echo(gettext("## Executing package UNINSTALL script"));
146*9781SMoriah.Waterland@Sun.COM 
147*9781SMoriah.Waterland@Sun.COM 	retcode = pkgexecl(NULL, NULL, NULL, NULL, SHELL, "-c", tmpcmd, NULL);
148*9781SMoriah.Waterland@Sun.COM 
149*9781SMoriah.Waterland@Sun.COM 	(void) unlink(tmpcmd);
150*9781SMoriah.Waterland@Sun.COM 	if (retcode) {
151*9781SMoriah.Waterland@Sun.COM 		echo(gettext("\nPre-SVR4 package reported failed removal.\n"));
152*9781SMoriah.Waterland@Sun.COM 	} else {
153*9781SMoriah.Waterland@Sun.COM 		echo(gettext(INFO_P4RMOK));
154*9781SMoriah.Waterland@Sun.COM 	}
155*9781SMoriah.Waterland@Sun.COM 
156*9781SMoriah.Waterland@Sun.COM 	psvr4mail(adm.mail, gettext(MSG_MAIL), retcode, pkg);
157*9781SMoriah.Waterland@Sun.COM 	(void) pkgumount(&pkgdev);
158*9781SMoriah.Waterland@Sun.COM 
159*9781SMoriah.Waterland@Sun.COM 	/* tell quit to call intf_reloc on exit */
160*9781SMoriah.Waterland@Sun.COM 
161*9781SMoriah.Waterland@Sun.COM 	quitSetIntfReloc(&intf_reloc);
162*9781SMoriah.Waterland@Sun.COM 
163*9781SMoriah.Waterland@Sun.COM 	return (retcode);
164*9781SMoriah.Waterland@Sun.COM }
165*9781SMoriah.Waterland@Sun.COM 
166*9781SMoriah.Waterland@Sun.COM /*
167*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
168*9781SMoriah.Waterland@Sun.COM  * static internal (private) functions
169*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
170*9781SMoriah.Waterland@Sun.COM  */
171*9781SMoriah.Waterland@Sun.COM 
172*9781SMoriah.Waterland@Sun.COM /*
173*9781SMoriah.Waterland@Sun.COM  * When quit() gains control this function will be invoked if quitSetIntfReloc()
174*9781SMoriah.Waterland@Sun.COM  * is called specifying this function - see presvr4() above for details.
175*9781SMoriah.Waterland@Sun.COM  */
176*9781SMoriah.Waterland@Sun.COM 
177*9781SMoriah.Waterland@Sun.COM static void
intf_reloc(void)178*9781SMoriah.Waterland@Sun.COM intf_reloc(void)
179*9781SMoriah.Waterland@Sun.COM {
180*9781SMoriah.Waterland@Sun.COM 	char	path[PATH_MAX];
181*9781SMoriah.Waterland@Sun.COM 
182*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(path, sizeof (path), "%s/intf_reloc", PKGBIN);
183*9781SMoriah.Waterland@Sun.COM 	(void) pkgexecl(NULL, NULL, NULL, NULL, SHELL, "-c", path, NULL);
184*9781SMoriah.Waterland@Sun.COM }
185