-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdk2Galileo.sh
executable file
·327 lines (310 loc) · 7.82 KB
/
sdk2Galileo.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/bash
########################################
# define help message #
########################################
thisFile=`basename $0`
read -d '' help <<- EOF
Usage: ./$thisFile
options:
-m mode [default is copy]
[copy | configure | get]
-h display this message
## The following flags are only valid in copy mode ##
-f files to copy [default is all]
[all | ndn-cxx | nfd | cryptopp | conf]
-a copy everything [default]
-l copy libraries
-b copy binaries
-i copy headers
EOF
########################################
# Set default values #
########################################
target='all'
part='all'
mode='copy'
read -d '' initScript <<- EOF
opkg update;
opkg install --force-overwrite uclibc;
opkg install vim git;
opkg install pkgconfig openssl sqlite3;
EOF
imageURL='http://sourceforge.net/projects/ndn-in-one/files/image.tar.gz'
rootURL='http://sourceforge.net/projects/ndn-in-one/files/root.tar.gz'
response=n
port=22
########################################
# detect operating system #
########################################
function detectOS
{
if [ "$OSTYPE" == "linux-gnu" ]
then
sedFlag='-i '
echo "operating system: linux"
elif [[ $OSTYPE == darwin* ]]
then
sedFlag="-i '' "
echo "operating system: darwin"
else
echo "un-recognized operating system"
exit
fi
}
########################################
# get options #
########################################
function getOptions
{
if [ $# -eq 0 ]
then
echo "$help"
exit
fi
while getopts ":m:f:albih" opt
do
case $opt in
m)
if [ "$OPTARG" = "copy" ]
then
mode='copy'
elif [ "$OPTARG" = "configure" ]
then
mode='configure'
elif [ "$OPTARG" = "get" ]
then
mode='get'
else
echo "option -$opt must be one of [copy | configure]"
echo "$help"
exit
fi
;;
f)
if [ "$OPTARG" = "all" ]
then
target='all'
elif [ "$OPTARG" = "ndn-cxx" ]
then
target='ndn-cxx'
elif [ "$OPTARG" = "nfd" ]
then
target='nfd'
elif [ "$OPTARG" = "cryptopp" ]
then
target='cryptopp'
elif [ "$OPTARG" = "conf" ]
then
target='conf'
else
echo "option -$opt must be one of [all, ndn-cxx, nfd, cryptopp, conf]"
echo "$help"
exit
fi
;;
a)
part='all'
;;
l)
part='library'
;;
b)
part='binary'
;;
i)
part='header'
;;
h)
echo "$help"
exit
;;
:)
echo "option -$OPTARG requires an argument"
echo "$help"
exit
;;
\?)
echo un-recognized option
echo "$help"
exit
;;
esac
done
}
########################################
# get : get image or toolchain #
########################################
function get {
if [ -z $3]
then
getHelp=true
else
if [ $3 = "image" ]
then
echo "getting galileo image... get a cup of tea..."
wget $imageURL
getHelp=false
elif [ $3 = "ndn" ]
then
echo "getting all the ndn/nfd headers, libraries, and binaries..."
wget $rootURL
getHelp=false
else
getHelp=true
fi
fi
if [ $getHelp == true ]
then
echo " Usage: ./$thisFile -m get [image | ndn]"
echo " to obtain Galileo's linux image:"
echo " ./$thisFile -m get image"
echo " to obtain ndn/nfd's headers, libraries, and binaries"
echo " ./$thisFile -m get ndn"
exit
fi
}
########################################
# setupToolchain detect and setup tool #
########################################
function setupToolchain {
if [ -e root.tar.gz ]
then
echo "detecting tool chain installed in" `pwd`
printf "do you want to use this toolchain? [y]"
read response
if [ $response == y ]
then
if [ -e root ]
then
:
else
echo "decompressing tool chain"
tar -xzvf root.tar.gz
fi
response='root'
fi
fi
if [ $response != root ]
then
if [ -e /opt/ndn/environment-setup-i586-poky-linux-uclibc ]
then
echo "detecting tool chain installed in /opt/ndn"
printf "do you want to use this toolchain? [y]"
read response
if [ $response == y ]
then
echo "continuing....."
source /opt/ndn/environment-setup-i586-poky-linux-uclibc
response=yocto
else
printf "download headers, libraries, and binaries? [y]"
read response
fi
else
echo "can not detect toolchain, download headers, libraries, and binaries? [y]"
read response
fi
fi
if [ $response == y ]
then
wget $rootURL
tar -xzvf root.tar.gz
cd root
export PKG_CONFIG_SYSROOT_DIR=`pwd`
elif [ $response == root ]
then
cd root
export PKG_CONFIG_SYSROOT_DIR=`pwd`
elif [ $response == yocto ]
then
:
else
echo "Good bye then~"
exit
fi
}
########################################
# Wrapper function #
########################################
function Scp {
scp -P $port "$@"
}
########################################
# GetIP : get ssh IP and port #
########################################
function getIP {
printf "Enter your Galileo IP(deault port is 22, change it by entering IP:port): "
read GalileoIP
t=`echo $GalileoIP | cut -d ":" -f2`
if [ $t != $GalileoIP ]
then
GalileoIP=`echo $GalileoIP | cut -d ":" -f1`
port=$t
fi
}
########################################
# main program #
########################################
getOptions "$@"
if [ $mode == get ]
then
get "$@"
exit
fi
if [ $mode == copy ]
then
setupToolchain
cd $PKG_CONFIG_SYSROOT_DIR
echo "switching directory to $PKG_CONFIG_SYSROOT_DIR"
fi
if [ $mode == copy ]
then
echo "Transfering $part of $target"
getIP
if [ $target == "cryptopp" -o $target == all ]
then
echo "Moving cryptopp headers to $GalileoIP"
Scp -r include/cryptopp root@$GalileoIP:/include
echo "Moving cryptopp libraries to $GalileoIP"
Scp lib/libcryptopp.so root@$GalileoIP:/lib
fi
if [ $target == "ndn-cxx" -o $target == all ]
then
echo "Moving ndn-cxx headers to $GalileoIP"
Scp -r usr/include/ndn-cxx root@$GalileoIP:/usr/include
echo "Moving ndn-cxx libraries to $GalileoIP"
Scp usr/lib/libndn-cxx.a root@$GalileoIP:/usr/lib
echo "Moving ndn binaries to $GalileoIP"
Scp -r usr/bin/ndn* root@$GalileoIP:/bin
fi
if [ $target == "nfd" -o $target == all ]
then
echo "Moving nfd binaries to $GalileoIP"
Scp -r usr/bin/nfd* root@$GalileoIP:/bin
fi
if [ $target == "conf" -o $target == all ]
then
echo "Moving /usr/etc/ndn startup scripts to $GalileoIP"
ssh -p $port root@$GalileoIP 'mkdir -p /opt/ndn/sysroots/i586-poky-linux-uclibc/usr/etc/'
Scp -r usr/etc/ndn root@$GalileoIP:/opt/ndn/sysroots/i586-poky-linux-uclibc/usr/etc/
Scp -r usr/etc/ndn root@$GalileoIP:/opt/ndn/sysroots/i586-poky-linux-uclibc/usr/etc/
echo "Moving base-feeds.conf startup scripts to $GalileoIP"
echo "src/gz all http://repo.opkg.net/galileo/repo/all" > base-feeds.conf
echo "src/gz clanton http://repo.opkg.net/galileo/repo/clanton" >> base-feeds.conf
echo "src/gz i586 http://repo.opkg.net/galileo/repo/i586" >> base-feeds.conf
Scp base-feeds.conf root@$GalileoIP:/etc/opkg/
rm -f base-feeds.conf
fi
echo "========== copying complete ========="
fi
if [ $mode == configure ]
then
getIP
echo "The following commands will be run:"
echo $initScript
echo $initScript | xargs ssh -p $port root@$GalileoIP
echo "customizing nfd-start"
Scp nfd-start root@$GalileoIP:/bin
echo "customizing nfd-stop"
Scp nfd-stop root@$GalileoIP:/bin
fi