16 Feb 2006    caspar 20060216

1. 
2. 
3. 
4. 
5. 
6. 
7. 
8. 
9. 
10. 
11. 
12. 

NAME

caspar - Makefile snippets for common tasks

SYNOPSIS

In a Makefile, do either
  include caspar/mk/caspar.mk
or
  include caspar/mk/docbook.mk
or
  include caspar/mk/pod.mk
.

DESCRIPTION

Caspar offers Makefile snippets for common tasks, like installing (configuration) files, or typesetting LaTeX, DocBook XML and DocBook SGML documents.

The typesetting functionality is delivered by docbook.mk and pod.mk. This is documented in caspar-typesetting(7).

The installing-stuff functionality is delivered by caspar.mk. (That's what the rest of the manual will talk about.) It enables one to run 'make install' from within a tree which typically holds configuration files, managed using CVS (or Subversion or any other version control system, for that matter).

It is useful in cases like this: all configuration files of some host are under version control, and, after commiting a change to CVS, you want to be able to easily install the new configuration file on the host.

With caspar, all you have to do is specify the hostname in one place, and specify the name of the target directory in each CVS directory.

USAGE

Within a CVS tree, create a file include/install.mk, with contents like e.g.
 csp_UHOST = root@some.host.somewhere
 include caspar/mk/caspar.mk
. Within each other directory of the CVS tree which holds files, create a Makefile, which looks like e.g.
 csp_DIR = /some/dir/ectory/
 include ../../include/install.mk
. If you'd like to use the install-recursive target too, in directories which hold subdirectories (but not files), you'll have to create a Makefile which looks something like
 include ../../include/install.mk
. From within the CVS tree, one can call:
  make <filename>-install
  make install
  make load
  make
  make install-recursive
Calling make install (or make) now will scp all files in the current directory to the remote location. The install-recursive target descends down the tree, and calls make install in each subdirectory.

VARIABLES

The variables one can set in a calling Makefile are:
csp_CP
  
cp binary, just "cp" by default
csp_SCP
  
scp binary, just "scp" by default
csp_SUCP
  
script wrapping sudo in ssh, csp_sucp by default
csp_PUSH
  
make function for pushing files to remote location. Usually, this is a wrapper around a script or program. The function will be passed 4 arguments: local filename, [user@]host, remote directory and (a possibly empty) extra argument. [user@]host will be set to all elements of $(csp_UHOSTS); directory will be set to $(csp_DIR). The fourth argument will be set to $(csp_XARG). Currenly, $(csp_scp_FUNC), $(csp_cp_FUNC) and $(csp_sucp_FUNC) are supported as push plugins. If csp_PUSH is unset, the default $(csp_scp_FUNC) is used.
csp_scp_UHOST
  
ssh-reachable user@host
csp_scp_UHOSTS
  
space separated list of ssh-reachable user@host items
csp_UHOSTS
  
space separated list of user@host items, reachable using $(csp_PUSH).
csp_cp_DIR
  
directory to which we can cp(1), instead of scp
csp_scp_DIR
  
directory on ssh reachable host, with trailing /
csp_DIR
  
directory on host, reachable using function $(csp_PUSH). Set to $(csp_scp_DIR) by default.
csp_LOAD
  
targets which should depend on the `load' target.
csp_EXTRAFILES
  
extra files which should be installed. Can be used to include files starting with a dot.
csp_TABOOFILES
  
files which should never be installed. Set to Makefile .%.swp %~ #%# pod2htmd.tmp pod2htmi.tmp by default.
csp_TABOOFILES_ADD
  
extra files which should never be installed; added to list in csp_TABOOFILES.
csp_TABOOFILES_SKIP
  
files which should be installed, even if in initial csp_TABOOFILES list. Removed from csp_TABOOFILES list.
csp_TABOODIRS
  
directories to exclude in install-recursive target. set to CVS .svn by default.
csp_TABOODIRS_ADD, csp_TABOODIRS_SKIP
  
see csp_TABOOFILES equivalents.
The following variables might get phased out or removed soonish:
csp_CPFLAGS
  
extra arguments to pass to cp invocation, none by default
csp_SCPFLAGS
  
extra arguments to pass to scp invocation, e.g. '-i .ssh/id_rsa-root'
csp_SUH
  
ssh-reachable user@host (Secure User at Host)
csp_SUHS
  
space separated list of ssh-reachable user@host items (Secure User at HostS)
csp_CPDIR
  
directory to which we can cp(1), instead of scp (CoPy DIRectory)
csp_CPDIRS
  
space separated list of directories to which we can copy (CoPy DIRectorieS)
csp_SCPDIR
  
directory on ssh reachable host, with trailing / (Secure CoPy DIRectory)
csp_SUHDIRS
  
this is the list $(csp_SUH):$(dir) for each $(dir) in $(csp_SUHS) (or where dir = $(csp_SCPDIR), in case csp_SUHS is not set). However, more items can get added to this list on the fly.

EXAMPLES

Some examples:

Using csp_CP and csp_LOAD
username/etc/Makefile is

   FIXME TEST THIS
  csp_PUSH = $(csp_CP)
  csp_DIR = $(HOME)/etc/
  csp_LOAD = crontab-load
  include ../include/install.mk

  crontab-load:
        crontab $(csp_CPDIR)/crontab
while ../include/install.mk is just
  include caspar/mk/caspar.mk
.

Using csp_scp_DIR and csp_LOAD
etc/Makefile is

  csp_scp_DIR = /etc/
  csp_LOAD = aliases-load
  include ../include/install.mk

  aliases-load:
      ssh $(csp_scp_UHOST) "cd /etc; postalias aliases; postfix reload"
while ../include/install.mk is
  csp_scp_UHOST = root@some.host.somewhere
  include caspar/mk/caspar.mk

Using the csp_sucp script
To use the csp_sucp script (and not the default scp(1)), add

  csp_PUSH = $(csp_sucp_FUNC)
to ../include/install.mk. If you need to sudo(1) to another user on the remote host, add something like
 csp_XARG = postgres
. (If such a username is not supplied, sudo (and csp_sucp) use the default: root.)

Using the csp_TABOOFILES_{ADD,SKIP} variables
Using the csp_TABOOFILES_{ADD,SKIP} variables is handy if you want to install a Makefile, instead of using it: Create Makefile just as you'd like to have it installed on the remote location. Now, create GNUmakefile as e.g.

  csp_TABOOFILES_SKIP = Makefile
  csp_TABOOFILES_ADD = GNUmakefile

  csp_scp_DIR = /etc/foobar/
  csp_scp_UHOST = root@some.host.somewhere

  load:
        ssh $(csp_scp_UHOST) "make -C $(csp_scp_DIR)"
Now, make install and make load will do the right thing.

Using the csp_EXTRAFILES variable
Using the csp_EXTRAFILES variable is handy if you want to install files with a leading dot. E.g.:

  csp_EXTRAFILES = .bashrc
  csp_SUHDIRS = root@some.host.somewhere:

More advanced tricks
Supply e.g.

 csp_UHOSTS = root@localhost root@some.host.somewhere
in install.mk, to install on multiple hosts. Run
 csp_UHOST=joe@otherhost make filename-install
to install filename as joe@otherhost, instead of the default as given in install.mk.

When you don't want to ssh to root@some.host.somewhere directly, you could do

 sudo rsync -az /path/to/your/config_archive /etc
.

FILES

caspar/mk/caspar.mk, caspar/mk/docbook.mk, caspar/mk/pod.mk

ENVIRONMENT

For caspar.mk: csp_cp_DIR, csp_CP, csp_LOAD, csp_SCP, csp_UHOST, csp_PUSH, ...

BUGS

See TODO and/or BUGS, distributed with the caspar package. (And online at http://mdcc.cx/pub/caspar/caspar-latest/TODO.)

TRIVIA

caspar is named after Caspar the Friendly Ghost, since that's the title of the Daniel Johnston song I was listening to when deciding to package my homegrown scripts.

AUTHOR

Joost van Baal

SEE ALSO

caspar-typesetting(7)

The caspar homepage is at http://mdcc.cx/caspar/ .

The `cvs-conf' package ( http://project.tuxfamily.org/cvs-conf, http://packages.debian.org/stable/utils/cvs-conf.html ) probably offers about the same functionality as caspar.mk. However, this package seems largely unmaintained (between September 2002 and May 2004, at least).

docbookmk, by Michael Wiedmann ( http://www.miwie.org/docbkmake/ ) offers probably a superset of Caspar's docbook.mk functionality.

SUP, the Software Upgrade Protocol and it's implementation by Carnegie Mellon University offers another way to distribute (configuration)files. Beware though: between Nov 1996 and June 2004, no new release has been published. The Debian ( ftp://ftp.debian.org/debian/pool/main/s/sup/ ) and NetBSD packages are likely still maintained, though.

cfengine ( http://www.cfengine.org/ ), by Mark Burgess e.a., builds expert systems to administrate and configure large computer networks: it delivers a very big superset of caspar's installation mechanism.

The svk version control system is said to be quite usable for handling configuration file management (without a separate install mechanism like caspar). See also this discussion on the Debian development list.