Home | History | Annotate | Line # | Download | only in xinstall
xinstall.c revision 1.61
      1  1.61    simonb /*	$NetBSD: xinstall.c,v 1.61 2001/11/23 16:14:51 simonb Exp $	*/
      2   1.5       jtc 
      3   1.1       cgd /*
      4   1.5       jtc  * Copyright (c) 1987, 1993
      5   1.5       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.20       mrg #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38  1.20       mrg __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
     39  1.20       mrg 	The Regents of the University of California.  All rights reserved.\n");
     40   1.1       cgd #endif /* not lint */
     41   1.1       cgd 
     42   1.1       cgd #ifndef lint
     43   1.5       jtc #if 0
     44   1.5       jtc static char sccsid[] = "@(#)xinstall.c	8.1 (Berkeley) 7/21/93";
     45  1.20       mrg #else
     46  1.61    simonb __RCSID("$NetBSD: xinstall.c,v 1.61 2001/11/23 16:14:51 simonb Exp $");
     47   1.5       jtc #endif
     48   1.1       cgd #endif /* not lint */
     49   1.1       cgd 
     50   1.1       cgd #include <sys/param.h>
     51   1.5       jtc #include <sys/mman.h>
     52   1.1       cgd #include <sys/stat.h>
     53  1.61    simonb #include <sys/wait.h>
     54   1.5       jtc 
     55   1.5       jtc #include <ctype.h>
     56  1.50     lukem #include <err.h>
     57   1.5       jtc #include <errno.h>
     58   1.5       jtc #include <fcntl.h>
     59   1.1       cgd #include <grp.h>
     60  1.61    simonb #include <libgen.h>
     61   1.5       jtc #include <paths.h>
     62   1.1       cgd #include <pwd.h>
     63   1.1       cgd #include <stdio.h>
     64   1.5       jtc #include <stdlib.h>
     65   1.5       jtc #include <string.h>
     66   1.5       jtc #include <unistd.h>
     67  1.50     lukem #include <vis.h>
     68   1.5       jtc 
     69   1.1       cgd #include "pathnames.h"
     70  1.29       mrg #include "stat_flags.h"
     71   1.1       cgd 
     72  1.28  wsanchez #define STRIP_ARGS_MAX 32
     73  1.31   hubertf #define BACKUP_SUFFIX ".old"
     74  1.28  wsanchez 
     75  1.50     lukem int	dobackup, docopy, dodir, dostrip, dolink, dopreserve, dorename,
     76  1.50     lukem 	    dounpriv;
     77  1.50     lukem int	numberedbackup;
     78  1.50     lukem int	mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
     79  1.50     lukem char	pathbuf[MAXPATHLEN];
     80  1.50     lukem uid_t	uid;
     81  1.50     lukem gid_t	gid;
     82  1.54     lukem char	*group, *owner, *fflags, *tags;
     83  1.50     lukem FILE	*metafp;
     84  1.50     lukem char	*metafile;
     85  1.50     lukem u_long	fileflags;
     86  1.50     lukem char	*stripArgs;
     87  1.50     lukem char	*suffix = BACKUP_SUFFIX;
     88   1.5       jtc 
     89  1.16  christos #define LN_ABSOLUTE	0x01
     90  1.16  christos #define LN_RELATIVE	0x02
     91  1.16  christos #define LN_HARD		0x04
     92  1.16  christos #define LN_SYMBOLIC	0x08
     93  1.16  christos #define LN_MIXED	0x10
     94  1.16  christos 
     95   1.5       jtc #define	DIRECTORY	0x01		/* Tell install it's a directory. */
     96   1.5       jtc #define	SETFLAGS	0x02		/* Tell install to set flags. */
     97  1.50     lukem #define	HASUID		0x04		/* Tell install the uid was given */
     98  1.50     lukem #define	HASGID		0x08		/* Tell install the gid was given */
     99   1.5       jtc 
    100  1.50     lukem void	backup(const char *);
    101  1.48    simonb void	copy(int, char *, int, char *, off_t);
    102  1.61    simonb int	do_link(char *, char *);
    103  1.61    simonb void	do_symlink(char *, char *);
    104  1.50     lukem void	install(char *, char *, u_int);
    105  1.50     lukem void	install_dir(char *, u_int);
    106  1.50     lukem int	main(int, char *[]);
    107  1.48    simonb void	makelink(char *, char *);
    108  1.61    simonb void	metadata_log(const char *, const char *, struct timeval *, const char *);
    109  1.50     lukem int	parseid(char *, id_t *);
    110  1.48    simonb void	strip(char *);
    111  1.48    simonb void	usage(void);
    112  1.61    simonb char   *xbasename(char *);
    113  1.61    simonb char   *xdirname(char *);
    114   1.1       cgd 
    115   1.5       jtc int
    116  1.48    simonb main(int argc, char *argv[])
    117   1.1       cgd {
    118  1.53     lukem 	struct stat	from_sb, to_sb;
    119  1.53     lukem 	void		*set;
    120  1.53     lukem 	u_int		iflags;
    121  1.53     lukem 	int		ch, no_target;
    122  1.53     lukem 	char		*p, *to_name;
    123  1.43       cgd 
    124  1.43       cgd 	setprogname(argv[0]);
    125   1.1       cgd 
    126   1.5       jtc 	iflags = 0;
    127  1.54     lukem 	while ((ch = getopt(argc, argv, "cbB:df:g:l:m:M:o:prsS:T:U")) != -1)
    128   1.1       cgd 		switch((char)ch) {
    129  1.31   hubertf 		case 'B':
    130  1.31   hubertf 			suffix = optarg;
    131  1.35   hubertf 			numberedbackup = 0;
    132  1.35   hubertf 			{
    133  1.35   hubertf 				/* Check if given suffix really generates
    134  1.35   hubertf 				   different suffixes - catch e.g. ".%" */
    135  1.35   hubertf 				char suffix_expanded0[FILENAME_MAX],
    136  1.35   hubertf 				     suffix_expanded1[FILENAME_MAX];
    137  1.35   hubertf 				(void)snprintf(suffix_expanded0, FILENAME_MAX,
    138  1.35   hubertf 					       suffix, 0);
    139  1.35   hubertf 				(void)snprintf(suffix_expanded1, FILENAME_MAX,
    140  1.35   hubertf 					       suffix, 1);
    141  1.35   hubertf 				if (strcmp(suffix_expanded0, suffix_expanded1)
    142  1.35   hubertf 				    != 0)
    143  1.35   hubertf 					numberedbackup = 1;
    144  1.35   hubertf 			}
    145  1.31   hubertf 			/* fall through; -B implies -b */
    146  1.61    simonb 			/*FALLTHROUGH*/
    147  1.31   hubertf 		case 'b':
    148  1.31   hubertf 			dobackup = 1;
    149  1.31   hubertf 			break;
    150   1.1       cgd 		case 'c':
    151   1.1       cgd 			docopy = 1;
    152   1.1       cgd 			break;
    153  1.26  christos 		case 'd':
    154  1.26  christos 			dodir = 1;
    155  1.26  christos 			break;
    156   1.5       jtc 		case 'f':
    157  1.52        tv 			fflags = optarg;
    158   1.5       jtc 			break;
    159   1.1       cgd 		case 'g':
    160   1.1       cgd 			group = optarg;
    161   1.1       cgd 			break;
    162  1.16  christos 		case 'l':
    163  1.16  christos 			for (p = optarg; *p; p++)
    164  1.16  christos 				switch (*p) {
    165  1.16  christos 				case 's':
    166  1.16  christos 					dolink &= ~(LN_HARD|LN_MIXED);
    167  1.16  christos 					dolink |= LN_SYMBOLIC;
    168  1.16  christos 					break;
    169  1.16  christos 				case 'h':
    170  1.16  christos 					dolink &= ~(LN_SYMBOLIC|LN_MIXED);
    171  1.16  christos 					dolink |= LN_HARD;
    172  1.16  christos 					break;
    173  1.16  christos 				case 'm':
    174  1.16  christos 					dolink &= ~(LN_SYMBOLIC|LN_HARD);
    175  1.16  christos 					dolink |= LN_MIXED;
    176  1.16  christos 					break;
    177  1.16  christos 				case 'a':
    178  1.16  christos 					dolink &= ~LN_RELATIVE;
    179  1.16  christos 					dolink |= LN_ABSOLUTE;
    180  1.16  christos 					break;
    181  1.16  christos 				case 'r':
    182  1.16  christos 					dolink &= ~LN_ABSOLUTE;
    183  1.16  christos 					dolink |= LN_RELATIVE;
    184  1.16  christos 					break;
    185  1.16  christos 				default:
    186  1.16  christos 					errx(1, "%c: invalid link type", *p);
    187  1.61    simonb 					/* NOTREACHED */
    188  1.16  christos 				}
    189  1.16  christos 			break;
    190  1.26  christos 		case 'm':
    191  1.26  christos 			if (!(set = setmode(optarg)))
    192  1.26  christos 				errx(1, "%s: invalid file mode", optarg);
    193  1.26  christos 			mode = getmode(set, 0);
    194  1.42     enami 			free(set);
    195  1.26  christos 			break;
    196  1.50     lukem 		case 'M':
    197  1.50     lukem 			metafile = optarg;
    198  1.50     lukem 			break;
    199  1.26  christos 		case 'o':
    200  1.26  christos 			owner = optarg;
    201  1.26  christos 			break;
    202  1.26  christos 		case 'p':
    203  1.26  christos 			dopreserve = 1;
    204  1.26  christos 			break;
    205  1.33  christos 		case 'r':
    206  1.33  christos 			dorename = 1;
    207  1.33  christos 			break;
    208  1.28  wsanchez 		case 'S':
    209  1.49    simonb 			stripArgs = strdup(optarg);
    210  1.49    simonb 			if (stripArgs == NULL)
    211  1.49    simonb 				errx(1, "%s", strerror(ENOMEM));
    212  1.28  wsanchez 			/* fall through; -S implies -s */
    213  1.61    simonb 			/*FALLTHROUGH*/
    214  1.26  christos 		case 's':
    215  1.26  christos 			dostrip = 1;
    216  1.26  christos 			break;
    217  1.54     lukem 		case 'T':
    218  1.54     lukem 			tags = optarg;
    219  1.54     lukem 			break;
    220  1.38  sommerfe 		case 'U':
    221  1.50     lukem 			dounpriv = 1;
    222  1.38  sommerfe 			break;
    223   1.1       cgd 		case '?':
    224   1.1       cgd 		default:
    225   1.1       cgd 			usage();
    226   1.1       cgd 		}
    227   1.1       cgd 	argc -= optind;
    228   1.1       cgd 	argv += optind;
    229   1.2       jtc 
    230  1.23        tv 	/* strip and link options make no sense when creating directories */
    231  1.23        tv 	if ((dostrip || dolink) && dodir)
    232  1.16  christos 		usage();
    233  1.16  christos 
    234  1.16  christos 	/* strip and flags make no sense with links */
    235  1.52        tv 	if ((dostrip || fflags) && dolink)
    236   1.2       jtc 		usage();
    237   1.2       jtc 
    238   1.2       jtc 	/* must have at least two arguments, except when creating directories */
    239   1.2       jtc 	if (argc < 2 && !dodir)
    240   1.1       cgd 		usage();
    241   1.1       cgd 
    242   1.1       cgd 	/* get group and owner id's */
    243  1.52        tv 	if (group && !dounpriv) {
    244  1.50     lukem 		struct group *gp;
    245  1.50     lukem 
    246  1.50     lukem 		if ((gp = getgrnam(group)) != NULL)
    247  1.50     lukem 			gid = gp->gr_gid;
    248  1.50     lukem 		else if (! parseid(group, &gid))
    249  1.41       cgd 			errx(1, "unknown group %s", group);
    250  1.50     lukem 		iflags |= HASGID;
    251  1.50     lukem 	}
    252  1.52        tv 	if (owner && !dounpriv) {
    253  1.50     lukem 		struct passwd *pp;
    254  1.50     lukem 
    255  1.50     lukem 		if ((pp = getpwnam(owner)) != NULL)
    256  1.50     lukem 			uid = pp->pw_uid;
    257  1.50     lukem 		else if (! parseid(owner, &uid))
    258  1.41       cgd 			errx(1, "unknown user %s", owner);
    259  1.50     lukem 		iflags |= HASUID;
    260  1.50     lukem 	}
    261  1.50     lukem 
    262  1.52        tv 	if (fflags && !dounpriv) {
    263  1.52        tv 		if (string_to_flags(&fflags, &fileflags, NULL))
    264  1.52        tv 			errx(1, "%s: invalid flag", fflags);
    265  1.52        tv 		iflags |= SETFLAGS;
    266  1.52        tv 	}
    267  1.52        tv 
    268  1.50     lukem 	if (metafile) {
    269  1.50     lukem 		if ((metafp = fopen(metafile, "a")) == NULL)
    270  1.50     lukem 			warn("open %s", metafile);
    271  1.41       cgd 	}
    272   1.1       cgd 
    273   1.2       jtc 	if (dodir) {
    274   1.2       jtc 		for (; *argv != NULL; ++argv)
    275  1.50     lukem 			install_dir(*argv, iflags);
    276   1.2       jtc 		exit (0);
    277   1.5       jtc 	}
    278   1.2       jtc 
    279   1.1       cgd 	no_target = stat(to_name = argv[argc - 1], &to_sb);
    280   1.2       jtc 	if (!no_target && S_ISDIR(to_sb.st_mode)) {
    281   1.1       cgd 		for (; *argv != to_name; ++argv)
    282  1.50     lukem 			install(*argv, to_name, iflags | DIRECTORY);
    283   1.1       cgd 		exit(0);
    284   1.1       cgd 	}
    285   1.1       cgd 
    286   1.1       cgd 	/* can't do file1 file2 directory/file */
    287   1.1       cgd 	if (argc != 2)
    288   1.1       cgd 		usage();
    289   1.1       cgd 
    290   1.1       cgd 	if (!no_target) {
    291  1.61    simonb 		/* makelink() handles checks for links */
    292  1.61    simonb 		if (!dolink) {
    293  1.61    simonb 			if (stat(*argv, &from_sb))
    294  1.61    simonb 				err(1, "%s", *argv);
    295  1.61    simonb 			if (!S_ISREG(to_sb.st_mode))
    296  1.61    simonb 				errx(1, "%s: not a regular file", to_name);
    297  1.61    simonb 			if (to_sb.st_dev == from_sb.st_dev &&
    298  1.61    simonb 			    to_sb.st_ino == from_sb.st_ino)
    299  1.61    simonb 				errx(1, "%s and %s are the same file", *argv,
    300  1.61    simonb 				    to_name);
    301  1.61    simonb 		}
    302   1.5       jtc 		/*
    303   1.5       jtc 		 * Unlink now... avoid ETXTBSY errors later.  Try and turn
    304   1.5       jtc 		 * off the append/immutable bits -- if we fail, go ahead,
    305   1.5       jtc 		 * it might work.
    306   1.5       jtc 		 */
    307   1.5       jtc #define	NOCHANGEBITS	(UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND)
    308   1.5       jtc 		if (to_sb.st_flags & NOCHANGEBITS)
    309   1.5       jtc 			(void)chflags(to_name,
    310   1.5       jtc 			    to_sb.st_flags & ~(NOCHANGEBITS));
    311  1.32   hubertf 		if (dobackup)
    312  1.32   hubertf 			backup(to_name);
    313  1.34  christos 		else if (!dorename)
    314  1.31   hubertf 			(void)unlink(to_name);
    315   1.1       cgd 	}
    316  1.50     lukem 	install(*argv, to_name, iflags);
    317   1.1       cgd 	exit(0);
    318   1.1       cgd }
    319   1.1       cgd 
    320   1.1       cgd /*
    321  1.50     lukem  * parseid --
    322  1.50     lukem  *	parse uid or gid from arg into id, returning non-zero if successful
    323  1.50     lukem  */
    324  1.50     lukem int
    325  1.50     lukem parseid(char *name, id_t *id)
    326  1.50     lukem {
    327  1.50     lukem 	char	*ep;
    328  1.50     lukem 
    329  1.50     lukem 	errno = 0;
    330  1.50     lukem 	*id = (id_t)strtoul(name, &ep, 10);
    331  1.50     lukem 	if (errno || *ep != '\0')
    332  1.50     lukem 		return (0);
    333  1.50     lukem 	return (1);
    334  1.50     lukem }
    335  1.50     lukem 
    336  1.50     lukem /*
    337  1.61    simonb  * do_link --
    338  1.61    simonb  *	make a hard link, obeying dorename if set
    339  1.61    simonb  *	return -1 on failure
    340  1.61    simonb  */
    341  1.61    simonb int
    342  1.61    simonb do_link(char *from_name, char *to_name)
    343  1.61    simonb {
    344  1.61    simonb 	char tmpl[MAXPATHLEN];
    345  1.61    simonb 	int ret;
    346  1.61    simonb 
    347  1.61    simonb 	if (dorename) {
    348  1.61    simonb 		(void)snprintf(tmpl, sizeof(tmpl), "%s/inst.XXXXXX",
    349  1.61    simonb 		    xdirname(to_name));
    350  1.61    simonb 		if (mktemp(tmpl) == NULL)
    351  1.61    simonb 			err(1, "%s", tmpl);
    352  1.61    simonb 		ret = link(from_name, tmpl);
    353  1.61    simonb 		if (ret == 0) {
    354  1.61    simonb 			ret = rename(tmpl, to_name);
    355  1.61    simonb 			if (ret < 0)
    356  1.61    simonb 				/* remove temporary link before exiting */
    357  1.61    simonb 				(void)unlink(tmpl);
    358  1.61    simonb 		}
    359  1.61    simonb 		return (ret);
    360  1.61    simonb 	} else
    361  1.61    simonb 		return (link(from_name, to_name));
    362  1.61    simonb }
    363  1.61    simonb 
    364  1.61    simonb /*
    365  1.61    simonb  * do_symlink --
    366  1.61    simonb  *	make a symbolic link, obeying dorename if set
    367  1.61    simonb  *	exit on failure
    368  1.61    simonb  */
    369  1.61    simonb void
    370  1.61    simonb do_symlink(char *from_name, char *to_name)
    371  1.61    simonb {
    372  1.61    simonb 	char tmpl[MAXPATHLEN];
    373  1.61    simonb 
    374  1.61    simonb 	if (dorename) {
    375  1.61    simonb 		(void)snprintf(tmpl, sizeof(tmpl), "%s/inst.XXXXXX",
    376  1.61    simonb 		    xdirname(to_name));
    377  1.61    simonb 		if (mktemp(tmpl) == NULL)
    378  1.61    simonb 			err(1, "%s", tmpl);
    379  1.61    simonb 
    380  1.61    simonb 		if (symlink(from_name, tmpl) == -1)
    381  1.61    simonb 			err(1, "symlink %s -> %s", from_name, tmpl);
    382  1.61    simonb 		if (rename(tmpl, to_name) == -1) {
    383  1.61    simonb 			/* remove temporary link before exiting */
    384  1.61    simonb 			(void)unlink(tmpl);
    385  1.61    simonb 			err(1, "%s: rename", to_name);
    386  1.61    simonb 		}
    387  1.61    simonb 	} else {
    388  1.61    simonb 		if (symlink(from_name, to_name) == -1)
    389  1.61    simonb 			err(1, "symlink %s -> %s", from_name, to_name);
    390  1.61    simonb 	}
    391  1.61    simonb }
    392  1.61    simonb 
    393  1.61    simonb /*
    394  1.16  christos  * makelink --
    395  1.16  christos  *	make a link from source to destination
    396  1.16  christos  */
    397  1.16  christos void
    398  1.48    simonb makelink(char *from_name, char *to_name)
    399  1.16  christos {
    400  1.53     lukem 	char	src[MAXPATHLEN], dst[MAXPATHLEN], lnk[MAXPATHLEN];
    401  1.16  christos 
    402  1.16  christos 	/* Try hard links first */
    403  1.16  christos 	if (dolink & (LN_HARD|LN_MIXED)) {
    404  1.61    simonb 		if (do_link(from_name, to_name) == -1) {
    405  1.16  christos 			if ((dolink & LN_HARD) || errno != EXDEV)
    406  1.16  christos 				err(1, "link %s -> %s", from_name, to_name);
    407  1.16  christos 		}
    408  1.57     lukem 		else {
    409  1.59     perry 			metadata_log(to_name, "hlink", NULL, from_name);
    410  1.16  christos 			return;
    411  1.57     lukem 		}
    412  1.16  christos 	}
    413  1.16  christos 
    414  1.16  christos 	/* Symbolic links */
    415  1.16  christos 	if (dolink & LN_ABSOLUTE) {
    416  1.16  christos 		/* Convert source path to absolute */
    417  1.16  christos 		if (realpath(from_name, src) == NULL)
    418  1.61    simonb 			err(1, "%s", from_name);
    419  1.61    simonb 		do_symlink(src, to_name);
    420  1.59     perry 		metadata_log(to_name, "link", NULL, src);
    421  1.16  christos 		return;
    422  1.16  christos 	}
    423  1.16  christos 
    424  1.16  christos 	if (dolink & LN_RELATIVE) {
    425  1.61    simonb 		char *cp, *d, *s;
    426  1.16  christos 
    427  1.16  christos 		/* Resolve pathnames */
    428  1.16  christos 		if (realpath(from_name, src) == NULL)
    429  1.61    simonb 			err(1, "%s", from_name);
    430  1.61    simonb 
    431  1.61    simonb 		/*
    432  1.61    simonb 		 * The last component of to_name may be a symlink,
    433  1.61    simonb 		 * so use realpath to resolve only the directory.
    434  1.61    simonb 		 */
    435  1.61    simonb 		cp = dirname(to_name);
    436  1.61    simonb 		if (realpath(cp, dst) == NULL)
    437  1.61    simonb 			err(1, "%s", cp);
    438  1.61    simonb 		/* .. and add the last component */
    439  1.61    simonb 		if (strcmp(dst, "/") != 0) {
    440  1.61    simonb 			if (strlcat(dst, "/", sizeof(dst)) > sizeof(dst))
    441  1.61    simonb 				errx(1, "resolved pathname too long");
    442  1.61    simonb 		}
    443  1.61    simonb 		cp = xbasename(to_name);
    444  1.61    simonb 		if (strlcat(dst, cp, sizeof(dst)) > sizeof(dst))
    445  1.61    simonb 			errx(1, "resolved pathname too long");
    446  1.16  christos 
    447  1.16  christos 		/* trim common path components */
    448  1.16  christos 		for (s = src, d = dst; *s == *d; s++, d++)
    449  1.16  christos 			continue;
    450  1.16  christos 		while (*s != '/')
    451  1.16  christos 			s--, d--;
    452  1.16  christos 
    453  1.16  christos 		/* count the number of directories we need to backtrack */
    454  1.16  christos 		for (++d, lnk[0] = '\0'; *d; d++)
    455  1.16  christos 			if (*d == '/')
    456  1.61    simonb 				(void)strcat(lnk, "../");
    457  1.16  christos 
    458  1.61    simonb 		(void)strcat(lnk, ++s);
    459  1.16  christos 
    460  1.61    simonb 		do_symlink(lnk, dst);
    461  1.59     perry 		metadata_log(dst, "link", NULL, lnk);
    462  1.16  christos 		return;
    463  1.16  christos 	}
    464  1.16  christos 
    465  1.16  christos 	/*
    466  1.16  christos 	 * If absolute or relative was not specified,
    467  1.16  christos 	 * try the names the user provided
    468  1.16  christos 	 */
    469  1.61    simonb 	do_symlink(from_name, to_name);
    470  1.59     perry 	metadata_log(to_name, "link", NULL, from_name);
    471  1.16  christos }
    472  1.16  christos 
    473  1.16  christos /*
    474   1.1       cgd  * install --
    475   1.1       cgd  *	build a path name and install the file
    476   1.1       cgd  */
    477   1.5       jtc void
    478  1.50     lukem install(char *from_name, char *to_name, u_int flags)
    479   1.1       cgd {
    480  1.53     lukem 	struct stat	from_sb, to_sb;
    481  1.53     lukem 	struct timeval	tv[2];
    482  1.60     dillo 	int		devnull, from_fd, to_fd, serrno, tmpmode;
    483  1.53     lukem 	char		*p, tmpl[MAXPATHLEN], *oto_name;
    484   1.5       jtc 
    485   1.5       jtc 	if (flags & DIRECTORY || strcmp(from_name, _PATH_DEVNULL)) {
    486  1.56     perry 		if (!dolink) {
    487  1.56     perry 			if (stat(from_name, &from_sb))
    488  1.56     perry 				err(1, "%s", from_name);
    489  1.56     perry 			if (!S_ISREG(from_sb.st_mode))
    490  1.56     perry 				errx(1, "%s: not a regular file", from_name);
    491  1.56     perry 		}
    492   1.5       jtc 		/* Build the target path. */
    493   1.5       jtc 		if (flags & DIRECTORY) {
    494   1.5       jtc 			(void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s",
    495   1.5       jtc 			    to_name,
    496  1.21     lukem 			    (p = strrchr(from_name, '/')) ? ++p : from_name);
    497   1.1       cgd 			to_name = pathbuf;
    498   1.1       cgd 		}
    499   1.1       cgd 		devnull = 0;
    500   1.5       jtc 	} else {
    501   1.5       jtc 		from_sb.st_flags = 0;	/* XXX */
    502   1.1       cgd 		devnull = 1;
    503   1.5       jtc 	}
    504   1.1       cgd 
    505   1.5       jtc 	/*
    506   1.5       jtc 	 * Unlink now... avoid ETXTBSY errors later.  Try and turn
    507   1.5       jtc 	 * off the append/immutable bits -- if we fail, go ahead,
    508   1.5       jtc 	 * it might work.
    509   1.5       jtc 	 */
    510   1.5       jtc 	if (stat(to_name, &to_sb) == 0 &&
    511   1.5       jtc 	    to_sb.st_flags & (NOCHANGEBITS))
    512   1.5       jtc 		(void)chflags(to_name, to_sb.st_flags & ~(NOCHANGEBITS));
    513  1.33  christos 	if (dorename) {
    514  1.61    simonb 		(void)snprintf(tmpl, sizeof(tmpl), "%sinst.XXXXXX",
    515  1.61    simonb 		    xdirname(to_name));
    516  1.33  christos 		oto_name = to_name;
    517  1.33  christos 		to_name = tmpl;
    518  1.33  christos 	} else {
    519  1.37  christos 		oto_name = NULL;	/* pacify gcc */
    520  1.33  christos 		if (dobackup)
    521  1.33  christos 			backup(to_name);
    522  1.33  christos 		else
    523  1.33  christos 			(void)unlink(to_name);
    524  1.33  christos 	}
    525  1.16  christos 
    526  1.16  christos 	if (dolink) {
    527  1.61    simonb 		makelink(from_name, dorename ? oto_name : to_name);
    528  1.16  christos 		return;
    529  1.16  christos 	}
    530   1.1       cgd 
    531   1.5       jtc 	/* Create target. */
    532  1.33  christos 	if (dorename) {
    533  1.33  christos 		if ((to_fd = mkstemp(to_name)) == -1)
    534  1.33  christos 			err(1, "%s", to_name);
    535  1.33  christos 	} else {
    536  1.33  christos 		if ((to_fd = open(to_name,
    537  1.33  christos 		    O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) < 0)
    538  1.33  christos 			err(1, "%s", to_name);
    539  1.33  christos 	}
    540   1.1       cgd 	if (!devnull) {
    541   1.1       cgd 		if ((from_fd = open(from_name, O_RDONLY, 0)) < 0) {
    542   1.1       cgd 			(void)unlink(to_name);
    543   1.5       jtc 			err(1, "%s", from_name);
    544   1.1       cgd 		}
    545   1.5       jtc 		copy(from_fd, from_name, to_fd, to_name, from_sb.st_size);
    546   1.1       cgd 		(void)close(from_fd);
    547   1.1       cgd 	}
    548   1.9  jonathan 
    549   1.9  jonathan 	if (dostrip) {
    550   1.1       cgd 		strip(to_name);
    551   1.9  jonathan 
    552   1.9  jonathan 		/*
    553   1.9  jonathan 		 * Re-open our fd on the target, in case we used a strip
    554   1.9  jonathan 		 *  that does not work in-place -- like gnu binutils strip.
    555   1.9  jonathan 		 */
    556   1.9  jonathan 		close(to_fd);
    557   1.9  jonathan 		if ((to_fd = open(to_name, O_RDONLY, S_IRUSR | S_IWUSR)) < 0)
    558   1.9  jonathan 		  err(1, "stripping %s", to_name);
    559   1.9  jonathan 	}
    560   1.9  jonathan 
    561  1.41       cgd 	/*
    562  1.41       cgd 	 * Set owner, group, mode for target; do the chown first,
    563  1.41       cgd 	 * chown may lose the setuid bits.
    564  1.41       cgd 	 */
    565  1.50     lukem 	if (!dounpriv &&
    566  1.50     lukem 	    (flags & (HASUID | HASGID)) && fchown(to_fd, uid, gid) == -1) {
    567  1.41       cgd 		serrno = errno;
    568  1.41       cgd 		(void)unlink(to_name);
    569  1.41       cgd 		errx(1, "%s: chown/chgrp: %s", to_name, strerror(serrno));
    570   1.1       cgd 	}
    571  1.60     dillo 	tmpmode = mode;
    572  1.58        tv 	if (dounpriv)
    573  1.60     dillo 		tmpmode &= S_IRWXU|S_IRWXG|S_IRWXO;
    574  1.60     dillo 	if (fchmod(to_fd, tmpmode) == -1) {
    575   1.5       jtc 		serrno = errno;
    576   1.5       jtc 		(void)unlink(to_name);
    577   1.5       jtc 		errx(1, "%s: chmod: %s", to_name, strerror(serrno));
    578   1.5       jtc 	}
    579   1.5       jtc 
    580   1.5       jtc 	/*
    581  1.26  christos 	 * Preserve the date of the source file.
    582  1.26  christos 	 */
    583  1.26  christos 	if (dopreserve) {
    584  1.37  christos #ifdef BSD4_4
    585  1.26  christos 		TIMESPEC_TO_TIMEVAL(&tv[0], &from_sb.st_atimespec);
    586  1.26  christos 		TIMESPEC_TO_TIMEVAL(&tv[1], &from_sb.st_mtimespec);
    587  1.37  christos #else
    588  1.37  christos 		tv[0].tv_sec = from_sb.st_atime;
    589  1.37  christos 		tv[0].tv_usec = 0;
    590  1.37  christos 		tv[1].tv_sec = from_sb.st_mtime;
    591  1.37  christos 		tv[1].tv_usec = 0;
    592  1.37  christos #endif
    593  1.50     lukem 		if (!dounpriv && futimes(to_fd, tv) == -1)
    594  1.26  christos 			warn("%s: futimes", to_name);
    595   1.5       jtc 	}
    596   1.5       jtc 
    597   1.1       cgd 	(void)close(to_fd);
    598  1.33  christos 
    599  1.50     lukem 	if (dorename) {
    600  1.33  christos 		if (rename(to_name, oto_name) == -1)
    601  1.33  christos 			err(1, "%s: rename", to_name);
    602  1.50     lukem 		to_name = oto_name;
    603  1.50     lukem 	}
    604  1.33  christos 
    605   1.5       jtc 	if (!docopy && !devnull && unlink(from_name))
    606   1.5       jtc 		err(1, "%s", from_name);
    607  1.50     lukem 
    608  1.50     lukem 	/*
    609  1.50     lukem 	 * If provided a set of flags, set them, otherwise, preserve the
    610  1.50     lukem 	 * flags, except for the dump flag.
    611  1.50     lukem 	 */
    612  1.50     lukem 	if (!dounpriv && chflags(to_name,
    613  1.51     lukem 	    flags & SETFLAGS ? fileflags : from_sb.st_flags & ~UF_NODUMP) == -1)
    614  1.51     lukem 	{
    615  1.50     lukem 		if (errno != EOPNOTSUPP || (from_sb.st_flags & ~UF_NODUMP) != 0)
    616  1.50     lukem 			warn("%s: chflags", to_name);
    617  1.50     lukem 	}
    618  1.50     lukem 
    619  1.59     perry 	metadata_log(to_name, "file", tv, NULL);
    620   1.1       cgd }
    621   1.1       cgd 
    622   1.1       cgd /*
    623   1.1       cgd  * copy --
    624   1.1       cgd  *	copy from one file to another
    625   1.1       cgd  */
    626   1.5       jtc void
    627  1.48    simonb copy(int from_fd, char *from_name, int to_fd, char *to_name, off_t size)
    628   1.1       cgd {
    629  1.53     lukem 	ssize_t	nr, nw;
    630  1.53     lukem 	int	serrno;
    631  1.53     lukem 	char	*p;
    632  1.53     lukem 	char	buf[MAXBSIZE];
    633   1.1       cgd 
    634   1.5       jtc 	/*
    635  1.28  wsanchez 	 * There's no reason to do anything other than close the file
    636  1.28  wsanchez 	 * now if it's empty, so let's not bother.
    637   1.5       jtc 	 */
    638  1.28  wsanchez 	if (size > 0) {
    639  1.45       chs 
    640  1.28  wsanchez 		/*
    641  1.45       chs 		 * Mmap and write if less than 8M (the limit is so we
    642  1.45       chs 		 * don't totally trash memory on big files).  This is
    643  1.45       chs 		 * really a minor hack, but it wins some CPU back.
    644  1.28  wsanchez 		 */
    645  1.45       chs 
    646  1.28  wsanchez 		if (size <= 8 * 1048576) {
    647  1.28  wsanchez 			if ((p = mmap(NULL, (size_t)size, PROT_READ,
    648  1.45       chs 			    MAP_FILE|MAP_SHARED, from_fd, (off_t)0))
    649  1.45       chs 			    == MAP_FAILED) {
    650  1.45       chs 				goto mmap_failed;
    651  1.36   thorpej 			}
    652  1.44       cgd #ifdef MADV_SEQUENTIAL
    653  1.39  christos 			if (madvise(p, (size_t)size, MADV_SEQUENTIAL) == -1
    654  1.39  christos 			    && errno != EOPNOTSUPP)
    655  1.38  sommerfe 				warnx("madvise: %s", strerror(errno));
    656  1.44       cgd #endif
    657  1.38  sommerfe 
    658  1.36   thorpej 			if (write(to_fd, p, size) != size) {
    659  1.36   thorpej 				serrno = errno;
    660  1.36   thorpej 				(void)unlink(to_name);
    661  1.36   thorpej 				errx(1, "%s: %s",
    662  1.36   thorpej 				    to_name, strerror(serrno));
    663  1.36   thorpej 			}
    664  1.28  wsanchez 		} else {
    665  1.45       chs mmap_failed:
    666  1.36   thorpej 			while ((nr = read(from_fd, buf, sizeof(buf))) > 0) {
    667  1.28  wsanchez 				if ((nw = write(to_fd, buf, nr)) != nr) {
    668  1.28  wsanchez 					serrno = errno;
    669  1.28  wsanchez 					(void)unlink(to_name);
    670  1.45       chs 					errx(1, "%s: %s", to_name,
    671  1.45       chs 					    strerror(nw > 0 ? EIO : serrno));
    672  1.28  wsanchez 				}
    673  1.36   thorpej 			}
    674  1.28  wsanchez 			if (nr != 0) {
    675   1.5       jtc 				serrno = errno;
    676   1.5       jtc 				(void)unlink(to_name);
    677  1.28  wsanchez 				errx(1, "%s: %s", from_name, strerror(serrno));
    678   1.5       jtc 			}
    679   1.1       cgd 		}
    680   1.1       cgd 	}
    681   1.1       cgd }
    682   1.1       cgd 
    683   1.1       cgd /*
    684   1.1       cgd  * strip --
    685   1.1       cgd  *	use strip(1) to strip the target file
    686   1.1       cgd  */
    687   1.5       jtc void
    688  1.48    simonb strip(char *to_name)
    689   1.1       cgd {
    690  1.53     lukem 	int	serrno, status;
    691  1.53     lukem 	char	*stripprog;
    692   1.1       cgd 
    693   1.1       cgd 	switch (vfork()) {
    694   1.1       cgd 	case -1:
    695   1.5       jtc 		serrno = errno;
    696   1.5       jtc 		(void)unlink(to_name);
    697  1.22   thorpej 		errx(1, "vfork: %s", strerror(serrno));
    698  1.61    simonb 		/*NOTREACHED*/
    699   1.1       cgd 	case 0:
    700  1.18   thorpej 		stripprog = getenv("STRIP");
    701  1.18   thorpej 		if (stripprog == NULL)
    702  1.18   thorpej 			stripprog = _PATH_STRIP;
    703  1.28  wsanchez 
    704  1.28  wsanchez 		if (stripArgs) {
    705  1.50     lukem 			/*
    706  1.50     lukem 			 * build up a command line and let /bin/sh
    707  1.50     lukem 			 * parse the arguments
    708  1.50     lukem 			 */
    709  1.28  wsanchez 			char* cmd = (char*)malloc(sizeof(char)*
    710  1.28  wsanchez 						  (3+strlen(stripprog)+
    711  1.28  wsanchez 						     strlen(stripArgs)+
    712  1.28  wsanchez 						     strlen(to_name)));
    713  1.49    simonb 
    714  1.49    simonb 			if (cmd == NULL)
    715  1.49    simonb 				errx(1, "%s", strerror(ENOMEM));
    716  1.28  wsanchez 
    717  1.28  wsanchez 			sprintf(cmd, "%s %s %s", stripprog, stripArgs, to_name);
    718  1.28  wsanchez 
    719  1.28  wsanchez 			execl(_PATH_BSHELL, "sh", "-c", cmd, NULL);
    720  1.28  wsanchez 		} else
    721  1.40       cgd 			execlp(stripprog, "strip", to_name, NULL);
    722  1.28  wsanchez 
    723  1.22   thorpej 		warn("%s", stripprog);
    724  1.22   thorpej 		_exit(1);
    725  1.61    simonb 		/*NOTREACHED*/
    726   1.1       cgd 	default:
    727   1.1       cgd 		if (wait(&status) == -1 || status)
    728   1.5       jtc 			(void)unlink(to_name);
    729   1.1       cgd 	}
    730  1.32   hubertf }
    731  1.32   hubertf 
    732  1.32   hubertf /*
    733  1.61    simonb  * backup --
    734  1.61    simonb  *	backup file "to_name" to to_name.suffix
    735  1.61    simonb  *	if suffix contains a "%", it's taken as a printf(3) pattern
    736  1.61    simonb  *	used for a numbered backup.
    737  1.32   hubertf  */
    738  1.32   hubertf void
    739  1.48    simonb backup(const char *to_name)
    740  1.32   hubertf {
    741  1.61    simonb 	char	bname[FILENAME_MAX];
    742  1.32   hubertf 
    743  1.35   hubertf 	if (numberedbackup) {
    744  1.32   hubertf 		/* Do numbered backup */
    745  1.32   hubertf 		int cnt;
    746  1.32   hubertf 		char suffix_expanded[FILENAME_MAX];
    747  1.32   hubertf 
    748  1.32   hubertf 		cnt=0;
    749  1.32   hubertf 		do {
    750  1.50     lukem 			(void)snprintf(suffix_expanded, FILENAME_MAX, suffix,
    751  1.50     lukem 			    cnt);
    752  1.61    simonb 			(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name,
    753  1.61    simonb 			    suffix_expanded);
    754  1.32   hubertf 			cnt++;
    755  1.61    simonb 		} while (access(bname, F_OK) == 0);
    756  1.32   hubertf 	} else {
    757  1.32   hubertf 		/* Do simple backup */
    758  1.61    simonb 		(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name, suffix);
    759  1.32   hubertf 	}
    760  1.32   hubertf 
    761  1.61    simonb 	(void)rename(to_name, bname);
    762   1.1       cgd }
    763   1.1       cgd 
    764   1.1       cgd /*
    765   1.5       jtc  * install_dir --
    766  1.47       wiz  *	build directory hierarchy
    767   1.2       jtc  */
    768   1.7       jtc void
    769  1.50     lukem install_dir(char *path, u_int flags)
    770   1.2       jtc {
    771  1.53     lukem         char		*p;
    772  1.53     lukem         struct stat	sb;
    773  1.53     lukem         int		ch;
    774   1.2       jtc 
    775   1.4       cgd         for (p = path;; ++p)
    776   1.4       cgd                 if (!*p || (p != path && *p  == '/')) {
    777   1.2       jtc                         ch = *p;
    778   1.2       jtc                         *p = '\0';
    779   1.2       jtc                         if (stat(path, &sb)) {
    780   1.2       jtc                                 if (errno != ENOENT || mkdir(path, 0777) < 0) {
    781   1.7       jtc 					err(1, "%s", path);
    782   1.2       jtc                                 }
    783   1.2       jtc                         }
    784   1.2       jtc                         if (!(*p = ch))
    785   1.4       cgd 				break;
    786   1.2       jtc                 }
    787   1.2       jtc 
    788  1.50     lukem 	if (!dounpriv && (
    789  1.50     lukem 	    ((flags & (HASUID | HASGID)) && chown(path, uid, gid) == -1)
    790  1.50     lukem 	    || chmod(path, mode) == -1 )) {
    791   1.5       jtc                 warn("%s", path);
    792  1.41       cgd 	}
    793  1.59     perry 	metadata_log(path, "dir", NULL, NULL);
    794   1.2       jtc }
    795   1.2       jtc 
    796   1.2       jtc /*
    797  1.50     lukem  * metadata_log --
    798  1.50     lukem  *	if metafp is not NULL, output mtree(8) full path name and settings to
    799  1.50     lukem  *	metafp, to allow permissions to be set correctly by other tools.
    800  1.50     lukem  */
    801  1.50     lukem void
    802  1.59     perry metadata_log(const char *path, const char *type, struct timeval *tv,
    803  1.57     lukem 	const char *link)
    804  1.50     lukem {
    805  1.50     lukem 	const char	extra[] = { ' ', '\t', '\n', '\\', '#', '\0' };
    806  1.53     lukem 	char		*buf;
    807  1.50     lukem 
    808  1.50     lukem 	if (!metafp)
    809  1.50     lukem 		return;
    810  1.50     lukem 	buf = (char *)malloc(4 * strlen(path) + 1);	/* buf for strsvis(3) */
    811  1.50     lukem 	if (buf == NULL) {
    812  1.50     lukem 		warnx("%s", strerror(ENOMEM));
    813  1.50     lukem 		return;
    814  1.50     lukem 	}
    815  1.50     lukem 	if (flock(fileno(metafp), LOCK_EX) == -1) {	/* lock log file */
    816  1.50     lukem 		warn("can't lock %s", metafile);
    817  1.50     lukem 		return;
    818  1.50     lukem 	}
    819  1.50     lukem 
    820  1.50     lukem 	strsvis(buf, path, VIS_CSTYLE, extra);		/* encode name */
    821  1.50     lukem 	fprintf(metafp, ".%s%s type=%s mode=%#o",	/* print details */
    822  1.59     perry 	    buf[0] == '/' ? "" : "/", buf, type, mode);
    823  1.57     lukem 	if (link)
    824  1.57     lukem 		fprintf(metafp, " link=%s", link);
    825  1.52        tv 	if (owner)
    826  1.52        tv 		fprintf(metafp, " uname=%s", owner);
    827  1.52        tv 	if (group)
    828  1.52        tv 		fprintf(metafp, " gname=%s", group);
    829  1.52        tv 	if (fflags)
    830  1.52        tv 		fprintf(metafp, " flags=%s", fflags);
    831  1.54     lukem 	if (tags)
    832  1.54     lukem 		fprintf(metafp, " tags=%s", tags);
    833  1.57     lukem 	if (tv != NULL && dopreserve)
    834  1.50     lukem 		fprintf(metafp, " time=%ld.%ld", tv[1].tv_sec, tv[1].tv_usec);
    835  1.50     lukem 	fputc('\n', metafp);
    836  1.50     lukem 	fflush(metafp);					/* flush output */
    837  1.50     lukem 	if (flock(fileno(metafp), LOCK_UN) == -1) {	/* unlock log file */
    838  1.50     lukem 		warn("can't unlock %s", metafile);
    839  1.50     lukem 	}
    840  1.50     lukem 	free(buf);
    841  1.50     lukem }
    842  1.50     lukem 
    843  1.61    simonb /*
    844  1.61    simonb  * xbasename --
    845  1.61    simonb  *	libc basename(3) that returns a pointer to a static buffer
    846  1.61    simonb  *	instead of overwriting that passed-in string.
    847  1.61    simonb  */
    848  1.61    simonb char *
    849  1.61    simonb xbasename(char *path)
    850  1.61    simonb {
    851  1.61    simonb 	static char tmp[MAXPATHLEN];
    852  1.61    simonb 
    853  1.61    simonb 	(void)strlcpy(tmp, path, sizeof(tmp));
    854  1.61    simonb 	return (basename(tmp));
    855  1.61    simonb }
    856  1.61    simonb 
    857  1.61    simonb /*
    858  1.61    simonb  * xdirname --
    859  1.61    simonb  *	libc dirname(3) that returns a pointer to a static buffer
    860  1.61    simonb  *	instead of overwriting that passed-in string.
    861  1.61    simonb  */
    862  1.61    simonb char *
    863  1.61    simonb xdirname(char *path)
    864  1.61    simonb {
    865  1.61    simonb 	static char tmp[MAXPATHLEN];
    866  1.50     lukem 
    867  1.61    simonb 	(void)strlcpy(tmp, path, sizeof(tmp));
    868  1.61    simonb 	return (dirname(tmp));
    869  1.61    simonb }
    870  1.50     lukem 
    871  1.50     lukem /*
    872   1.1       cgd  * usage --
    873   1.1       cgd  *	print a usage message and die
    874   1.1       cgd  */
    875   1.5       jtc void
    876  1.48    simonb usage(void)
    877   1.1       cgd {
    878  1.53     lukem 
    879   1.2       jtc 	(void)fprintf(stderr, "\
    880  1.54     lukem usage: install [-Ubcprs] [-M log] [-T tags] [-B suffix] [-f flags] [-m mode]\n\
    881  1.50     lukem 	    [-o owner] [-g group] [-l linkflags] [-S stripflags] file1 file2\n\
    882  1.54     lukem        install [-Ubcprs] [-M log] [-T tags] [-B suffix] [-f flags] [-m mode]\n\
    883  1.54     lukem 	    [-o owner] [-g group] [-l linkflags] [-S stripflags]\n\
    884  1.50     lukem 	    file1 ... fileN directory\n\
    885  1.54     lukem        install [-Up] [-M log] [-T tags] -d [-m mode]\n\
    886  1.54     lukem 	    [-o owner] [-g group] directory ...\n");
    887   1.6       jtc 	exit(1);
    888   1.1       cgd }
    889