The freefix script

Here is a contribution from Peter Holmes based on an earlier program by Christopher Rabson that permits some packages to be moved from their predetermined base directory (say /usr/local) to some other directory. Comments to questions asked by S. Christensen are included at the end of the script.

From: peter holmes 

I too wanted my stuff installed in /usr/local,
so I expanded on Christopher Rabson's shell script.  The result was the
"freefix" script enclosed.  It does all the work required to change the
BASEDIR in the packages you supply.  It also changes the package NAME to
the name of the PaCkAgE DaTaStReAm (makes the software rev show up in
pkginfo).


#!/bin/sh
#
#  freefix - freeware "fix" script - modify BASEDIR and NAME of a package
#
#    usage:  freefix pkgstream [ newBASEDIR ]
#
#    notes:  File pkgstream MUST be a "PaCkAgE DaTaStReAm".  If newBASEDIR
#            is not specified, "/usr/local" will be used.  The NAME of the
#            package is changed to pkgstream.
#
#   **********************************************************************
#   *** CAVEAT EMPTOR:  THE FILE pkgstream IS REPLACED BY THIS SCRIPT! ***
#   **********************************************************************
#
#   author:  Peter Holmes (with much help from Christopher Rabson's original)
#
PATH=/usr/bin:/usr/sbin
prog=`basename $0`
tmpdir=$prog.tmpdir
pkgstream=$1
newNAME=$1
newBASEDIR=$2
newBASEDIR=${newBASEDIR:=/usr/local}
#
#  sanity check
#
if [ ! -f $pkgstream ]; then
    echo "$prog: pkgstream file \""$pkgstream"\" not found!"
    exit 1
fi
#
#  make a working directory, put the package in it, cd to it, sanity checks
#
rm -r -f $tmpdir
mkdir $tmpdir
pkgtrans $pkgstream $tmpdir all
cd $tmpdir/*
if [ ! -f pkginfo ]; then
        echo "$prog: pkginfo file not found!"
        exit 2
fi
if [ ! -d reloc ]; then
        echo "$prog: package does not appear to be relocatable"
        exit 3
fi
#
#  modify and replace the 'pkginfo' file
#
mv pkginfo pkginfo-orig
awk '/NAME=/ { $1="NAME='$newNAME'" } ; /BASEDIR=/ { $1="BASEDIR='$newBASEDIR'" } ; { print $1 }' pkginfo-orig > pkginfo
rm pkginfo-orig
#
#  modify and replace the 'pkgmap' file.
#
size=`wc -c pkginfo | cut -f6 -d' '`
chksum=`sum pkginfo | cut -f1 -d' '`
mtime=`grep 'pkginfo' pkgmap | cut -f6 -d' '`
mv pkgmap pkgmap-orig
sed "s;pkginfo .*\$;pkginfo $size $chksum $mtime;" pkgmap-orig > pkgmap
rm pkgmap-orig
#
#  put the package back together - this section OVERWRITES the original
#  package stream and then removes the working directory!!! - if you 
#  don't like it, change it!!!
#
cd ../..
pkgtrans -os $tmpdir/. $pkgstream all
rm -r -f $tmpdir
#
# End of Script
#


The following are answers to your questions:

1. What about something like gcc which if compiled to be in /opt/FSFgcc
   tries to find libraries in /opt/FSFgcc/lib and this is compiled into
   the executable.

A. The freefix script does not touch any of the package's relocatables
and, as such, is not suitable for use with packages like gcc which
expect fixed locations.

2. Can you provide and example of how to use the function?

A. The following are examples of usage with packages downloaded from
your site:

  freefix ghostscript-4.03
  freefix xv-3.10 /usr/local (same as "freefix xv-3.10")
  freefix workman-1.3 /export/home/myhome/mypackagedir

3. In more recent compiles I have been putting things in /usr/local.
   Can you give an example of moving from a /usr/local package to and
   /opt package?

A. To move from /usr/local to /opt (given the caveats in the answer to
question 1), use something like:

  freefix ghostscript-4.03 /opt/ghostscript
  freefix xv-3.10 /opt/JBxv

Note that all this stuff only works given your current modus operandi
(single package, fixed BASEDIR with relative directories and files).

Contact Information

© Copyright 2011 Steven M. Christensen and Associates, Inc.
This page was last updated on January 1, 2011.