diff options
author | imp <imp@FreeBSD.org> | 1996-09-29 06:29:54 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 1996-09-29 06:29:54 +0000 |
commit | 7cb34628263e6ef7501c1737f8a0c9a9bdb6bf56 (patch) | |
tree | 0623e16c9e8319ccf22d9f3827f198e510c4529f | |
parent | f811c2ec39553f42bda2f64680e9265c11bbe9c0 (diff) | |
download | FreeBSD-src-7cb34628263e6ef7501c1737f8a0c9a9bdb6bf56.zip FreeBSD-src-7cb34628263e6ef7501c1737f8a0c9a9bdb6bf56.tar.gz |
Implement -d in install. Update the man page to reflect this change.
-rw-r--r-- | usr.bin/xinstall/install.1 | 24 | ||||
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 61 |
2 files changed, 73 insertions, 12 deletions
diff --git a/usr.bin/xinstall/install.1 b/usr.bin/xinstall/install.1 index 84cf473..2cd528c 100644 --- a/usr.bin/xinstall/install.1 +++ b/usr.bin/xinstall/install.1 @@ -30,9 +30,9 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)install.1 8.1 (Berkeley) 6/6/93 -.\" $Id: install.1,v 1.5 1996/04/06 01:50:39 julian Exp $ +.\" $Id: install.1,v 1.6 1996/09/24 04:14:58 imp Exp $ .\" -.Dd October 9, 1995 +.Dd September 22, 1996 .Dt INSTALL 1 .Os BSD 4.2 .Sh NAME @@ -40,14 +40,14 @@ .Nd install binaries .Sh SYNOPSIS .Nm install -.Op Fl cs +.Op Fl CcDps .Op Fl f Ar flags .Op Fl g Ar group .Op Fl m Ar mode .Op Fl o Ar owner .Ar file1 file2 .Nm install -.Op Fl Ccdps +.Op Fl CcDps .Op Fl f Ar flags .Op Fl g Ar group .Op Fl m Ar mode @@ -55,6 +55,13 @@ .Ar file1 \&... .Ar fileN directory +.Nm install +.Fl d +.Op Fl g Ar group +.Op Fl m Ar mode +.Op Fl o Ar owner +.Ar directory +\&... .Sh DESCRIPTION The file(s) are moved (or copied if the .Fl c @@ -79,18 +86,21 @@ Copy the file. This flag turns off the default behavior of .Nm install where it deletes the original file after creating the target. -.It Fl D +.It Fl D Print debugging information. If -.Fl d +.Fl D is specified one or more times, then print the renaming steps for .Fl C . If -.Fl d +.Fl D is specified two or more times, then warn about files that aren't installed with .Fl C . +.It Fl d +Create directories. +Missing parent directories are created as required. .It Fl f Specify the target's file flags. (See diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 780ed8b..4add5e8 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -80,7 +80,7 @@ static const char rcsid[] = #include "pathnames.h" -int debug, docompare, docopy, dopreserve, dostrip, verbose; +int debug, docompare, dodir, docopy, dopreserve, dostrip, verbose; int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; char *group, *owner, pathbuf[MAXPATHLEN]; char pathbuf2[MAXPATHLEN]; @@ -93,6 +93,7 @@ void copy __P((int, char *, int, char *, off_t)); int compare __P((int, const char *, int, const char *, const struct stat *, const struct stat *)); void install __P((char *, char *, u_long, u_int)); +void install_dir __P((char *)); u_long string_to_flags __P((char **, u_long *, u_long *)); void strip __P((char *)); void usage __P((void)); @@ -128,7 +129,7 @@ main(argc, argv) char *flags, *to_name; iflags = 0; - while ((ch = getopt(argc, argv, "CcDf:g:m:o:psv")) != EOF) + while ((ch = getopt(argc, argv, "CcdDf:g:m:o:psv")) != EOF) switch((char)ch) { case 'C': docompare = docopy = 1; @@ -139,6 +140,9 @@ main(argc, argv) case 'D': debug++; break; + case 'd': + dodir = 1; + break; case 'f': flags = optarg; if (string_to_flags(&flags, &fset, NULL)) @@ -172,7 +176,13 @@ main(argc, argv) } argc -= optind; argv += optind; - if (argc < 2) + + /* some options make no sense when creating directories */ + if ((docompare || dostrip) && dodir) + usage(); + + /* must have at least two arguments, except when creating directories */ + if (argc < 2 && !dodir) usage(); #ifdef ALLOW_NUMERIC_IDS @@ -192,6 +202,13 @@ main(argc, argv) #endif /* ALLOW_NUMERIC_IDS */ + if (dodir) { + for (; *argv != NULL; ++argv) + install_dir(*argv); + exit(EX_OK); + /* NOTREACHED */ + } + no_target = stat(to_name = argv[argc - 1], &to_sb); if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) { for (; *argv != to_name; ++argv) @@ -621,14 +638,48 @@ strip(to_name) } /* + * install_dir -- + * build directory heirarchy + */ +void +install_dir(path) + char *path; +{ + register char *p; + struct stat sb; + int ch; + + for (p = path;; ++p) + if (!*p || (p != path && *p == '/')) { + ch = *p; + *p = '\0'; + if (stat(path, &sb)) { + if (errno != ENOENT || mkdir(path, 0777) < 0) { + err(EX_OSERR, "%s", path); + /* NOTREACHED */ + } + } + if (!(*p = ch)) + break; + } + + if (((gid != (gid_t)-1 || uid != (uid_t)-1) && chown(path, uid, gid)) || + chmod(path, mode)) { + warn("%s", path); + } +} + +/* * usage -- * print a usage message and die */ void usage() { - (void)fprintf(stderr, -"usage: install [-CcDps] [-f flags] [-g group] [-m mode] [-o owner] file1 file2;\n\tor file1 ... fileN directory\n"); + (void)fprintf(stderr,"\ +usage: install [-CcDpSs] [-f flags] [-g group] [-m mode] [-o owner] file1 file2\n\ + install [-CcDpSs] [-f flags] [-g group] [-m mode] [-o owner] file1 ... fileN directory\n\ + install -d [-g group] [-m mode] [-o owner] directory ...\n"); exit(EX_USAGE); /* NOTREACHED */ } |