Parent: [4e780a] (diff)

Child: [e51447] (diff)

Download this file

upcmd.sh    76 lines (64 with data), 1.9 kB

 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
#!/bin/sh
# Script to control upmpdcli from the command line. Needs aux xml files to
# define the commands. Very few of this is specific upmpdcli-specific
# elements are noted by comments.
#
# The XML file names are like Servicename-ActionName The servicename part
# is only used to compute the service control url (which is specific to
# upmpdcli). The OpenHome service names themselves are special because
# upmpdcli prefixes them with OH (e.g. OHVolume instead of volume). So the
# whole service control url computation (and only it) would need changing
# for another renderer.
#
# LIMITATIONS:
# - does not work for parameter values containing whitespace
fatal()
{
echo $*;exit 1
}
usage()
{
fatal "Usage: upcmd.sh host:port service-action.xml [paramname value ...]\n
Examples:\n
upcmd.sh AVTransport-Play.xml\n
upcmd.sh OHVolume-SetVolume.xml Value 30\n
(look up the parameter names, this is not always 'Value')\n
"
}
test $# -ge 2 || usage
hostport=$1
shift
xml=$1
test -f "$xml" || fatal $xml does not exist
shift
sedcmd=''
while test $# -gt 0;do
name=$1
shift
test $# -gt 0 ||usage
value=$1
shift
sedcmd=$sedcmd" -e s/@$name@/$value/"
done
sa=`basename $xml .xml`
service=`echo $sa | awk -F- '{print $1}'`
action=`echo $sa | awk -F- '{print $2}'`
# Upmpdcli-specific: control url computation.
uribase=http://$hostport/ctl
ctluri=$uribase/$service
# End specific
if test "X$sedcmd" != "X"; then
postdata=`sed $sedcmd < $xml`
else
postdata=`cat $xml`
fi
#echo $postdata
serviceid=`grep xmlns:u $xml | \
awk '{print $2}' | \
sed -e 's/>//' -e 's/xmlns:u=//' -e 's/"//g'`
set -x
wget -O - \
--post-data="$postdata" \
--header 'SOAPACTION: "'$serviceid'#'$action'"' \
--header 'Content-Type: text/xml' \
$ctluri