Skip to content

Instantly share code, notes, and snippets.

@iki

iki/get-kamaelia.sh

Created Nov 27, 2009
Embed
What would you like to do?
#!/bin/sh
VER=0.9.8.0
MD5=13c5539712041c80b1a9ec65515694fd
APP=Kamaelia-$VER
PKG=Original-$APP-with-Axon.tar.gz
URL=http://www.kamaelia.org/release/MonthlyReleases/$APP.tar.gz
DST=dist-external
if [ "$OS" = "Windows_NT" ]; then
### this script runs happily with http://gnuwin32.sf.net,
### but we need to use bsdtar for compressed tar files.
tar() { bsdtar "$@"; return $?; }
fi
md5check() { ### filename, md5hash, [md5file], [error_message]
[ ! -f "$1" ] && echo "$0: cannot find '$1'" >&2 && return 1
local MDF=${3:-$1.md5}
[ ! -e "$MDF" ] && echo "$2 *`basename "$1"`" > "$MDF" && touch -r "$1" "$MDF"
echo "$2 *$1" | md5sum -c || { local R=$?; [ -n "$4" ] && echo "$0: $4" >&2; return $R; }
}
get() { ### url, target, md5hash, [md5_mismatch_message]
[ -f "$2" ] && md5check "$2" "$3" && return 0
wget -O "$2" "$1" || return $?
md5check "$2" "$3" "$4" || return $?
}
get_last_file() { ### [directory], [grep_pattern_filemask]
local L
L=`ls -1 "$1" | grep "$2" | tail -n1`
[ -n "$L" -a -e "${1:+$1/}$L" ] || { echo "$0: no file matching regexp '${2:-.*}' in '${1:-.}' found" >&2; return 1; }
echo "${1:+$1/}$L"
}
make_tbz() { ### [name]
echo "** building $1 tar.bz package" >&2
if [ "$1" != "Axon" ]; then
sed -i "s/\(^ *\)\(packages *= *\[\)/\1install_requires=['Axon >= 1.5.1'],\n\1\2/" setup.py || return $?
fi
python setup.py sdist --formats=bztar >&2 || return $?
get_last_file dist "$1-.*\.tar\.bz" || return $?
}
split_package() { ### package, context, command, destdir, check_extension, [subpackages]
local PKG CTX CMD DST TMP SUB RET OWD
PKG="$1"; shift;
CTX="${1:-.}"; shift;
CMD="$1"; shift;
DST="${1:-${PKG%/*}}"; shift; ### use package dir if destdir is empty
EXT="$1"; shift;
[ -n "$PKG" -a -f "$PKG" ] || { echo "$0: package not found: '$PKG'" >&2; return 1; }
[ -n "$DST" -a -d "$DST" ] || { echo "$0: invalid destination: '$DST'" >&2; return 1; }
[ -n "$CMD" ] || { echo "$0: invalid command: '$CMD'" >&2; return 1; }
TMP="`mktemp -d`" || return $?
STS= ### empty - noop, 0 - unpacked ok, 1 - error
OWD="`pwd`"
while [ -n "$1" ]; do
[ -n "$EXT" ] && SUB="`get_last_file "$DST" "$1.*$EXT" 2>/dev/null`" \
&& echo "** subpackage $1 already exists: $SUB" >&2 && shift && continue
[ -z "$STS" ] && { echo "** extracting '$PKG'" >&2 \
&& tar xf "$PKG" -C "$TMP" && STS=0 || { STS=1; break; }; }
[ ! -d "$TMP/$CTX/$1" ] && echo "-- subpackage $1 not found" >&2 && shift && continue
cd "$TMP/$CTX/$1" && SUB="`"$CMD" "$1"`" \
&& cd "$OWD" && mv -t "$DST" "$TMP/$CTX/$1/$SUB" && touch -r "$PKG" "$DST/${SUB##*/}" \
|| { echo "!! subpackage $1 processing failed" >&2; STS=1; }
shift
done
cd "$OWD" || STS=1
[ -n "$STS" ] && echo "** removing extracted files" >&2
rm -rf "$TMP" || STS=1
return $STS
}
[ -d "$DST" ] || mkdir -p "$DST" || exit $?
get "$URL" "$DST/$PKG" "$MD5" || exit $?
split_package "$DST/$PKG" "$APP" make_tbz "$DST" .tar.bz Axon Kamaelia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment