Imported Upstream version 0.9.1
[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 CEREAL_DIR=iotivity/extlibs/cereal
32 if [ ! -d ${CEREAL_DIR} ]
33 then
34         git clone https://github.com/USCiLab/cereal.git ${CEREAL_DIR}
35         pushd ${CEREAL_DIR}
36         git reset --hard 7121e91e6ab8c3e6a6516d9d9c3e6804e6f65245
37         git apply ../../resource/patches/cereal_gcc46.patch
38         popd
39 fi
40
41 #######################################
42 # Android 
43 #######################################
44
45 echo "Set up Android NDK"
46 export ANDROID_NDK=${PWD}/iotivity/tools/android-ndk
47 if [ ! -d ${ANDROID_NDK} ]
48 then
49         mkdir -p ${ANDROID_NDK}
50         pushd ${ANDROID_NDK}
51         wget_if_not_exists "android-ndk-r10d-linux-x86_64.bin" http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin
52         chmod a+x android-ndk-r10d-linux-x86_64.bin
53         ./android-ndk-r10d-linux-x86_64.bin
54         popd
55 fi
56
57 echo "Set up Android NDK"
58 export ANDROID_SDK=${PWD}/iotivity/tools/android-sdk-linux
59 if [ ! -d ${ANDROID_SDK} ]
60 then
61         pushd iotivity/tools
62         cd ..
63         wget_if_not_exists "android-sdk_r24.0.2-linux.tgz" http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
64         tar -xzf http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
65         popd
66 fi
67
68 #######################################
69 # Arduino Dependencies
70 #######################################
71
72 # Arduino Mega
73 echo "Set up Arduino Mega"
74 export ARDUINO_MEGA_DIR=${PWD}/arduino-1.0.5
75 if [ ! -d ${ARDUINO_MEGA_DIR} ]
76 then
77         wget_if_not_exists "arduino-1.0.5-linux64.tgz" http://arduino.googlecode.com/files/arduino-1.0.5-linux64.tgz
78         tar -xzf arduino-1.0.5-linux64.tgz
79         wget_if_not_exists "Time-1.0.5.zip" http://playground.arduino.cc/uploads/Code/Time.zip
80         mv Time.zip Time-1.0.5.zip
81         mkdir -p ${ARDUINO_MEGA_DIR}/libraries/Time
82         pushd ${ARDUINO_MEGA_DIR}/libraries/Time
83         unzip ../../../Time-1.0.5.zip
84         cd ../..
85         patch -p5 < ../iotivity/tools/arduino/patches/arduino-1.0.5_linux.patch
86         popd
87 fi
88
89 # Arduino Due
90 echo "Set up Arduino Due"
91 ARDUINO_DUE_DIR=${PWD}/arduino-1.5.7
92 if [ ! -d ${ARDUINO_DUE_DIR} ]
93 then
94         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
95         tar -xzf "download.php?f=%2Farduino-1.5.7-linux64.tgz"
96         wget_if_not_exists "Time-1.5.7.zip" http://www.pjrc.com/teensy/arduino_libraries/Time.zip
97         mv Time.zip Time-1.5.7.zip
98         mkdir -p ${ARDUINO_DUE_DIR}/libraries/Time
99         pushd ${ARDUINO_DUE_DIR}/libraries/Time
100         unzip ../../../Time-1.5.7.zip
101         cd ../..
102         patch -p5 < ../iotivity/tools/arduino/patches/arduino-1.5.7_linux.patch
103         popd
104 fi
105
106 # local.properties
107 cat > iotivity/resource/csdk/local.properties <<EOF
108 ifeq (\$(PLATFORM), arduinomega)
109         #Location of arduino sdk for Arduino Mega
110         ARDUINO_DIR := ${ARDUINO_MEGA_DIR}
111         ARDUINO_TOOLS_DIR := \$(ARDUINO_DIR)/hardware/tools/avr/bin
112 else
113         #Location of arduino sdk for Arduino Due
114         ARDUINO_DIR := ${ARDUINO_DUE_DIR}
115         ARDUINO_TOOLS_DIR := \$(ARDUINO_DIR)/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin
116 endif
117 EOF