Don’t just install everything into /usr/local

If you use windows then this is probably going to be very, very boring.
Every now and again you find yourself needing to install some piece of software on your computer from a source package. You tar xjf the package and descend into the subdirectory and type ./configure.
At this point I would yell stop! Rather than putting it into the default location of /usr/local, consider putting it in /usr/local/<package-version>.
How does this help I hear you ask. Well, using a simple script (in the extended entry), you create a set of symbolic links in the /usr/local directories which reference the files in the /usr/local/<package-version> directories.
If you decide to remove the package then simply remove the /usr/local/<package-version> directory and all the symlinks become broken. By using symlinks -rd /usr/local you clean the file system up and everything is peachy. If you don’t have a copy of symlinks, it is available from the debian repository, where you should find the source package somewhere near the bottom.

#!/bin/bash -p
[[ -z $package ]] && {
echo "Usage: $me <package> [destination = /usr/local]"
exit 2
cd $destdir/$package || {
echo "$me: package $package does not seem to be installed"
exit 1
# build the directory structure - this is a weakness
find . -type d | cpio -o | (cd $destdir; cpio -id)
find . -type f -exec $echo ln -s $destdir/$package/{} ../{} \;

Oh, and for solaris, as I’m using the file in various locations surrounded by symbols you will have to just pass it into a sub-program to execute the link command. Apparently solaris doesn’t just substitute the name of the target for the link; instead it will only substitute the name of the target when it is isolated (i.e. you would need to use the {} on their own without anything surrounding them – which explains the space between the closing brace and the backslashed semicolon – old habits). I supposed I could throw a bit of perl at this problem but… it works on my box so frell the rest of you :).
Meh, the entire problem is annoying; generally I would always have to create a program to process the {} operation anyway to prevent space characters from getting in the way but as we say in the trade 99% is better than 0%. If you want a 100% solution you need to add a script that performs the link – one per line produced from the find.

5 Replies to “Don’t just install everything into /usr/local”

  1. There a bug in that there script ?

    # bash -px vim70 /usr/local
    + package=vim70
    + destdir=/usr/local
    + [[ -z vim70 ]]
    + cd /usr/local/vim70
    + find . -type d
    + cpio -o
    + cd /usr/local
    + cpio -id
    5 blocks
    5 blocks
    + echo=echo
    + find . -type f -exec echo ln -s '/usr/local/vim70/{}' '../{}' ';'
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
    ln -s /usr/local/vim70/{} ../{}
  2. Grr, solaris’s find replaces barewords of {}’s and not substrings. See the source.

    libfind is coming though.

  3. Exqueeeze me? A bug, in my scripts 🙂 it was you single quoting the exec line. It should (iirc the mechanisms of the find command) be double quoted if you’re trying to protect yourself from a space filled file name.

  4. Hey ! I found the solaris buggie. Solaris’s find doesn’t want anything near the {}. Needs them on their own with nothing touching them 🙂

Comments are closed.