-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
160 lines (150 loc) · 4.06 KB
/
setup.sh
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
if [ $# -eq 2 ]
then
if ! [[ $1 == "--python-version" || $1 == "-p" ]]; then
echo -e "Parameter is not right\nUsage: setup.sh [--python-version|-p] [2.7|3.4|3.5]"
exit
fi
if ! [[ $2 == 2.7 || $2 == 3.4 || $2 == 3.5 ]]; then
echo -e "Python version is not right\n You can use python version 2.7, 3.4 and 3.5\nUsage: setup.sh [--python-version|-p] [2.7|3.4|3.5]"
exit
fi
INPUT_PYTHON_VERSION=$2
elif [ $# -eq 0 ]
then
INPUT_PYTHON_VERSION="0"
else
echo -e "Parameter is not right\nUsage: setup.sh [--python-version|-p] [2.7|3.4|3.5]"
exit
fi
CMAKE_LEAST="2.8.12"
GCC_LEAST="4.4.7"
vercomp() {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
checkpython() {
PYTHON2_VER=`python --version 2>&1 | cut -d" " -f2`
PYTHON3_VER=`python3 --version 2>&1 | cut -d" " -f2`
if [[ $1 == 0 ]]
then
echo "python version not specified,auto detecting..."
if [[ $PYTHON2_VER == 2.7* ]]
then
echo "Use python $PYTHON2_VER"
PYTHON_VERSION="2.7"
elif [[ $PYTHON3_VER == 3.4* ]]
then
echo "use python $PYTHON3_VER"
PYTHON_VERSION="3.4"
elif [[ $PYTHON3_VER == 3.5* ]]
then
echo "use python $PYTHON3_VER"
PYTHON_VERSION="3.5"
fi
elif [[ $1 == 2.7 ]]
then
if [[ $PYTHON2_VER == 2* ]]
then
echo "use python $PYTHON2_VER"
PYTHON_VERSION="2.7"
else
echo "Python 2.7 not found"
exit 1
fi
elif [[ $1 == 3.4 ]]
then
if [[ $PYTHON3_VER == 3.4* ]]
then
echo "use python $PYTHON3_VER"
PYTHON_VERSION="3.4"
else
echo "Python 3.4 not found"
exit 1
fi
elif [[ $1 == 3.5 ]]
then
if [[ $PYTHON3_VER == 3.5* ]]
then
echo "use python $PYTHON3_VER"
PYTHON_VERSION="3.5"
else
echo "Python 3.5 not found"
exit 1
fi
else
echo "Invalid python version specified"
exit 1
fi
}
GCC_VER=`gcc --version | head -n1 | cut -d" " -f4`
CMAKE_VER=`cmake --version | head -n1 | cut -d" " -f3`
vercomp $GCC_VER $GCC_LEAST
if [ $? -eq 2 ]
then
echo "gcc version too low (current:$GCC_VER,require:$GCC_LEAST)"
else
echo "gcc version check pass (current:$GCC_VER,require:$GCC_LEAST)"
fi
vercomp $CMAKE_VER $CMAKE_LEAST
if [ $? -eq 2 ]
then
echo "cmake version too low (current:$CMAKE_VER,require:$CMAKE_LEAST)"
else
echo "cmake version check pass (current:$CMAKE_VER,require:$CMAKE_LEAST)"
fi
checkpython $INPUT_PYTHON_VERSION
sudo apt-get update
sudo apt-get install -y cmake build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev python-dev python-smbus
if [[ $PYTHON_VERSION == 2.7 ]]; then
sudo apt-get install -y python-pip
else
sudo apt-get install -y python3-pip
fi
git clone https://github.com/Azure/azure-iot-sdk-python.git --recursive
cd azure-iot-sdk-python/build_all/linux
./setup.sh --python-version $PYTHON_VERSION
./build.sh --build-python $PYTHON_VERSION
cd ../../device/samples
cp iothub_client.so ../../../iothub_client.so
if [[ $PYTHON_VERSION == 2.7 ]]; then
sudo pip install RPi.GPIO
sudo pip install applicationinsights
else
sudo pip3 install RPi.GPIO
sudo pip3 install applicationinsights
fi
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
if [[ $PYTHON_VERSION == 2.7 ]]; then
sudo python setup.py install
else
sudo python3 setup.py install
fi
cd ..