Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Oct 2007 11:12:16 -0600
From:      James <oscartheduck@gmail.com>
To:        "Jonathan Horne" <freebsd@dfwlp.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: best way to distribute an item to everyones homedir?
Message-ID:  <d59e90ab0710281012m2b0a70d2qe5a479bed998bc5c@mail.gmail.com>
In-Reply-To: <200710280924.31680.freebsd@dfwlp.com>
References:  <200710280854.53041.freebsd@dfwlp.com> <d59e90ab0710280721l3d8a4e5bs7efb6d8c8fe5b56e@mail.gmail.com> <200710280924.31680.freebsd@dfwlp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 10/28/07, Jonathan Horne <freebsd@dfwlp.com> wrote:
>
> On Sunday 28 October 2007 09:21:55 you wrote:
> > maildir=/path/to/your/custom/maildir
> >
> > for dir in `ls /usr/home`
> > do
> > cp -r $maildir /usr/home/$dir/
> > done
>
> thanks james.  quick question... will that put the proper owner and chmod
> of
> the target homedirs, on the new directories?
>
> thanks,
> --
> Jonathan Horne
> http://dfwlpiki.dfwlp.org
> freebsd@dfwlp.com
>


...what an interesting question. Let me check.

Okay, a couple of things. First, for the copy command, make sure that you
don't include a trailing slash for the source directory, otherwise it copies
the contents of the directory and not the directory itself. So:

pclmills# cp -r COPYME ~james/

NOT:

pclmills# cp -r COPYME/ ~james/


This will set the group permission correctly, not the user, and the
permissions are in accordance with umask. So the result of the above copy
is:

[james@pclmills ~]$ ls -l | grep COPYME
drwxr-xr-x   2 root   james       512 Oct 28 11:03 COPYME


And the file inside the directory gets:

[james@pclmills ~]$ cd COPYME/
[james@pclmills ~/COPYME]$ ls -l
total 0
-rw-r--r--  1 root  james  0 Oct 28 11:03 file

As you've got configuration scripts, if your umask is the same as mine then
this should be fine.

It's reasonably trivial, of course, to add a line to the copy script to use
chmod and chown to change the permissions as you want them to be changed.
the $dir variable in the above for loop contains the name of the home
directory. If this is the same name as the UID/GID (which it is by default)
then even though it looks weird something like:

chown -R $dir:$dir /usr/home/$dir/$maildir

will get you close. Of course, remember this warning from man chown:

     -R      Change the user ID and/or the group ID of the specified
directory
             trees (recursively, including their contents) and files.
Beware
             of unintentionally matching the ``..'' hard link to the parent
             directory when using wildcards like ``.*''.

How I do something like this is to build the script one line at a time using
test directories that I set up. Do that first and everything should be
tickety boo.

I put the mailing list's address back in the cc line of this email; use
"reply all", not reply, to hit the whole mailing list and have people who
are *far* better scripters than me chime in with helpful hints ;)



James



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d59e90ab0710281012m2b0a70d2qe5a479bed998bc5c>