Annotation of OpenXM/src/util/oxfetch.sh, Revision 1.8
1.1 ohara 1: #!/bin/sh
1.8 ! iwane 2: # $OpenXM: OpenXM/src/util/oxfetch.sh,v 1.7 2006/10/13 11:51:25 ohara Exp $
1.1 ohara 3:
1.4 ohara 4: MASTER_SITES="ftp://ftp.math.kobe-u.ac.jp/pub/OpenXM/misc/"
5: fetch="wget --no-directories --passive-ftp --timestamping"
1.1 ohara 6: url=$1
7: distdir=${2:-.}
1.5 ohara 8: distinfo=${3:-./distinfo}
1.1 ohara 9: distfile=`basename "$url"`
10:
11: _usage () {
1.2 ohara 12: echo 'usage: oxfetch URL [savedir] [distinfo]'
1.1 ohara 13: exit 1
14: }
15:
16: _mkdir () {
17: if [ ! -d "$1" ]; then
18: mkdir -p "$1"
19: fi
20: }
21:
22: _fetch () {
1.8 ! iwane 23: if [ "$distfile" != "" -a ! -f "$distdir/$distfile" ]; then
1.1 ohara 24: (cd $distdir; $fetch $url)
25: fi
26: }
27:
1.5 ohara 28: # usage: _md5grep gc6.2.tar.gz distinfo
29: _md5grep () {
1.2 ohara 30: if [ $# -gt 0 ]; then
1.5 ohara 31: awk '/^MD5 \('"$1"'\) =/{print $NF}' $2
32: fi
33: }
34:
35: _md5sum () {
1.7 ohara 36: md5.sh "$1" | awk '{print $NF}'
1.2 ohara 37: }
38:
1.6 takayama 39: _check() {
1.4 ohara 40: if [ ! -f "$distdir/$distfile" ]; then
1.5 ohara 41: echo "Error: ${distfile} not found."
1.4 ohara 42: exit 1
43: fi
1.2 ohara 44: if [ -f "$distinfo" ]; then
1.5 ohara 45: key1=`_md5sum "${distdir}/${distfile}"`
46: key2=`_md5grep "${distfile}" ${distinfo}`
1.2 ohara 47: if [ "$key1" = "$key2" ] ; then
1.1 ohara 48: echo "Checksum OK for $distfile".
1.5 ohara 49: elif [ -z "$key1" ]; then
50: echo "Warnig: no md5 checker."
1.1 ohara 51: else
1.5 ohara 52: echo "Error: checksum mismatch for $distfile".
1.3 ohara 53: exit 1
1.1 ohara 54: fi
55: fi
56: }
57:
58: if [ $# -eq 0 ]; then
59: _usage
60: fi
61:
62: _mkdir $distdir
63: _fetch
64: _check
1.3 ohara 65: exit 0
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>