[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: bpm --- Bent Package Manager, using Lua
- From: Bennett Todd <bet@...>
- Date: Sun, 7 Sep 2003 04:22:24 -0400
At some point I plan on turning this inside out, so bpmbuild begins
#!/usr/bin/lua rather than #!/bin/sh, but that'll require I learn
Lua first, which I've not quite done. And I perhaps eventually this
will mature into a toolkit whose #! shell is a custom binary,
including the Lua library, routines for creating and unpacking cpio
archives, the bzip2 library, a sha1 routine, ....
However, I'm cranking out spec files (most of LinuxFromScratch,
plus other goodies to make me comfy), that look like this, as an
example:
pkg = "bash-2.05b";
url = "http://mirrors.kernel.org/gnu/bash/bash-2.05b.tar.gz";
build = [[
tar xzvf bash-2.05b.tar.gz
cd bash-2.05b
./configure --enable-static-link --with-curses \
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
make
make prefix=$BPM_ROOT/usr mandir=$BPM_ROOT/usr/share/man \
infodir=$BPM_ROOT/usr/share/info install
]];
Aim bpmbuild (attached) at such a spec file, and after the dust
settles there's bash-2.05b.cpio.bz2 sitting beside it. If you've
already downloaded the bash source tarball, then set up a directory
structure:
dirname/spec
dirname/src/bash-2.05b.tar.gz
where you get to pick dirname, and the above spec file is in
dirname/spec. bpmbuild dirname, same magic will happen,
bash-2.05b.cpio.bz2 will end up alongside dirname, but without
having to download the bash tarball.
-Bennett
#!/bin/sh
die(){ echo "$0: $*">&2; exit 1; }
syntax="syntax: $0 <bpmsrc>"
test $# = 1 || die $syntax
spec=$1
test -f $spec || spec=$1/spec
test -f $spec || die cannot find spec file $1 or $spec
pkg=`lua -l $spec -e 'print(pkg)'` || die $spec does not provide pkg
tmp=/var/tmp/`basename $0`.$$
trap "rm -rf $tmp" 0
mkdir -p $tmp/build || die cannot mkdir $tmp/build
mkdir $tmp/root || die cannot mkdir $tmp/root
test -d $1/src && cp -r $1/src/* $tmp/build/
srcs=""
lua -l $spec -e 'print(url)' | while read url;do
test -n "$url" || continue
srcfile=`basename $url`
srcs="$srcs $srcfile"
test -f $tmp/build/$srcfile || (cd $tmp/build && wget $url) || die cannot get $url
done
BPM_ROOT=$tmp/root; export BPM_ROOT
lua -l $spec -e 'print(build)' | (cd $tmp/build && sh -xe) || die build failed
pkgstuff=$tmp/root/var/lib/bpm/$pkg
mkdir -p $pkgstuff || die cannot mkdir $pkgstuff
test -d $1 && cp -r $1/* $pkgstuff/
test -d $pkgstuff/src || mkdir -p $pkgstuff/src || die cannot mkdir $pkgstuff/src
test -f $pkgstuff/spec || cp $spec $pkgstuff/spec || die cannot cp $spec $pkgstuff/spec
for srcfile in $srcs;do
test -f $pkgstuff/src/$srcfile || cp $tmp/build/$srcfile $pkgstuff/src/ || die cannot cp $tmp/build/$srcfile $pkgstuff/src/
done
sha1=var/lib/bpm/$pkg/sha1
(cd $tmp/root; rm -f $sha1; find * -type f -print0|xargs -0 openssl sha1 >$tmp/sha1) || die cannot compute sha1
mv $tmp/sha1 $tmp/root/$sha1
(cd $tmp/root; find * -type f -print0 | cpio -o0Hnewc) | bzip2 >$pkg.cpio.bz2 || die package wrap failed
exit 0
# bpmbuild specfile | pkgdir
# => pkg.cpio.bz2
#
# pkg comes from the specfile.
#
# If pkgdir is used, the specfile must reside in pkgdir/spec, and
# sources it calls for will be looked for in pkgdir/src/ before
# attempting to download them automatically.
#
# specfile is lua source, which should define the following variables:
#
# pkg --- pkgname, typically name-version
# url --- url for main source file --- or list of urls
# build --- shell cmd string to unpack, build, and install
#
# build will be run with envar BPM_ROOT set to a temporary, initially
# empty (but for FHS-style dirs) build root, into which the package
# should be installed.
#
# Here's a spec file:
#
# pkg = "bash-2.05b";
# url = "http://mirrors.kernel.org/gnu/bash/bash-2.05b.tar.gz";
# build = [[
# tar xzvf bash-2.05b.tar.gz && cd bash-2.05b &&
# ./configure --enable-static-link --prefix=/usr --with-curses &&
# make && make prefix=$BPM_ROOT/usr install
# ]];
#
# url can be a list of urls, if desired, using the same notation as
# for the scriptlet "build" --- a multiline string.
#
# bpmbuild will make sure all the files specified by the urls are
# present, taking them from pkgdir/src/ if they're there, wget-ing
# them if not. They will be visible in a tmp dir, in which "build"
# will be run by a sh, with BPM_ROOT in its env.
#
# TODO: dependancy tracking
#
# Build-time dependancy analysis: run build cmd under strace -efile,
# analyze results. Writes outside of cwd, BPM_ROOT, /tmp, and /var/tmp
# generate warnings; reads outside of those dirs (and /proc, and /dev)
# generate build dependancies based on the package owners of the files
# read.
#
# TODO: sandbox build
#
# TODO: redirect stdin from /dev/null before running any scripts, and stdout before {pre,post}{install,remove}
#
# TODO: {pre,post}{install,remove} canned scripts _only_, not provided in spec
Attachment:
pgpD5fqNDOrQi.pgp
Description: PGP signature