mkpak

This tool makes a tar.bz2 package out of the current directory. I wrote it in order to make backups to this website easier.

The tool looks for a file called "pakdef.txt" at the top level directory for the package, where it should be run from. This file contains information about which files should be included or not in the final package.

pakdef.txt contains one directive per line. A line can also be a comment line starting with '#' or a completely empty line. These lines will of course be ignored. There are two kinds of directives for now: filters and shell command directives.

Filters

A filter directive consists of a plus or minus sign, followed by a filter name, some whitespace and the filter argument. If the initial sign is '+', then this is a positive filter. Otherwise, it's a negative filter.

The program normally tries to add all files and directories it finds under the package directory into the tarball. The filters provide a way to exclude some of the files from the tarball. For each directory/file, the negative filters are applied first. If the file entry passes thru all negative filters, then it's added to the tarball. Otherwise, the program looks at all positive filters. If one of the positive filters match the file entry, it's added to the tarball. If the file entry goes thru all positive filters, then it's not added. Here is an example:

-sfx .d
+sfx .o.d
The first rule would eliminate all files ending with ".d". The second rule would add those back which end in ".o.d". For example, "libfoo.d" would be eliminated but "bar.o.d" would be added to the tarball.

Here is a list of the filters:

name  X
  Name of the file or directory is X. foo/X and bar/misc/X would
  both match.
dir X
  Everything under directory X would match, excluding the 
  directory X itself.
sfx X
  Name of the file ends with X. foo/machineX would match.
pfx X
  Name of the file starts with X. foo/Xmachine would match, but 
  not Xfoo/parity.c.
file X
  The file at path X would match only.
magic X
  A file with magic bytes corresponding to magic type X would 
  match.  Current magic types are elf, pdf and postscript.

Shell Command Directives

These directives execute shell commands in the top level package directory. These are also of two kinds; if the directive starts with <run, it's executed before the archival process. If it starts with >run, it's executed after the archival process. The rest of the line is separated from the directive by whitespace and is fed directly to the system function from libc. Here are some examples:
<run echo this is a pre-archival command
<run ls -l 
>run echo this is post-archival
Note that any escape encoding in command lines is ignored and fed directly to the shell. However, all whitespace characters are converted to spaces and multiple spaces are converted to single spaces.

Usage

The tool itself is called "mkpak". You need to call it with the path of the directory in which the tar file will be created. The name of the tarball will be X.tar.bz2 if the name of the directory you invoked it from was X.

The tool can also process symbolic links, but it doesn't follow them. It doesn't process any other weird file type such as sockets, pipes or device nodes.

Download

1.1: Shell command directives are implemented.

1.0: Initial version. You need the libarchive library from here. Just run "make" and put the resulting binary "mkpak" somewhere in your $PATH.

Links