import repository from arizona
[raven.git] / 2.0 / plush / gen-update.sh
1 #!/bin/sh
2
3 # <Purpose>
4 # Generate a PLuSH XML experiment file that will cause PLuSH to download
5 # the latest metadata file from the stork repository.  To do this, this script
6 # will also create a directory.xml file (needed by PLuSH to connect to PlanetLab
7 # nodes) and will download and compress the metadata file from the repository.
8 #
9 # Slice hostnames should be entered as arguments.
10
11 # get the username
12 USERNAME=$1
13
14 # get directory output
15 DIRECTORY=$2
16
17 # get experiment file
18 EXPERIMENT=$3
19
20 # metadata file
21 METADATA="/tmp/metadata"
22
23 # metadata url
24 METADATA_URL="https://stork-repository.cs.arizona.edu/packageinfo/metafile"
25
26 if [[ $USERNAME == "-h" || $USERNAME == "--help" || $USERNAME == "" || $DIRECTORY == "" || $EXPERIMENT == "" ]]; then
27      echo "Usage: <username> </path/to/metadata/file> </path/to/directory.xml> </path/to/plush/update/file.xml> [HOST]..."
28      echo "PlanetLab hostnames HOST are in the format"
29      echo "     SLICE@HOSTNAME:PORTNUM"
30      echo "and should be passed in as arguments"
31      exit 1
32 fi
33
34 # check write permissions
35 touch $DIRECTORY 2>/dev/null || (( echo "Insufficient write permissions" && exit 1 ))
36
37 # remove the file
38 rm -f $DIRECTORY 2>/dev/null || (( echo "Insufficient write permissions" && exit 1 ))
39
40 # test metadata write permissions
41 touch $METADATA 2>/dev/null || (( echo "Insufficient write permissions" && exit 1 ))
42
43 # remove old metadata
44 rm -f $METADATA 2>/dev/null || (( echo "Insufficient write permissions" && exit 1 ))
45
46 # get metadata
47 wget -c $METADATA_URL -O $METADATA || (( echo "Failed to download metadata" && exit 1 ))
48
49 # compress metadata
50 tar cf $METADATA.tar $METADATA || (( echo "Failed to compress metadata" && exit 1 ))
51
52 # create PlanetLab directory listing
53 cat > $DIRECTORY <<DIR_END1
54 <?xml version=1.0 encoding=UTF-8?>
55 <plush>
56     <resource_manager type=planetlab>
57          <user>$USERNAME</user>
58          <allsites>allsites.xml</allsites>
59 DIR_END1
60
61 # read remaining arguments (hostnames)
62 shift 3
63
64 # count hosts
65 HOSTCOUNT=0
66
67 # slice names
68 SLICES=
69
70 for host in $@; do 
71    # get hostname
72    hostname=$(echo $host | sed 's/\([a-zA-Z0-9_-.]*@[a-zA-Z0-9_-.]*:\).*/\1/' | sed 's/://g')
73
74    # get portnum
75    portnum=$(echo $host | sed 's/.*:\([0-9]*\)/\1/')
76
77    # save slice
78    SLICES[$HOSTCOUNT]=$hostname
79
80    echo "         <port_map slice=\"$hostname\" port=\"$portnum\"/>" >> $DIRECTORY
81    HOSTCOUNT=$((HOSTCOUNT + 1))
82 done
83
84 # finish writing directory file
85 cat >> $DIRECTORY <<END_DIR2
86     </resource_manager>
87     <resource_manager type="ssh">
88     </resource_manager>
89 </plush>
90 END_DIR2
91
92 # create the experiment file
93 test -f $EXPERIMENT && rm -f $EXPERIMENT
94
95 cat > $EXPERIMENT <<END1
96 <?xml version="1.0" encoding="utf-8"?>
97 <plush>
98    <project name="metadata">
99        <software name="get-metadata" type="none">
100          <package name="package1" type="tar">
101            <path>$METADATA.tar</path>
102          </package>
103        </software>
104        <component name="mynodes">
105             <rspec>
106               <num_hosts>$HOSTCOUNT</num_hosts>
107             </rspec>
108        <software name="get-metadata" />
109           <resources>
110 END1
111
112 # copy in resources
113 for slice_index in $(seq 0 $((HOSTCOUNT-1))); do
114    echo "            <resource type=\"planetlab\" group=\"${SLICES[$slice_index]}\"/>" >> $EXPERIMENT
115 done
116
117 # copy in remainder of file
118 cat >> $EXPERIMENT <<END2
119          </resources>
120      </component>
121      <experiment name="download-metadata">
122         <execution>
123            <component_block name="cb1">
124               <component name="mynodes" />
125                 <process_block name="p2">
126                    <process name="echo">
127                       <path>/bin/echo</path>
128                       <cmdline>
129                          <arg>"Run success"</arg>
130                       </cmdline>
131                       <cwd/>
132                    </process>
133                 </process_block>
134             </component_block>
135         </execution>
136      </experiment>
137   </project>
138 </plush>
139 END2
140