bug #398 test (bug was resolved last night), and a script to download all bug attachm...
[cvc5.git] / contrib / get-bug-attachments
1 #!/bin/bash
2 #
3 # get-bug-attachments
4 # Morgan Deters <mdeters@cs.nyu.edu>
5 # Wed, 26 Sep 2012 09:40:10 -0400
6 #
7
8 if [ $# -lt 1 ]; then
9 echo "usage: `basename $0` bugids.." >&2
10 exit 1
11 fi
12
13 while [ $# -gt 0 ]; do
14
15 bugid="$1"
16 shift
17
18 function webcat {
19 if which wget &>/dev/null; then
20 wget -O - "$1"
21 elif which curl &>/dev/null; then
22 curl "$1"
23 else
24 echo "Please install wget or curl." >&2;
25 exit 1
26 fi
27 }
28
29 function webget {
30 if which wget &>/dev/null; then
31 tmpfile="$(mktemp)"
32 filename="$(wget -qS -O "$tmpfile" "$1" 2>&1 | grep 'Content-disposition: attachment' | sed 's,.*filename="\(.*\)".*,\1,')"
33 ext="$(echo "$filename" | sed 's,.*\.\(.*\),\1,')"
34 if [ -e "$2.$ext" ] && ! diff -q "$tmpfile" "$2.$ext" &>/dev/null; then
35 c=a
36 while [ -e "$2$c.$ext" ] && ! diff -q "$tmpfile" "$2$c.$ext" &>/dev/null; do
37 c=$(echo $c | tr a-y b-z)
38 done
39 mkdir -p "$(dirname "$2")"
40 mv "$tmpfile" "$2$c.$ext"
41 echo "$2$c.$ext"
42 else
43 mkdir -p "$(dirname "$2")"
44 mv "$tmpfile" "$2.$ext"
45 echo "$2.$ext"
46 fi
47 elif which curl &>/dev/null; then
48 mkdir -p "$(dirname "$2")"
49 curl "$1" >"$2"
50 else
51 echo "Please install wget or curl." >&2;
52 exit 1
53 fi
54 }
55
56 count=0
57 for attachment in $(\
58 webcat "http://church.cims.nyu.edu/bugs/show_bug.cgi?id=$bugid" 2>/dev/null \
59 | grep ' href="attachment.cgi?id=[0-9][0-9]*' \
60 | sed 's,.* href="attachment.cgi?id=\([0-9][0-9]*\).*,\1,' \
61 | sort -nu); do
62
63 let count++
64 echo -n "Downloading attachment $attachment..."
65 webget "http://church.cims.nyu.edu/bugs/attachment.cgi?id=$attachment" "test/regress/regress0/bug$bugid"
66
67 done
68
69 if [ $count -eq 0 ]; then
70 echo "There are no bug testcase attachments for bug #$bugid."
71 else
72 echo "Downloaded $count bug testcases for bug #$bugid."
73 fi
74
75 done