Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / tools / vagrant / iotivity-setup.sh
1 #!/bin/bash
2
3 # User ID to use with git
4 GIT_USER=$1
5
6 function die {
7         echo $1
8         exit 255
9 }
10
11 # if file $1 does not exist, call wget on $2
12 function wget_if_not_exists {
13         test -f $1 || wget -q $2 || die "$1 does not exist and wget failed for $2"
14 }
15
16 # If you are behind a proxy, add all the environment variables required to
17 # set the proxy appropriately for your environment.
18 #source /vagrant/proxy_config
19
20 # Protect the private key for better security (and so that ssh will work)
21 chmod 600 .ssh/id_rsa
22
23 # Cannot use repo directory on host if host is Windows, because
24 # Windows does not handle symlinks properly
25 if [ ! -d "iotivity" ]
26 then
27         git clone ssh://${GIT_USER}@gerrit.iotivity.org/iotivity || die "git failed"
28         scp -p -P 29418 ${GIT_USER}@gerrit.iotivity.org:hooks/commit-msg iotivity/.git/hooks/
29 fi
30
31 export TINYCBOR_DIR=iotivity/extlibs/tinycbor
32 if [ ! -d ${CEREAL_DIR} ]
33 then
34         git clone https://github.com/01org/tinycbor ${CEREAL_DIR}
35 fi
36
37 #######################################
38 # Android
39 #######################################
40
41 echo "Set up Android NDK"
42 export ANDROID_NDK=${PWD}/iotivity/tools/android-ndk
43 if [ ! -d ${ANDROID_NDK} ]
44 then
45         mkdir -p ${ANDROID_NDK}
46         pushd ${ANDROID_NDK}
47         wget_if_not_exists "android-ndk-r10d-linux-x86_64.bin" http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin
48         chmod a+x android-ndk-r10d-linux-x86_64.bin
49         ./android-ndk-r10d-linux-x86_64.bin
50         popd
51 fi
52
53 echo "Set up Android NDK"
54 export ANDROID_SDK=${PWD}/iotivity/tools/android-sdk-linux
55 if [ ! -d ${ANDROID_SDK} ]
56 then
57         pushd iotivity/tools
58         cd ..
59         wget_if_not_exists "android-sdk_r24.0.2-linux.tgz" http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
60         tar -xzf http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
61         popd
62 fi
63
64 #######################################
65 # Arduino Dependencies
66 #######################################
67
68 # Arduino Mega
69 echo "Set up Arduino Mega"
70 export ARDUINO_MEGA_DIR=${PWD}/arduino-1.0.5
71 if [ ! -d ${ARDUINO_MEGA_DIR} ]
72 then
73         wget_if_not_exists "arduino-1.0.5-linux64.tgz" http://arduino.googlecode.com/files/arduino-1.0.5-linux64.tgz
74         tar -xzf arduino-1.0.5-linux64.tgz
75         wget_if_not_exists "Time-1.0.5.zip" http://playground.arduino.cc/uploads/Code/Time.zip
76         mv Time.zip Time-1.0.5.zip
77         mkdir -p ${ARDUINO_MEGA_DIR}/libraries/Time
78         pushd ${ARDUINO_MEGA_DIR}/libraries/Time
79         unzip ../../../Time-1.0.5.zip
80         cd ../..
81         patch -p5 < ../iotivity/tools/arduino/patches/arduino-1.0.5_linux.patch
82         popd
83 fi
84
85 # Arduino Due
86 echo "Set up Arduino Due"
87 ARDUINO_DUE_DIR=${PWD}/arduino-1.5.7
88 if [ ! -d ${ARDUINO_DUE_DIR} ]
89 then
90         wget_if_not_exists "download.php?f=%2Farduino-1.5.7-linux64.tgz" http://arduino.cc/download.php?f=/arduino-1.5.7-linux64.tgz
91         tar -xzf "download.php?f=%2Farduino-1.5.7-linux64.tgz"
92         wget_if_not_exists "Time-1.5.7.zip" http://www.pjrc.com/teensy/arduino_libraries/Time.zip
93         mv Time.zip Time-1.5.7.zip
94         mkdir -p ${ARDUINO_DUE_DIR}/libraries/Time
95         pushd ${ARDUINO_DUE_DIR}/libraries/Time
96         unzip ../../../Time-1.5.7.zip
97         cd ../..
98         patch -p5 < ../iotivity/tools/arduino/patches/arduino-1.5.7_linux.patch
99         popd
100 fi
101
102 # local.properties
103 cat > iotivity/resource/csdk/local.properties <<EOF
104 ifeq (\$(PLATFORM), arduinomega)
105         #Location of arduino sdk for Arduino Mega
106         ARDUINO_DIR := ${ARDUINO_MEGA_DIR}
107         ARDUINO_TOOLS_DIR := \$(ARDUINO_DIR)/hardware/tools/avr/bin
108 else
109         #Location of arduino sdk for Arduino Due
110         ARDUINO_DIR := ${ARDUINO_DUE_DIR}
111         ARDUINO_TOOLS_DIR := \$(ARDUINO_DIR)/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin
112 endif
113 EOF