[BACK]Return to oxfetch.sh CVS log [TXT][DIR] Up to [local] / OpenXM / src / util

Annotation of OpenXM/src/util/oxfetch.sh, Revision 1.5

1.1       ohara       1: #!/bin/sh
1.5     ! ohara       2: # $OpenXM: OpenXM/src/util/oxfetch.sh,v 1.4 2004/06/30 10:14:10 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 () {
                     23:     if [ "distfile" != "" -a ! -f "$distdir/$distfile" ]; then
                     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 () {
        !            36:     if [ "`which md5`" ]; then
        !            37:         md5 "$1" | awk '{print $NF}'
        !            38:     elif [ "`which md5sum`" ]; then
        !            39:         md5sum "$1" | awk '{print $1}'
1.2       ohara      40:     fi
                     41: }
                     42:
1.1       ohara      43: _check () {
1.4       ohara      44:     if [ ! -f "$distdir/$distfile" ]; then
1.5     ! ohara      45:         echo "Error: ${distfile} not found."
1.4       ohara      46:         exit 1
                     47:     fi
1.2       ohara      48:     if [ -f "$distinfo" ]; then
1.5     ! ohara      49:         key1=`_md5sum  "${distdir}/${distfile}"`
        !            50:         key2=`_md5grep "${distfile}" ${distinfo}`
1.2       ohara      51:         if [ "$key1" = "$key2" ] ; then
1.1       ohara      52:             echo "Checksum OK for $distfile".
1.5     ! ohara      53:         elif [ -z "$key1" ]; then
        !            54:             echo "Warnig: no md5 checker."
1.1       ohara      55:         else
1.5     ! ohara      56:             echo "Error: checksum mismatch for $distfile".
1.3       ohara      57:             exit 1
1.1       ohara      58:         fi
                     59:     fi
                     60: }
                     61:
                     62: if [ $# -eq 0 ]; then
                     63:     _usage
                     64: fi
                     65:
                     66: _mkdir $distdir
                     67: _fetch
                     68: _check
1.3       ohara      69: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>