#! /bin/sh # This is a script to automate some tasks when testing chicken # tarballs. It downloads, builds and tests chicken and installs a # couple of eggs. INSTALL_DIRNAME=test-chicken info() { echo "==== " $* } member() { item=$1 shift seq=$@ for i in $seq; do [ "$i" = "$item" ] && return 0 done return 1 } download() { uri=$1 downloader= downloader_args= if member '--skip-download' $args; then return 0 else if wget --version > /dev/null 2>&1; then downloader=wget elif curl --version > /dev/null 2>&1; then downloader=curl else echo "Could not find any downloader (attempted wget and curl). Aborting." exit 1 fi case $downloader in "wget") downloader_args="";; "curl") downloader_args="-O";; esac info Downloading $uri $downloader $downloader_args $uri fi } extract() { if member '--skip-extract' $args; then return 0 else tarball=`basename $uri` info Extracting $tarball # hack to determine the source dirname (nevermind the double call to gzip) chicken_source_dirname=`gzip -cd $tarball | tar tf - | head -n 1` tar=`echo $tarball | sed 's/\.gz$//'` gzip -cd $tarball > $tar && tar -xf $tar fi } build() { if member '--skip-build' $args; then return 0 else info Building $MAKE PREFIX=$TMPDIR/$INSTALL_DIRNAME $MAKE_ARGS fi } install() { if member '--skip-install' $args; then return 0 else info Installing $MAKE PREFIX=$TMPDIR/$INSTALL_DIRNAME $MAKE_ARGS install fi } check() { if member '--skip-check' $args; then return 0 else info Checking $MAKE PREFIX=$TMPDIR/$INSTALL_DIRNAME $MAKE_ARGS check fi } install_eggs() { if member '--skip-eggs' $args; then return 0 else info Installing eggs $TMPDIR/$INSTALL_DIRNAME/bin/chicken-install -test $TEST_EGGS fi } usage() { echo "Usage: PLATFORM= $this_program [] " cat <: --skip-download: skip downloading the tarball --skip-extract: skip extracting the tarball --skip-build: skip building Chicken --skip-install: skip installing Chicken --skip-check: skip testing Chicken --skip-eggs: skip installing eggs with the under-test Chicken $this_program uses the following environment variables: MAKE: "make" program to use (default: make) TMPDIR: temporary directory to use (default: created by mktemp) MAKE_ARGS: arguments to be passed to invocations of "make" (default: empty) TEST_EGGS: eggs to install with the under-test Chicken (default: $TEST_EGGS) EOF } args="$@" this_program=`basename $0` if member -h $args || member --help $args; then usage exit 0 fi # Determine non-optional argument (uri) uri= for arg in $args; do [ "`echo $arg | cut -b-2`" = "--" ] || uri=$arg done # Abort if cannot determine uri if [ "x$uri" = "x" ]; then usage exit 1 fi if [ "x$TMPDIR" = "x" ]; then TMPDIR=$PWD/`mktemp -d test-chicken-XXXXXX` else # Make TMPDIR an absolute pathname in case it is not if [ ! "`echo $TMPDIR | cut -b-1`" = "/" ]; then TMPDIR=$PWD/$TMPDIR fi fi [ "x$MAKE" = "x" ] && MAKE=make [ "x$TEST_EGGS" = "x" ] && TEST_EGGS="awful pastiche chickadee" info Using $TMPDIR cd $TMPDIR download $uri && \ extract && \ cd $chicken_source_dirname && \ build && \ install && \ check && \ install_eggs && \ info "Everything looks ok!"