monarch has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a build process using a Perl script thats primary function is to create a chroot() jail before running "make install" so that a package can install itself into what it *thinks* is the root filesystem but is actually another location altogether (later I can tar up the results and release the tarball onto other machines for release).

e.g. I create a directory /tmp/install, and have my source in /tmp/build. My script does the following:

I can tar up the contents of /tmp/install and have a clean build that can be applied to the root file system of similar machines.

My problem is that I want to build mod_perl and this a)needs Perl and b)wants to install things into the Perl library directories. A simple mount of the Perl directory is not sufficient because the Perl modules installed will go straight into my system (and I don't want that).

So I want to copy all of /usr/local/perl into /tmp/install/usr/local/perl, run my chroot(), do the make install, remove all the copied files from /tmp/install/usr/local/perl, and then be left with the Perl modules that were created in /tmp/install/usr/local/perl/lib/....

I thought about maybe using File::Find and File::Copy along with File::Path to automatically create directories, and storing each copied file into an array for subsequent deletion. Is this the best approach? How have other people applied a directory copy then removal (leaving any new artifacts in place).

update: corrected spelling.

Replies are listed 'Best First'.
Re: Copying File Structure, then Removing
by Hue-Bond (Priest) on Sep 06, 2006 at 11:18 UTC
    runs mount of /bin, /usr/bin, /lib, and /tmp/build into /tmp/install/bin,

    Nice! I'll try again to install Google Earth for linux using that trick. Silly me.

    My problem is that I want to build mod_perl and this [...] b)wants to install things into the Perl library directories.

    UnionFS comes to mind. It allows you to mount your whole filesystem (including /tmp/build) under /tmp/install read-only, then mount an empty filesystem also in /tmp/install. Do chroot; make install and UnionFS will take care of committing changes into the empty filesystem, without touching / (since it is read-only). This is how CD-based distros allow users to "write" to the CD.

    --
    David Serrano

Re: Copying File Structure, then Removing
by BrowserUk (Patriarch) on Sep 06, 2006 at 12:52 UTC

    Once you've set up the structure chown the files to a different (non-privileged) UID.

    Once the install is complete, log in under that other account and do a recursive delete on the files (rm -rf *?) on the chroot'd structure and it will leave behind anything created under the install account.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Copying File Structure, then Removing
by planetscape (Chancellor) on Sep 07, 2006 at 16:38 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.