Added Copyright header.
[src/xds/xds-server.git] / scripts / xds-utils / get-xds-agent.sh
1 #!/bin/bash
2  ###########################################################################
3 # Copyright 2017 IoT.bzh
4 #
5 # author: Sebastien Douheret <sebastien@iot.bzh>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
19
20 . /etc/xdtrc
21
22 [ -z "$XDS_AGENT_BASEURL" ] && XDS_AGENT_BASEURL="http://iot.bzh/download/public/2017/XDS/xds-agent/"
23 [ -z "$DEST_DIR" ] && DEST_DIR=./webapp/dist/assets/xds-agent-tarballs
24
25 # Fisrt check if we can access to iot.bzh (aka ovh.iot)
26 ping -c 1 -W 2 www.ovh.iot > /dev/null
27 if [ "$?" != "0" ]; then
28     echo "iot.bzh website not accessible !"
29     exit 1
30 fi
31
32 TARBALLS=$(curl -s ${XDS_AGENT_BASEURL} | grep -oP  'href="[^"]*.zip"' | cut -d '"' -f 2)
33
34 usage() {
35     echo "Usage: $(basename $0) [-h|--help] [-noclean] [-a|--arch <arch name>] [-l|--list]"
36         exit 1
37 }
38
39 do_cleanup=true
40 while [ $# -ne 0 ]; do
41     case $1 in
42         -h|--help|"")
43             usage
44             ;;
45         -l|--list)
46             echo "Available xds-agent tarballs:"
47             for t in $TARBALLS; do echo " $t"; done
48             exit 0
49             ;;
50         -noclean)
51             do_cleanup=false
52             ;;
53         *)
54             echo "Invalid argument: $1"
55             usage
56             ;;
57     esac
58     shift
59 done
60
61 if [ ! -d ${DEST_DIR} ]; then
62     echo "Invalid destination directory: ${DEST_DIR}"
63     exit 1
64 fi
65
66 # Get not existing tarballs
67 exitCode=0
68 for file in $TARBALLS; do
69     DESTFILE=${DEST_DIR}/${file}
70     if [ ! -f $DESTFILE ]; then
71         echo -n " Downloading ${file}... "
72         wget -q "${XDS_AGENT_BASEURL}/${file}" -O ${DESTFILE}
73         if [ "$?" != 0 ]; then
74             echo "ERROR"
75             exitCode=1
76         fi
77         echo "OK"
78     fi
79 done
80
81 exit $exitCode