File editing from program control

Eric A. Ayer mwalker at ee.pdx.edu
Wed Jun 28 22:54:13 PDT 2000


What is the easiest way to edit a file from the control of a shell script?  I
was thinking about some things like util-linux, and how some of the options
need to be changed, and how this is usually done with vi.  For an automated
install, vi won't work (it might be an option though :).

I've been working on some scripts that will install programs.  They include a
file with shell variables defined for things like the tar-files directory, the
$LFS directory, as well as some useful shell functions.  Then they make sure
the source exists, patches exist, untar, compile, install, and delete the
source directory.  Some variables can be passed in, like NODELSRC, to tune the
way the packages work.  Here is the vars file, along with the static diffutils
script (most complicated so far):

vars:

TARDIR=/mnt/dos/windows/temp/Linux/pkgs2
SRCDIR=/root/ALFS/source
LFS=/root/ALFS/lfs
IPKGDIR=/root/ALFS/ipkgdir


# some useful shell functions

makedirs()
{
   while [ $# -ne 0 ]
   do
      [ ! -d $1 ] && mkdir $1
      shift
   done
}


And here is diffutils:

#!/bin/sh

# Special flags:
#   NODELSRC='y' - don't delete the source directory
#   NOPATCH='y' - don't apply patch to source


# include the vars file
. ${0%`basename $0`}/vars


# define variables for this package
TARFILE=diffutils-2.7.tar.gz
PATCHFILE=diffutils-2.7.patch
UNTARDIR=diffutils-2.7

# see if source exists, and if so, delete it
[ -d $SRCDIR/$UNTARDIR ] && rm -rf $SRCDIR/$UNTARDIR

# make sure source exists
if [ ! -f $TARDIR/$TARFILE ]
then
   echo "Missing source file: $TARFILE"

   if [ "$NOPATCH" != "y" ] && [ ! -f $TARDIR/$PATCHFILE ]
   then
      echo "Patch file also missing: $PATCHFILE"
   fi

   exit 1
fi

# make sure patch exists, if needed
if [ "$NOPATCH" != "y" ] && [ ! -f $TARDIR/$PATCHFILE ]
then
   echo "Patch file missing: $PATCHFILE"
   exit 1
fi

# untar the source
cd $SRCDIR
tar xvfz $TARDIR/$TARFILE

# apply patch if needed
cd $UNTARDIR
[ "$NOPATCH" != "y" ] && patch -Np1 -i $TARDIR/$PATCHFILE
cd $SRCDIR


# configure, compile, and install - static, so direct install
cd $UNTARDIR
./configure --prefix=/usr --disable-nls
make -e LDFLAGS=-static
make -e prefix=$LFS/usr install


# delete source unless NODELSRC=y
[ "$NODELSRC" != "y" ] && rm -rf $SRCDIR/$UNTARDIR


Some programs move files around a bit, like fileutils.  Also, the variables
that automatically strip binaries could be included in vars - up to the user.

Incidently, bash won't compile - complains about -lcurses not being found.
That may be just something wrong with this LFS system.

					-Erik

--
Mail archive: http://www.pcrdallas.com/mail-archives/alfs-discuss
IRC access: server: irc.linuxfromscratch.org port: 6667 channel: #LFS
Unsubscribe: email alfs-discuss-request at linuxfromscratch.org and put
"unsubscribe" (without the quotation marks) in the body of the message
(no subject is required)



More information about the alfs-discuss mailing list