aboutsummaryrefslogtreecommitdiffstats
path: root/runcheck
blob: d8095dd7d05b8bcebe7021875bd4bb7e264ff8ef (plain)
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
#!/bin/sh

basedir="$(cd $(dirname $0); pwd)"

set -e

file=urls-test.txt

if [ "$1" ] ; then
    file="$1"
fi

if [ ! -d har-data ]; then mkdir har-data ; fi
if [ ! -d kml-data ]; then mkdir kml-data ; fi
cat $file | while read url ; do
    case "$url" in
      http*)
        # Save with URL as filename, replacing / with % and dropping trailing slash.
        filename=$(echo "$url" | sed 's%/$%%' |tr / %)
        harfile="har-data/$filename.har"
        kmlfile="kml-data/$filename.kml"
        if [ ! -e "$harfile" ] ; then
            echo "testing $url"
            if phantomjs --ssl-protocol any $basedir/netsniff.js "$url" > "$harfile.new" &&
              [ -s "$harfile.new" ] &&
              [ "$(jq -r '.log | .entries | map(.request) | map(.url) | join("\n")'  $harfile.new)" ]; then
                mv "$harfile.new" "$harfile"
                $basedir/har2kml "$harfile" > $kmlfile
            else
                echo "error: unable to handle $url"
                if ! rm "$harfile.new" ; then
                    echo "error: unable to remove $harfile.new"
                fi
            fi
        else
            echo "info: not contacting "$url", already had $harfile"
        fi
        ;;
    esac
done