File: update-traces

package info (click to toggle)
bro 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,640 kB
  • sloc: ansic: 126,302; cpp: 95,205; yacc: 2,528; lex: 1,819; sh: 793; python: 700; makefile: 134
file content (80 lines) | stat: -rwxr-xr-x 1,548 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/env bash
#
# Downloads all traces as specified in <cwd>/traces.cfg to directory $1.
#
# traces.cfg must consist of lines of the form "<url> <md5sum>"

if [ "$1" == "" ]; then
    echo "usage: `basename $0` <traces-directory>"
    exit 1
fi

if [ ! -e $cfg ]; then
    echo "No $cfg found."
    exit 1
fi

cfg=traces.cfg

for p in .proxy ../.proxy; do
    if [ -e $p ]; then
        proxy=`cat $p | head -1 | awk '{print $1}'`
        echo Using proxy $proxy ...
        proxy="ALL_PROXY=$proxy"
        break
    fi
done

mkdir -p $1

cat $cfg | while read line; do

    if echo $line | grep -q '^[ \t]*$'; then
        continue
    fi

    if echo $line | grep -q '^[ \t]*#'; then
        continue
    fi

    url=`echo $line | awk '{print $1}'`
    auth=`echo $line | awk '{print $2}'`

    file=$1/`echo $url | sed 's#^.*/##g'`
    fp=$file.md5sum

    if [ "$auth" != "" ]; then
        auth="-u $auth"
    fi

    # Get the fingerprint file.
    if ! eval "$proxy curl $auth -fsS --anyauth $url.md5sum -o $fp.tmp"; then
        echo "Error: Could not get $url.md5sum, skipping download."
        continue
    fi

    download=0

    if [ -e $fp ]; then
        if ! cmp -s $fp $fp.tmp; then
            download=1
        fi
    else
       download=1
    fi

    if [ "$download" = "1" ]; then
        echo Getting $url ...
        echo
        eval "$proxy curl $auth -f --anyauth $url -o $file"
        echo
        mv $fp.tmp $fp
     #else
     #  echo "`basename $file` already available."
     fi

    rm -f $fp.tmp

done