Remove already present XSL files from /etc/pazpar2
[pazpar2-moved-to-github.git] / perf / bash / pp2client.sh
1 #!/bin/sh
2
3 usage()
4 {
5     cat <<EOF
6 Usage: pp2client.sh [OPTIONS]
7 Options:                  Default values
8     [--prefix=URLPREFIX]  http://localhost:9004/search.pz2
9     [--query=QUERY]       water
10     [--service=SERVICE]
11     [--settings=SETTINGS]
12     [--outfile=OUTFILE]
13     [--timed]
14 EOF
15     exit 1
16 }
17 H=http://localhost:9004/search.pz2
18 SERVICE=""
19 SETTINGS=""
20 QUERY=water
21 OF=1
22 TIME=""
23
24 if test $# -eq 0; then 
25     usage
26     exit 0;
27 fi
28
29 while test $# -gt 0; do
30     case "$1" in
31         -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
32         *) optarg= ;;
33     esac
34     case $1 in
35         --prefix=*)
36           H=$optarg
37           ;;
38         --query=*)
39           QUERY=$optarg
40           ;;
41         --service=*)
42           SERVICE="&service=$optarg"
43           ;;
44         --settings=*)
45           SETTINGS="$optarg"
46           ;;
47         --outfile=*)
48           OF=$optarg
49           ;;
50         --timed)
51           TIME="yes"
52           ;;
53         -*)
54           usage
55           ;;
56     esac
57     shift
58 done
59
60 if [ "$TIME" != "" ] ; then
61     /usr/bin/time --format "$OF, init, %e" wget -q -O ${TMP_DIR}$OF.init.xml "$H/?command=init${SERVICE}"  2> ${TMP_DIR}$OF.init.time
62 else
63     wget -q -O ${TMP_DIR}$OF.init.xml "$H/?command=init${SERVICE}" 
64 fi
65
66 R="$?"
67 if [ "$R" != 0 ]; then
68     if [ "$R" = "4" ]; then    
69         echo "wget returned network error. Maybe Pazpar2 is not running at"
70         echo "$H"
71         exit 4
72     fi
73     echo "wget failed. Exit code $R"
74     exit 1
75 fi
76 S=`xsltproc get_session.xsl $OF.init.xml`
77 if [ -n "$SETTINGS" ] ; then
78     if [ "$TIME" != "" ] ; then
79         /usr/bin/time --format "$OF, settings, %e" wget -q -O ${TMP_DIR}$OF.settings.xml "$H?command=settings&session=$S&${SETTINGS}" 2> ${TMP_DIR}$OF.settings.time
80     else
81         wget -q -O ${TMP_DIR}$OF.settings.xml "$H?command=settings&session=$S&${SETTINGS}" 
82     fi
83 fi
84
85 if [ "$TIME" != "" ] ; then
86     /usr/bin/time --format "$OF, search, %e" wget -q -O ${TMP_DIR}$OF.search.xml "$H?command=search&query=$QUERY&session=$S" 2> ${TMP_DIR}$OF.search.time
87 else
88     wget -q -O ${TMP_DIR}$OF.search.xml "$H?command=search&query=$QUERY&session=$S"
89 fi
90 sleep 1
91 if [ "$TIME" != "" ] ; then
92     /usr/bin/time --format "$OF, show, %e" wget -q -O ${TMP_DIR}$OF.show.xml "$H?command=show&session=$S&sort=relevance&start=0&num=100&block=1" 2> ${TMP_DIR}$OF.show.time
93 else
94     wget -q -O ${TMP_DIR}$OF.show.xml "$H?command=show&session=$S&sort=relevance&start=0&num=100&block=1"
95 fi
96 wget -q -O ${TMP_DIR}$OF.bytarget.xml "$H?command=bytarget&session=$S"
97 wget -q -O ${TMP_DIR}$OF.stat.xml "$H?command=stat&session=$S"
98 wget -q -O ${TMP_DIR}$OF.info.xml "$H?command=info"
99 exit 0
100
101 # Local Variables:
102 # mode:shell-script
103 # sh-indentation: 2
104 # sh-basic-offset: 4
105 # End: