help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: processing order, preprocessing, etc.


From: Kai Großjohann
Subject: Re: processing order, preprocessing, etc.
Date: Mon, 23 Dec 2002 19:42:35 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu)

"Luke A. Kanies" <luke@madstop.com> writes:

> Yeah, I was thinking more along the lines of Tobias Oetiker's
> TemplateTree; rather than use the native package format, I would just have
> cfengine copy the files over, and I guess perform any necessary post/pre
> install functions.

Actually, I implemented a horrible solution for this, but focused on
config files.  It even appears to work.  But maybe others here have
better ideas :-)

There is a script copycf.sh that's distributed by CFengine and is
included below.  It is invoked by CFengine as follows:

/----
| shellcommands:
|     copyfiles::
|         "$(script)/copycf.sh $(files) $(allclasses)"
\----

So CFengine knows the list of classes, and copycf.sh uses it.
$(files), despite the name, is a directory name.  Here is the
description of the directory layout:

# Directory structure for keeping config files.

# We use the script copycf.sh to copy config files to the right location,
# so that need not be done here.  The idea is that we have a directory
# "files" which is a sibling of the "inputs" directory.  Under "files", we
# keep the same directory structure as in the main directory tree.  But for
# each config file /etc/foo, we have a directory files/etc/foo with files
# in it named according to CFengine classes.  The script copycf.sh contains
# a priority list of classes and, for each host, looks for the first
# matching class to find a config file.  For example, say we have the
# following three files in files/etc/foo: default, crybaby, laptop.  And
# the priority list of classes contains the host, laptop, desktop, and
# default, in that order.  Then the host crybaby (which is also a laptop)
# will get the file crybaby.  Another host spike which is also a laptop
# will get the file laptop, and finally a host patty which is a desktop
# machine will get the file default.


As you can see, it's all quite horrible.  Amazinly enough, it works.
I think that FAI (the Debian autoinstall tool) comes with a program
fcopy that does something similar in spirit.

There is something that needs to be done: I have to edit copycf.sh
from time to time to add new classes to specify their precedence.

Now for the script:

#!/bin/sh
# $Id: copycf.sh,v 1.6 2002/12/14 20:30:38 kai Exp $

# Most of the documentation for this file can be found in
# cfagent.conf.  See the section "Directory structure" in the comment
# near the beginning of the file.

host=`uname -n`
priority="$host cfengine_server cups_server kbd_de burn mirror_sw"
priority="$priority homesys dell ibm laptop dhcp desktop any"

files="$1"
cfallclasses="$2"

cfallclasses=$(echo $cfallclasses | cut -d= -f2)

case $cfallclasses in
    (:*:)
    ;;
    (*:)
    cfallclasses=:$cfallclasses
    ;;
    (:*)
    cfallclasses=${cfallclasses}:
    ;;
    (*)
    cfallclasses=:${cfallclasses}:
    ;;
esac

# Usage: copyfile <FILE>
# Iterate over list of classes in order ($priority) and install the
# first config file that is found.
copyfile () {
    file="$1"
    for c in $priority; do
        case $cfallclasses in
            (*:${c}:*)
            if [ -f $files/$file/$c ]; then
                if cmp -s $files/$file/$c /$file; then
                    :
                else
                    echo "Installing /$file for class $c"
                    d=$(dirname /$file)
                    test -d $d || mkdir -p $d
                    install -p $files/$file/$c /$file
                    return
                fi
            fi
            ;;
        esac
    done
    return 1
}

# Compute candidate directory names as follows.  Get list of files in
# tree, then take the directory of each file, then eliminate
# duplicates.  Make sure that resulting dir names are relative to
# $files.

candidates=$(
    find $files -name CVS -prune -o -type f -print | {
        while read f; do
            dirname $f
        done;
    } | uniq | sed -e s:$files/:: )

for f in $candidates; do
    copyfile $f
done

# copycf.sh ends here


-- 
~/.signature is: umop ap!sdn    (Frank Nobis)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]