Date: Fri, 2 Feb 1996 20:18:38 +0100 (MET) From: haury@sagem.fr To: hackers@freebsd.org Subject: Q: why install -d dir missing ? Message-ID: <199602021918.UAA10893@sagem.fr>
next in thread | raw e-mail | index | archive | help
I am wondering why the well known option '-d' is missing in current install
program. Since I am a newbie in FreeBSD, I hope it's not an old war :-)
If the problem is just because no one has time to do that, here are my patches.
I have copied the right routine in NetBSD 1.0 and adapted it for FreeBSD.
NOTA: I have changed the '-d' (debug) option in '-D'.
======= CUT HERE (don't forget to remove my signature) =============
*** ./usr.bin/xinstall/install.1#ctm Wed Jan 31 14:35:24 1996
--- ./usr.bin/xinstall/install.1 Wed Jan 31 15:56:03 1996
***************
*** 47,53 ****
.Op Fl o Ar owner
.Ar file1 file2
.Nm install
! .Op Fl Ccdps
.Op Fl f Ar flags
.Op Fl g Ar group
.Op Fl m Ar mode
--- 47,53 ----
.Op Fl o Ar owner
.Ar file1 file2
.Nm install
! .Op Fl CcDps
.Op Fl f Ar flags
.Op Fl g Ar group
.Op Fl m Ar mode
***************
*** 55,60 ****
--- 55,67 ----
.Ar file1
\&...
.Ar fileN directory
+ .Nm install
+ .Fl d
+ .Op Fl m Ar mode
+ .Op Fl o Ar owner
+ .Op Fl g Ar group
+ .Ar directory
+ \&...
.Sh DESCRIPTION
The file(s) are moved (or copied if the
.Fl c
***************
*** 79,96 ****
This flag turns off the default behavior of
.Nm install
where it deletes the original file after creating the target.
! .It Fl d
Print debugging information.
If
! .Fl d
is specified one or more times,
then print the renaming steps for
.Fl C .
If
! .Fl d
is specified two or more times,
then warn about files that aren't installed with
.Fl C .
.It Fl f
Specify the target's file flags.
(See
--- 86,106 ----
This flag turns off the default behavior of
.Nm install
where it deletes the original file after creating the target.
! .It Fl D
Print debugging information.
If
! .Fl D
is specified one or more times,
then print the renaming steps for
.Fl C .
If
! .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
*** ./usr.bin/xinstall/xinstall.c#ctm Tue Jan 30 11:41:50 1996
--- ./usr.bin/xinstall/xinstall.c Fri Feb 2 20:12:17 1996
***************
*** 81,87 ****
struct passwd *pp;
struct group *gp;
! int debug, docompare, docopy, dopreserve, dostrip;
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
char *group, *owner, pathbuf[MAXPATHLEN];
char pathbuf2[MAXPATHLEN];
--- 81,87 ----
struct passwd *pp;
struct group *gp;
! int debug, docompare, docopy, dopreserve, dostrip, dodir;
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
char *group, *owner, pathbuf[MAXPATHLEN];
char pathbuf2[MAXPATHLEN];
***************
*** 111,117 ****
char *flags, *to_name;
iflags = 0;
! while ((ch = getopt(argc, argv, "Ccdf:g:m:o:ps")) != EOF)
switch((char)ch) {
case 'C':
docompare = docopy = 1;
--- 111,117 ----
char *flags, *to_name;
iflags = 0;
! while ((ch = getopt(argc, argv, "CcDdf:g:m:o:ps")) != EOF)
switch((char)ch) {
case 'C':
docompare = docopy = 1;
***************
*** 119,127 ****
case 'c':
docopy = 1;
break;
! case 'd':
debug++;
break;
case 'f':
flags = optarg;
if (string_to_flags(&flags, &fset, NULL))
--- 119,130 ----
case 'c':
docopy = 1;
break;
! case 'D':
debug++;
break;
+ case 'd':
+ dodir = 1;
+ break;
case 'f':
flags = optarg;
if (string_to_flags(&flags, &fset, NULL))
***************
*** 152,158 ****
}
argc -= optind;
argv += optind;
! if (argc < 2)
usage();
/* get group and owner id's */
--- 155,161 ----
}
argc -= optind;
argv += optind;
! if (argc < 2 && !dodir)
usage();
/* get group and owner id's */
***************
*** 161,166 ****
--- 164,176 ----
if (owner && !(pp = getpwnam(owner)))
errx(EX_NOUSER, "unknown user %s", owner);
+ if (dodir) {
+ for (; *argv != NULL; ++argv)
+ build(*argv);
+ exit (0);
+ /* 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)
***************
*** 492,497 ****
--- 502,546 ----
}
/*
+ * build --
+ * build directory heirarchy
+ */
+ build(path)
+ char *path;
+ {
+ register char *p;
+ struct stat sb;
+ int create, ch;
+
+ for (create = 0, p = path;; ++p)
+ if (!*p || *p == '/') {
+ ch = *p;
+ *p = '\0';
+ if (stat(path, &sb)) {
+ if (errno != ENOENT || mkdir(path, 0777) < 0) {
+ errx(EX_OSERR, "mkdir %s", path);
+ }
+ create = 1;
+ } else {
+ if ((sb.st_mode & S_IFMT) != S_IFDIR) {
+ errx(EX_CANTCREAT, "%s not a directory",
+ path);
+ }
+ }
+ if (!(*p = ch))
+ break;
+ }
+
+ if ((group || owner) &&
+ chown(path, owner ? pp->pw_uid : -1, group ? gp->gr_gid : -1) ||
+ chmod(path, mode)) {
+ errx(EX_OSERR, "chmod %s", path);
+ }
+
+ return(0);
+ }
+
+ /*
* usage --
* print a usage message and die
*/
***************
*** 499,504 ****
usage()
{
(void)fprintf(stderr,
! "usage: install [-Ccdps] [-f flags] [-g group] [-m mode] [-o owner] file1 file2;\n\tor file1 ... fileN directory\n");
exit(1);
}
--- 548,553 ----
usage()
{
(void)fprintf(stderr,
! "usage: install [-CcDps] [-f flags] [-g group] [-m mode] [-o owner] file1 file2;\n\tor file1 ... fileN directory;\n install -d [-g group] [-m mode] [-o owner] dir1 ... dirN;\n");
exit(1);
}
--
=Christian Haury (Christian.Haury@sagem.fr)
---------------------------------------------------------
| SAGEM Eragny - Avenue du Gros Chene - Eragny BP 51 |
| 95612 Cergy Pontoise Cedex - France |
| phone : +33 (1) 34 30 53 93 | telex : 607387F |
| fax : +33 (1) 34 30 50 28 | teletex : 933-130731770 |
---------------------------------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199602021918.UAA10893>
