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

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

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

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