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