xref: /illumos-gate/usr/src/cmd/svr4pkg/pkgtrans/main.c (revision 2e10def1)
15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland  * CDDL HEADER START
35c51f124SMoriah Waterland  *
45c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland  *
85c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland  * See the License for the specific language governing permissions
115c51f124SMoriah Waterland  * and limitations under the License.
125c51f124SMoriah Waterland  *
135c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland  *
195c51f124SMoriah Waterland  * CDDL HEADER END
205c51f124SMoriah Waterland  */
215c51f124SMoriah Waterland 
2232991bedSPeter Tribble /*
2332991bedSPeter Tribble  * Copyright (c) 2017 Peter Tribble.
2432991bedSPeter Tribble  */
2532991bedSPeter Tribble 
265c51f124SMoriah Waterland /*
275c51f124SMoriah Waterland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
285c51f124SMoriah Waterland  * Use is subject to license terms.
295c51f124SMoriah Waterland  */
305c51f124SMoriah Waterland 
315c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
325c51f124SMoriah Waterland /* All Rights Reserved */
335c51f124SMoriah Waterland 
34382f00c9SGarrett D'Amore /*
35382f00c9SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
36382f00c9SGarrett D'Amore  */
375c51f124SMoriah Waterland 
385c51f124SMoriah Waterland #include <locale.h>
395c51f124SMoriah Waterland #include <libintl.h>
405c51f124SMoriah Waterland #include <stdio.h>
415c51f124SMoriah Waterland #include <signal.h>
425c51f124SMoriah Waterland #include <stdlib.h>
435c51f124SMoriah Waterland #include <unistd.h>
445c51f124SMoriah Waterland #include <string.h>
455c51f124SMoriah Waterland #include <pkgtrans.h>
465c51f124SMoriah Waterland #include <pkglib.h>
475c51f124SMoriah Waterland #include <pkglocs.h>
485c51f124SMoriah Waterland #include <libadm.h>
495c51f124SMoriah Waterland #include <libinst.h>
50382f00c9SGarrett D'Amore #include <messages.h>
515c51f124SMoriah Waterland 
525c51f124SMoriah Waterland static int	options;
535c51f124SMoriah Waterland 
545c51f124SMoriah Waterland static void	usage(void);
555c51f124SMoriah Waterland static void	trap(int signo);
565c51f124SMoriah Waterland 
575c51f124SMoriah Waterland int
main(int argc,char * argv[])585c51f124SMoriah Waterland main(int argc, char *argv[])
595c51f124SMoriah Waterland {
605c51f124SMoriah Waterland 	int	c;
615c51f124SMoriah Waterland 	void	(*func)();
625c51f124SMoriah Waterland 	extern int	optind;
63*2e10def1SPeter Tribble 	int		ret;
645c51f124SMoriah Waterland 
655c51f124SMoriah Waterland 	(void) setlocale(LC_ALL, "");
665c51f124SMoriah Waterland 
675c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
685c51f124SMoriah Waterland #define	TEXT_DOMAIN "SYS_TEST"
695c51f124SMoriah Waterland #endif
705c51f124SMoriah Waterland 	(void) textdomain(TEXT_DOMAIN);
715c51f124SMoriah Waterland 
725c51f124SMoriah Waterland 	(void) set_prog_name(argv[0]);
735c51f124SMoriah Waterland 
7432991bedSPeter Tribble 	while ((c = getopt(argc, argv, "snio?")) != EOF) {
755c51f124SMoriah Waterland 		switch (c) {
765c51f124SMoriah Waterland 		case 'n':
775c51f124SMoriah Waterland 			options |= PT_RENAME;
785c51f124SMoriah Waterland 			break;
795c51f124SMoriah Waterland 
805c51f124SMoriah Waterland 		case 'i':
815c51f124SMoriah Waterland 			options |= PT_INFO_ONLY;
825c51f124SMoriah Waterland 			break;
835c51f124SMoriah Waterland 
845c51f124SMoriah Waterland 		case 'o':
855c51f124SMoriah Waterland 			options |= PT_OVERWRITE;
865c51f124SMoriah Waterland 			break;
875c51f124SMoriah Waterland 
885c51f124SMoriah Waterland 		case 's':
895c51f124SMoriah Waterland 			options |= PT_ODTSTREAM;
905c51f124SMoriah Waterland 			break;
915c51f124SMoriah Waterland 
925c51f124SMoriah Waterland 		default:
935c51f124SMoriah Waterland 			usage();
945c51f124SMoriah Waterland 			return (1);
955c51f124SMoriah Waterland 		}
965c51f124SMoriah Waterland 	}
975c51f124SMoriah Waterland 	func = signal(SIGINT, trap);
985c51f124SMoriah Waterland 	if (func != SIG_DFL)
995c51f124SMoriah Waterland 		(void) signal(SIGINT, func);
1005c51f124SMoriah Waterland 	(void) signal(SIGHUP, trap);
1015c51f124SMoriah Waterland 	(void) signal(SIGQUIT, trap);
1025c51f124SMoriah Waterland 	(void) signal(SIGTERM, trap);
1035c51f124SMoriah Waterland 	(void) signal(SIGPIPE, trap);
1045c51f124SMoriah Waterland 	(void) signal(SIGPWR, trap);
1055c51f124SMoriah Waterland 
1065c51f124SMoriah Waterland 	if ((argc-optind) < 2) {
1075c51f124SMoriah Waterland 		usage();
1085c51f124SMoriah Waterland 		return (1);
1095c51f124SMoriah Waterland 	}
1105c51f124SMoriah Waterland 
1115c51f124SMoriah Waterland 	ret = pkgtrans(flex_device(argv[optind], 1),
11232991bedSPeter Tribble 	    flex_device(argv[optind+1], 1), &argv[optind+2], options);
1135c51f124SMoriah Waterland 
1145c51f124SMoriah Waterland 	quit(ret);
1155c51f124SMoriah Waterland 	/*NOTREACHED*/
1165c51f124SMoriah Waterland }
1175c51f124SMoriah Waterland 
1185c51f124SMoriah Waterland void
quit(int retcode)1195c51f124SMoriah Waterland quit(int retcode)
1205c51f124SMoriah Waterland {
1215c51f124SMoriah Waterland 	(void) signal(SIGINT, SIG_IGN);
1225c51f124SMoriah Waterland 	(void) signal(SIGHUP, SIG_IGN);
1235c51f124SMoriah Waterland 	(void) ds_close(1);
1245c51f124SMoriah Waterland 	(void) pkghead(NULL);
1255c51f124SMoriah Waterland 	exit(retcode);
1265c51f124SMoriah Waterland }
1275c51f124SMoriah Waterland 
1285c51f124SMoriah Waterland static void
trap(int signo)1295c51f124SMoriah Waterland trap(int signo)
1305c51f124SMoriah Waterland {
1315c51f124SMoriah Waterland 	(void) signal(SIGINT, SIG_IGN);
1325c51f124SMoriah Waterland 	(void) signal(SIGHUP, SIG_IGN);
1335c51f124SMoriah Waterland 
1345c51f124SMoriah Waterland 	if (signo == SIGINT) {
1355c51f124SMoriah Waterland 		progerr(gettext("aborted at user request.\n"));
1365c51f124SMoriah Waterland 		quit(3);
1375c51f124SMoriah Waterland 	}
1385c51f124SMoriah Waterland 	progerr(gettext("aborted by signal %d\n"), signo);
1395c51f124SMoriah Waterland 	quit(1);
1405c51f124SMoriah Waterland }
1415c51f124SMoriah Waterland 
1425c51f124SMoriah Waterland static void
usage(void)1435c51f124SMoriah Waterland usage(void)
1445c51f124SMoriah Waterland {
1455c51f124SMoriah Waterland 	(void) fprintf(stderr,
14632991bedSPeter Tribble 	    gettext("usage: %s [-ions] srcdev dstdev [pkg [pkg...]]\n"),
1475c51f124SMoriah Waterland 	    get_prog_name());
1485c51f124SMoriah Waterland }
149