[comp.sources.wanted] "cpmod" Copy Modes program wanted

sa@ttidca.TTI.COM (Steve Alter) (08/11/87)

This shouldn't be too tough to write, but why re-invent the computer?

We could really use a "cpmod" program to copy modes/ownerships/times
from one existing file to other existing files.  I envision the
syntax like:

	cpmod [-m] [-o] [-t] file another-file ...

This would copy modes (unless -m is given), ownerships (unless -o is
given) and times (unless -t is given) from the first file to all of
the other files.  Note that copying of times is not possible if any
destination file is a directory, but no error message should be
produced in that case.  If all three options are given then an error
message should be produced saying that there is no work left to do.

Once this is done, could it be incorporated into a rcpmod "Remote Copy
Modes" program?  We need something like this to maintain files on
our local network, but "rcp -p" won't suffice because each system
needs slight modifications in many of the files and I'd like all of
the destination versions to have the same timestamp, modes, etc.

(Sounds like a good project for a CS graduate student! (:-))

-- Steve Alter
...!{csun,trwrb,psivax}!ttidca!alter  or  alter@tti.com
Citicorp/TTI, Santa Monica CA  (213) 452-9191 x2541

root@conexch.UUCP (Larry Dighera) (08/15/87)

In article <1092@ttidca.TTI.COM> sa@ttidca.TTI.COM (Steve Alter) writes:
>We could really use a "cpmod" program to copy modes/ownerships/times
>from one existing file to other existing files.  I envision the
>syntax like:
>
>       cpmod [-m] [-o] [-t] file another-file ...
>
>This would copy modes (unless -m is given), ownerships (unless -o is
>given) and times (unless -t is given) from the first file to all of
>the other files.  Note that copying of times is not possible if any
>destination file is a directory, but no error message should be
>produced in that case.  If all three options are given then an error
>message should be produced saying that there is no work left to do.
>Citicorp/TTI, Santa Monica CA  (213) 452-9191 x2541

Your proposal for a new command strikes a resonant chord with me.  I too
have been longing for a way to specify modes and ownerships with a single
cp or mv command.  An associate wrote the following "first attempt" at 
a program that combines chmod, chown, chgrp.  

-----------------------------  C U T    H E R E   ---------------------------
/*
 *   Chall ( Change all ) is a poor attempt to combined chown, chgrp, and
 *   chmod into one program. The usage of the program is as follows:
 *   chall file_name owner [group [ permissions ]]
 *
 *   Please note that group and permissions are optional.
 *   If you wish to leave one of the fields as they already exist, you can
 *   enter a - ( minus) in that field and that entry will be skipped. An
 *   example is as follows: chall foo - group 777
 *   The above entry will change the group and permissions only!
 *
 *   Written without any glory by Sanford Zelkovitz
 *
*/
#include <stdio.h>
#define OWNER "chown "
#define GROUP "chgrp "
#define PERMS "chmod "
char buffer[99];
main(argc, argv) int argc; char *argv[];
{
        if(argc < 3)
                {
                (void)fprintf(stderr, "\nUsage: chall filename owner [group perms]\n");
                exit (1);
                }
        if(argv[2][0] == '-')goto l1;
        strcpy(buffer, OWNER);
        strcat(buffer, argv[2]);
        strcat(buffer, " ");
        strcat(buffer, argv[1]);
        (void)system(buffer);
l1:
        if(argc == 3)return;
        if(argv[3][0] == '-')goto l2;
        strcpy(buffer, GROUP);
        strcat(buffer, argv[3]);
        strcat(buffer, " ");
        strcat(buffer, argv[1]);
        (void)system(buffer);
l2:
        if(argc == 4)return;
        if(argv[4][0] == '-')return;
        strcpy(buffer, PERMS);
        strcat(buffer, argv[4]);
        strcat(buffer, " ");
        strcat(buffer, argv[1]);
        (void)system(buffer);
}
-----------------------------  C U T    H E R E   ---------------------------

Perhaps this will inspire one of our resident gurus into action.  Here is what
I envision as a single command to perform the duties of cp, chmod, chown, chgrp,
and touch.

        cpx [-m xxxx] [-o owner] [-g group] [-t MMDDYYHHMM] source-file dest

Where each -option changes the destination file's mode, ownership, group, and/or
time to that option's argument.  Ideally, the full syntax of chmod would be 
supported.  A similarly smart mvx program would also be useful.

I suppose that the "proper" way to implement this type of functionality in
a command and still remain safely within the "philosophy of Un*x" would 
be to write a suitable shell script :-).

Best Regards,
Larry Dighera

-- 
USMAIL: The Consultants' Exchange, PO Box 12100, Santa Ana, CA  92712
(714) 842-6348: IBM-PC BBS (N81); (714) 842-5851: Xenix guest account (E71)
UUCP: ...!ucbvax!ucivax!mickey!conexch!root || ...!trwb!ucla-an!conexch!root
UUCP: conexch Any ACU 2400 17148425851 ogin:-""-ogin:-""-ogin: nuucp