[lfs-support] [LFS 7.2] [Chapter 6] Symlink Style Package

Stephen Bryant StephenRBryant at gmail.com
Mon Jan 28 12:40:07 PST 2013


On 28 January 2013 13:08, Stephen Bryant <StephenRBryant at gmail.com> wrote:
<snip>
> I should also say that I have realised that the script I gave earlier
> is *massively flawed* and should not be used (I have created a new
> version that actually does what I intended, but don't have it to hand
> right at the moment).
>
<snip>
>
> Steve

For anyone who's interested, here is the 'improved' symbolic link creation
script. No guarantees implied or given, but it seems to be working for me
so far so I'm going to keep using it until I find a good reason not too. It
is so densely commented because I don't write bash scripts very often, so I
want to be able to understand it if I come back to it sometime in the
future:

cat > CreateSymlinks.sh << "EOF"
#!/bin/sh

# Create a soft-link from the root-tree equivalent of the files in the
calling directory
# and its children to the absolute locations of these files.

# Find each subdirectory in this directory
find . -type d | while read relpath; # Assign each relative ./path/of/dirs
to $relpath in turn
do
   if [ -d "$relpath" ] # Ensure $relpath is a directory
   then
      if [ "$relpath" != "." ] # Ignore the current ('./') directory
      then
         # Extract the root tree equivalent of the relative path:
/path/of/dirs
         rootpath="${relpath#*.}" # Remove leading '.'

         # Create the target directories in the root tree, if not already
present.
         echo "mkdir -p $rootpath"
         mkdir -p "$rootpath"

         # Get the absolute location of the relative path:
/usr/pkg/pkg-nam/pkg-num/path/of/dirs
         abspath="$(readlink -f $relpath)"

         # Create the symlinks to the files / links
         # Only find the file/symlink (-type f) contents of the current
(-maxdepth 1) $relpath
         find "$abspath" -type f -maxdepth 1 | while read filepath;
         do
            filename="$(basename $filepath)"
            echo "ln -sv $abspath/$filename $rootpath"
            ln -sv "$abspath"/"$filename" "$rootpath"
         done
      fi
   fi
done
EOF

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-support/attachments/20130128/94c4f1f7/attachment.html>


More information about the lfs-support mailing list