UNPKG

25.3 kBapplication/x-shView Raw
1#!/bin/bash
2
3SDK_URL="http://sdk.insyber.com/Releases_Syberos_Pdk/"
4Target_URL="http://sdk.insyber.com/Releases_Syberos_Pdk/"
5declare -a target_package_array
6declare -A arch_branch_array
7
8SDKDIR="sdk/sdk-root"
9DOWNLOAD_OUTPUT="/tmp"
10
11function Usage()
12{
13 local command_name=$(basename $0)
14
15 echo\
16 "
17 ${command_name} -- script to automatically install platform sdk and sb2 target
18 default install target is main_dev,can change it.
19 ========pdk is platform sdk====================
20
21 options:
22 --help show help info
23 --arch sb2 arch target(armv7tnhl or i686)
24 --branch target branch name, default main_dev. (main_dev or xuanwu,miit_cert,product_lily,ginkgo_millet,product_rockchip)
25 --sdk-package path of sdk installation pacakge,
26 support local package and remote package (http, ftp)
27 --target-package path of sb2 target installation package,
28 support local package and remote package (http, ftp)
29 --sdk-install-path path to install sdk(若用户没有定义,默认安装路径为~/Syberos-Pdk)
30 --target-install-path path to install sb2 target
31 --sdk-alias-name name to write alias command in ~/.bashrc
32 --only-install-target only install sb2 target
33 --sudo-password sudo password
34 --silent slient mode
35
36 参数:
37 --help 显示帮助信息
38  --arch target的架构平台,可选参数(armv7tnhl or i686)
39 --branch target的分支名,可选参数(main_dev or xuanwu,miit_cert,product_lily,ginkgo_millet)
40 --sdk-package sdk的安装包路径,可选择本地路径的安装包,也支持http和ftp的安装包
41  --target-package target的安装包路径,可选择本地路径的安装包,也支持http和ftp的安装包
42 --sdk-install-path sdk的安装路径(若用户没有定义,默认安装路径为~/Syberos-Pdk)
43  --target-install-path target的安装路径
44 --sdk-alias-name 定义别名,写入~/.bashrc
45 --only-install-target 只安装target (主要用于从服务器上下包时,该参数可用)
46  --sudo-password sudo时的密码
47 --silent 静默模式
48 "
49}
50function DownloadFile()
51{
52 echo "Downloading..... please wait...."
53 local fromurl=$1
54 local user=$2
55 local password=$3
56
57 local excmd="wget --timeout=12 --tries=3 --no-check-certificate --timestamping -P /tmp"
58 [ "x${user}" != "x" ] && excmd="${excmd} --user=${user}"
59 [ "x${password}" != "x" ] && excmd="${excmd} --password=${password}"
60 excmd="${excmd} ${fromurl}"
61 eval ${excmd}
62
63 return $?
64}
65
66function ReadPassword()
67{
68 if [ "x" == "x${sudo_password}" ]; then
69 read -s -p "请输入当前用户名的密码:" sudo_password
70 fi
71}
72
73function sudoExec()
74{
75 expect <<_EOF_
76 log_user 1
77 set timeout 30000
78 spawn sudo $@
79 expect {
80 "(yes/no)?" {send "yes\r"; exp_continue}
81 "password" {send -- "${sudo_password}\r"; exp_continue}
82 "密码" {send -- "${sudo_password}\r"; exp_continue}
83 eof {}
84 }
85 catch wait result
86 exit [lindex \$result 3]
87_EOF_
88}
89
90function SudoExec()
91{
92
93 if [ "x" == "x${sudo_password}" ]; then
94 echo "password is null"
95 exit 1
96 else
97 echo $sudo_password|sudo -S $@
98 fi
99
100}
101
102function read_config_file()
103{
104 while read line
105 do
106 TITLE_NAME=${line%%=*}
107 if [ "$TITLE_NAME"x == "sdk-version"x ];then
108 sdk_version=${line##*=}
109 break
110 fi
111 if [ "$TITLE_NAME"x == "target-version"x ];then
112 target_version=${line##*=}
113 break
114 fi
115 done < $1
116 return 0
117}
118function ParseVersion()
119{
120 local file=$1
121 read_config_file $file
122
123
124}
125function PreInstallSDK()
126{
127 local ret
128
129 if [[ ${sdk_package} =~ (^http://|^ftp://) ]]; then
130
131 if [ ${sdk_package_flag} -ne 1 ];then
132 DownloadFile ${SDK_URL%/}/sdk-${sdk_branch}/sdk-version-${sdk_branch}.txt
133 ParseVersion $DOWNLOAD_OUTPUT/sdk-version-${sdk_branch}.txt
134 sdk_package=${SDK_URL%/}/sdk-${sdk_branch}/syberos_sdk-${sdk_branch}-build${sdk_version}.tar.bz2
135 fi
136 DownloadFile ${sdk_package}
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 echo "download SDK package ${sdk_package} fail"
140 exit 1
141 fi
142 echo "download SDK package ${sdk_package} ok"
143 sdk_package=$DOWNLOAD_OUTPUT/$(basename ${sdk_package})
144 else
145 if [ ! -f ${sdk_package} ]; then
146 echo "SDK package ${sdk_package} not exists"
147 exit 1
148 fi
149 fi
150
151
152 return 0
153}
154
155function SelectAnotherPath()
156{
157 local oldpath=$1
158 local overwrite=
159 local newvalue=
160 local message=$2
161
162 sdk_install_path=$oldpath
163 if [ ! -d ${sdk_install_path} ]; then
164 SudoExec mkdir -p ${sdk_install_path}
165 if [ $? -ne 0 ]; then
166 echo "mkdir ${sdk_install_path} fail"
167 exit 1
168 fi
169 else
170 SudoExec rm -rf ${oldpath%/}/*
171 if [ $? -ne 0 ]; then
172 echo "rm ${sdk_install_path}/* fail,Device is busy!!!"
173 exit 1
174 fi
175 fi
176}
177
178function silentModeCreatInstallSDKPath()
179{
180 local InstallPath=$1
181 if [ -d $InstallPath ]; then
182 SudoExec rm ${InstallPath%/}/* -rf
183 fi
184 SudoExec mkdir -p $InstallPath
185}
186
187function InstallSDK()
188{
189 if [ $silent_flag -eq 1 ]; then
190 silentModeCreatInstallSDKPath $sdk_install_path
191 else
192 if [ ! -d ${sdk_install_path} ]; then
193 SelectAnotherPath ${sdk_install_path} "是否安装在默认路径下${sdk_install_path}"
194 else
195 SelectAnotherPath ${sdk_install_path} "${sdk_install_path}已经存在,是否覆盖"
196 fi
197 fi
198
199 if [ -f ${HOME}/.config/qtversions.conf ]; then
200 rm ${HOME}/.config/qtversions.conf
201 fi
202
203 if [ -d ${HOME}/.scratchbox2 ]; then
204 SudoExec rm -rf ${HOME}/.scratchbox2
205 fi
206
207 if [ ${target_install_path_flag} -ne 1 ]; then
208 target_install_path="${sdk_install_path%/}/targets"
209 fi
210
211 echo "being Install ${sdk_package}......"
212 SudoExec tar --numeric-owner -p -xjf ${sdk_package} -C ${sdk_install_path}
213 [ $? -ne 0 ] && echo "extract ${sdk_package} fail" && exit 1
214
215 SudoExec chown -R $USER ${sdk_install_path%/}/
216 my_uid=$(echo $(id -u))
217 sed -i "/^[^:]*:[^:]*:${my_uid}/d" ${sdk_install_path%/}/$SDKDIR/etc/passwd
218 SudoExec chown -R root:root ${sdk_install_path%/}/$SDKDIR
219 SudoExec chmod u+s ${sdk_install_path%/}/$SDKDIR/usr/bin/sudo
220
221 if [ -f ${sdk_install_path%/}/sdk/script/kchroot ]; then
222 SudoExec chown -R root:root ${sdk_install_path%/}/sdk/script/kchroot
223 SudoExec chmod u+s ${sdk_install_path%/}/sdk/script/kchroot
224 fi
225
226 if [ -f ${sdk_install_path%/}/sdk/script/uninstall_bin ]; then
227 SudoExec chown -R root:root ${sdk_install_path%/}/sdk/script/uninstall_bin
228 SudoExec chmod u+s ${sdk_install_path%/}/sdk/script/uninstall_bin
229 if [ -f ${sdk_install_path%/}/sdk/uninstall ]; then
230 SudoExec rm -f ${sdk_install_path%/}/sdk/uninstall
231 fi
232 SudoExec ln -s ${sdk_install_path%/}/sdk/script/uninstall_bin ${sdk_install_path%/}/sdk/uninstall
233 fi
234
235 [ ! -f ${sdk_install_path%/}/$SDKDIR/syberos-sdk-chroot ] && \
236 echo "${sdk_install_path%/}/$SDKDIR/syberos-sdk-chroot not exists, please ensure that you have install correct Platform SDK package." && \
237 exit 1
238
239 grep "alias ${sdk_alias_name}=" ${HOME}/.bashrc 1>/dev/null 2>&1 && \
240 sed -i "/alias ${sdk_alias_name}=/d" ${HOME}/.bashrc;
241
242 grep "alias ${sdk_alias_name}=" ${HOME}/.bashrc 1>/dev/null 2>&1 || \
243 echo "alias ${sdk_alias_name}=$(readlink -f ${sdk_install_path%/}/$SDKDIR/syberos-sdk-chroot)" >> "${HOME}/.bashrc"; source ${HOME}/.bashrc;
244
245
246 grep "sdk-install-path" ${HOME}/.config/qtversions.conf 1>/dev/null 2>&1 && \
247 sed -i "/^sdk-install-path/d" ${HOME}/.config/qtversions.conf;
248
249 grep "sdk-install-path" ${HOME}/.config/qtversions.conf 1>/dev/null 2>&1 || \
250 echo "sdk-install-path=${sdk_install_path%/}" >> "${HOME}/.config/qtversions.conf";
251
252 [ ! -f ${HOME}/.syberossdk.profile ] && \
253 echo 'PS1="SyberOS-SDK $PS1"' > ${HOME}/.syberossdk.profile;
254
255 [ -d ${sdk_install_path%/}/sdk/qt-examples ] && \
256 find ${sdk_install_path%/}/sdk/qt-examples/ -type f|xargs touch
257
258 return 0
259}
260
261function PreInstallTarget()
262{
263 local ret
264
265 if [[ ${target_package} =~ (^http://|^ftp://) ]]; then
266
267 if [ $target_package_flag -ne 1 ]; then
268 DownloadFile ${Target_URL%/}/target-${arch}-${branch}/target-version-${arch}-${branch}.txt
269 ParseVersion $DOWNLOAD_OUTPUT/target-version-${arch}-${branch}.txt
270 target_package=${Target_URL%/}/target-${arch}-${branch}/target-${arch}-${branch}-build${target_version}.tar.bz2
271 fi
272
273# local user_target_package=$(basename ${target_package})
274# target_name="${user_target_package%%-build*}"
275
276 DownloadFile ${target_package}
277 ret=$?
278 if [ $ret -ne 0 ]; then
279 echo "download SB2 target package ${target_package} fail"
280 exit 1
281 fi
282 echo "download SB2 target package ${target_package} ok"
283 target_package=$DOWNLOAD_OUTPUT/$(basename ${target_package})
284 else
285 if [ ! -f ${target_package} ]; then
286 echo "SB2 target package ${target_package} not exists"
287 exit 1
288 fi
289 fi
290
291
292 return 0
293}
294
295function SelectAnotherPathTarget()
296{
297
298 local oldpath=$1
299 local overwrite=
300 local newvalue=
301 echo
302 while true
303 do
304 read -p "${target_install_path%/}/${target_name} 已经存在, 是否覆盖它[y/n]?" overwrite
305 if [ ${overwrite} == "n" ]; then
306 read -p "请输入新的绝对路径:" newvalue
307 # if [ -d ${target_install_path%/}/${target_name} ]; then
308 # target_name=${newvalue}
309 # continue
310 if [ -d ${newvalue} ]; then
311 oldpath=$newvalue
312 continue
313
314 else
315 target_install_path=$oldpath
316 # SudoExec mkdir -p ${target_install_path%/}/${target_name}
317 SudoExec mkdir -p ${target_install_path}
318 break
319 fi
320 else
321 SudoExec rm -rf ${target_install_path%/}/${target_name}/*
322 break
323 fi
324 done
325}
326function silentModeCreatInstallTargetPath()
327{
328 local installPath=$1
329 if [ -d $installPath/${target_name} ];then
330 SudoExec rm $installPath/${target_name} -rf
331 fi
332 SudoExec mkdir -p $installPath
333}
334
335function InstallTarget()
336{
337 if [ $silent_flag -eq 1 ]; then
338 silentModeCreatInstallTargetPath ${target_install_path}
339 else
340 if [ ! -d ${target_install_path%/}/${target_name} ]; then
341 # SudoExec mkdir -p ${target_install_path%/}/${target_name}
342 SudoExec mkdir -p ${target_install_path}
343 if [ $? -ne 0 ]; then
344 echo "mkdir ${target_install_path} fail"
345 exit 1
346 fi
347 else
348 SelectAnotherPathTarget ${target_install_path}
349 fi
350 fi
351
352 echo "being Install ${target_package}....."
353 SudoExec tar --numeric-owner -p -xjf ${target_package} -C ${target_install_path%/}/
354 [ $? -ne 0 ] && echo "extract ${target_package} fail" && exit 1
355 SudoExec chown -R $USER ${target_install_path%/}/${target_name}/*
356 my_uid=$(echo $(id -u))
357 sed -i "/^[^:]*:[^:]*:${my_uid}/d" ${target_install_path%/}/${target_name}/etc/passwd
358 grep :$(id -u): /etc/passwd >> ${target_install_path%/}/${target_name}/etc/passwd
359 grep :$(id -g): /etc/group >> ${target_install_path%/}/${target_name}/etc/group
360
361 sed -i "s#\$SDK_INSTALL_PATH#${sdk_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.query
362
363 grep "${target_name}" ${HOME}/.config/qtversions.conf 1>/dev/null 2>&1 && \
364 sed -i "/^${target_name}/d" ${HOME}/.config/qtversions.conf;
365
366 grep "${target_name}" ${HOME}/.config/qtversions.conf 1>/dev/null 2>&1 || \
367 echo "${target_name}=${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake" >> "${HOME}/.config/qtversions.conf";
368 if [ "x$arch" == "xarmv7tnhl" ];then
369 SudoExec ${sdk_install_path%/}/$SDKDIR/syberos-sdk-chroot "cd /parentroot/$(readlink -f ${target_install_path%/}/${target_name}) && sb2-init -d -L \"--sysroot=/\" -C \"--sysroot=/\" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / ${target_name} /opt/cross/bin/armv7tnhl-meego-linux-gnueabi-gcc"
370 #sed -i "s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.query
371 sed -i "/cat\ /{s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g}" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake
372 sed -i "s#\$TARGET_INSTALL_PATH#\/parentroot${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake
373 sed -i "/cat\ /{s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g}" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.originfix
374 sed -i "s#\$TARGET_INSTALL_PATH#\/parentroot${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.originfix
375 sed -i "s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.query
376 else
377 if [ ! -d ${HOME}/.scratchbox2 ]; then
378 mkdir -p ${HOME}/.scratchbox2
379 fi
380 sed -i "s#\$TARGET_INSTALL_PATH#\/parentroot${target_install_path%/}#g" ${target_install_path%/}/${target_name}/scratchbox2/${target_name}/sybersdk-target-i686.config ${target_install_path%/}/${target_name}/exec_${target_name}
381 cp -r ${target_install_path%/}/${target_name}/scratchbox2/* $HOME/.scratchbox2/
382 SudoExec mv ${target_install_path%/}/${target_name}/exec_${target_name} ${sdk_install_path%/}/${SDKDIR}/usr/bin/
383 sed -i "/cat\ /{s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g}" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake
384 sed -i "s#\$TARGET_INSTALL_PATH#\/parentroot\/parentroot${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake
385 sed -i "/cat\ /{s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g}" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.originfix
386 sed -i "s#\$TARGET_INSTALL_PATH#\/parentroot\/parentroot${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.originfix
387 sed -i "s#\$TARGET_INSTALL_PATH#${target_install_path%/}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.query
388 sed -i "s#^QT_COMPILE_ARGS:sb2 -t ${target_name} -R#QT_COMPILE_ARGS:exec_${target_name}#g" ${target_install_path%/}/${target_name}/usr/lib/qt5/bin/qmake.query
389 SudoExec chown -R root:root ${target_install_path%/}/${target_name}
390 SudoExec chmod u+s ${target_install_path%/}/${target_name}/usr/bin/sudo
391 fi
392
393
394 return 0
395}
396
397function ShowResultinfo()
398{
399 if [ ${target_package_flag} -eq 1 ] && [ ${sdk_package_flag} -ne 1 ]; then
400 echo "only install target!!!"
401 else
402 if [ ${only_install_target} -ne 1 ]; then
403 echo \
404 "--------------------------------------------
405 Platform SDK Infomation
406 installation package: ${sdk_package}
407 location: $(readlink -f ${sdk_install_path})
408 alias name: ${sdk_alias_name}"
409 fi
410 fi
411
412 if [ ${target_package_flag} -ne 1 ] && [ ${sdk_package_flag} -eq 1 ]; then
413 echo "only install sdk!!!"
414 else
415 if [ ${only_install_sdk} -ne 1 ]; then
416 echo \
417 "--------------------------------------------
418 ScratBox2 target Infomation
419 installation package: ${target_package}
420 location: $(readlink -f ${target_install_path%/}/${target_name})
421 target name: ${target_name}"
422 fi
423 fi
424
425 echo "--------------------------------------------"
426 echo "Just enjoy it!"
427}
428
429
430function ArgParse()
431{
432 local index=0;
433 sudo_password=""
434 branch="main_dev"
435 arch="armv7tnhl"
436 sdk_branch="main_dev"
437
438 sdk_install_path_flag=0
439 only_install_sdk=0
440 sdk_package="${SDK_URL%/}/sdk-${sdk_branch}/syberos_sdk-build1.tar.bz2"
441 sdk_install_path="${HOME}/Syberos-Pdk"
442 sdk_alias_name="pdk"
443
444
445 target_package_flag=0
446 target_name_flag=0
447 only_install_target=0
448 only_install_arch_flag=0
449 target_install_path_flag=0
450 sdk_package_flag=0
451 silent_flag=0
452 branch_flag=0
453 target_package="${Target_URL%/}/target-${arch}-${branch}/target-${arch}-${branch}-build1.tar.bz2"
454 target_package_array[0]="${Target_URL%/}/target-${arch}-${branch}/target-${arch}-${branch}-build1.tar.bz2"
455
456 branch_array=()
457
458
459 target_install_path="/srv/syberos/targets"
460 target_name="${target_package%%.tar.bz2}"
461
462 while [ -n "$1" ];
463 do
464 case "$1" in
465 --help)
466 Usage
467 exit 0
468 ;;
469 --sudo-password)
470 shift
471 sudo_password=$1
472 shift
473 ;;
474 --sdk-branch)
475 shift
476 sdk_branch=$1
477 shift
478 ;;
479 --branch)
480 shift
481 branch_array[${#branch_array[@]}]=$1
482 branch_flag=1
483 shift
484 ;;
485 --arch)
486 shift
487 arch=$1
488 only_install_arch_flag=1
489 shift
490 ;;
491 --only-install-sdk)
492 only_install_sdk=1
493 shift
494 ;;
495 --sdk-package)
496 shift
497 sdk_package=$1
498 sdk_package_flag=1
499 shift
500 ;;
501 --sdk-install-path)
502 shift
503 sdk_install_path=$1
504 sdk_install_path_flag=1
505 shift
506 ;;
507 --sdk-alias-name)
508 shift
509 sdk_alias_name=$1
510 shift
511 ;;
512 --only-install-target)
513 only_install_target=1
514 shift
515 ;;
516 --target-package)
517 shift
518 target_package_array[${#target_package_array[@]}]=$1
519 target_package_flag=1
520 shift
521 ;;
522 --target-install-path)
523 shift
524 target_install_path=$1
525 target_install_path_flag=1
526 shift
527 ;;
528 --silent)
529 silent_flag=1
530 shift
531 ;;
532 --archbranch)
533 shift
534 archbranch=()
535 while [ -n "$1" ];
536 do
537 (echo "$1" | grep "^--") 1>/dev/null 2>&1 && break
538 n=${#archbranch[@]}
539 archbranch[n]=$1
540 shift
541 if [ $n == 1 ]; then break;
542 fi
543 ((n++))
544 done
545 ;;
546 # --target-name)
547 # shift
548 # target_name=$1
549 # target_name_flag=1
550 # shift
551 # ;;
552 *)
553 echo "invalid option -- $1"
554 exit 1
555 esac
556 local result=`expr ${#archbranch[@]} % 2`
557 if [ ${#archbranch[@]} != 0 ] && [ $result == 0 ]; then
558 local array_index="${archbranch[0]}-${index}"
559 arch_branch_array[${array_index}]=${archbranch[1]}
560 ((index++))
561 unset archbranch
562 fi
563 done
564
565 if [ ${target_package_flag} -ne 1 ]; then
566 target_package_array[0]="${Target_URL%/}/target-${arch}-${branch}/target-${arch}-${branch}-build1.tar.bz2"
567 fi
568# else
569# local user_package=$(basename ${target_package})
570# arch=`echo $user_package|cut -f2 -d-`
571# fi
572
573 if [ ${sdk_install_path_flag} -eq 1 -a $target_install_path_flag -ne 1 ];then
574 target_install_path="${sdk_install_path%/}/targets"
575 fi
576
577# if [ ${target_name_flag} -ne 1 ]; then
578# local user_target_package=$(basename ${target_package})
579# target_name="${user_target_package%%-build*}"
580# fi
581 if [ ${only_install_target} -eq 1 -a ${sdk_install_path_flag} -eq 1 ];then
582 if [ ! -d ${sdk_install_path%/}/$SDKDIR ];then
583 echo "error:${sdk_install_path%/}/$SDKDIR is not exist!!!"
584 exit 1
585 fi
586 fi
587
588 if [ ${target_package_flag} -eq 1 -a ${sdk_install_path_flag} -eq 1 -a ${sdk_package_flag} -ne 1 ];then
589 if [ ! -d ${sdk_install_path%/}/$SDKDIR ];then
590 echo "error:${sdk_install_path%/}/$SDKDIR is not exist!!!"
591 exit 1
592 fi
593 fi
594
595 if [ ${only_install_sdk} -eq 1 -a ${only_install_target} -eq 1 ]; then
596 echo "option --only-install-sdk and --only-install-target can't be set at the same time"
597 exit 1
598 fi
599 if [ ${only_install_target} -eq 1 -a ${sdk_install_path_flag} -ne 1 ];then
600 echo "option --sdk-install-path and --only-install-target must be set at the same time"
601 exit 1
602 fi
603 if [ ${sdk_package_flag} -ne 1 ]; then
604 if [ ${target_package_flag} -eq 1 -a ${sdk_install_path_flag} -eq 0 ]; then
605 echo "option --sdk-install-path and --target-package must be set at the same time"
606 exit 1
607 fi
608
609 if [ ${target_package_flag} -eq 1 -a ! -f ${sdk_install_path%/}/$SDKDIR/syberos-sdk-chroot ]; then
610 echo "option --sdk-install-path ${sdk_install_path%/} error"
611 exit 1
612 fi
613 fi
614
615}
616
617function exec_install_target()
618{
619
620 local ret
621 if [ ${target_package_flag} -ne 1 ] && [ ${sdk_package_flag} -eq 1 ]; then
622 echo "only install sdk!!!"
623 else
624 if [ ${only_install_sdk} -ne 1 ]; then
625 for package_name in ${target_package_array[@]}
626 do
627 if [ $target_package_flag -eq 1 ];then
628 if [ "x$package_name" == x$target_package ]; then
629 continue;
630 fi
631 fi
632
633 target_package=$package_name
634 local user_target_package=$(basename ${target_package})
635 if [ ${only_install_arch_flag} -ne 1 ];then
636 arch=`echo $user_target_package|cut -f2 -d-`
637 fi
638
639 if [ $branch_flag != 0 ]; then
640 target_name="target-$arch-$branch"
641 else
642 target_name="${user_target_package%%-build*}"
643 fi
644
645 PreInstallTarget
646 echo "It will be install ${target_package}............"
647 InstallTarget
648 ret=$?
649 if [ $ret -ne 0 ]; then
650 echo "scratbox2 target install fail."
651 exit 1
652 fi
653 echo "scratbox2 target install successfully."
654 done
655 fi
656 fi
657
658 if [ ${sdk_package_flag} -ne 1 -a ${only_install_sdk} -ne 1 ] && [ ${only_install_arch_flag} -ne 1 -a ${target_package_flag} -ne 1 ]; then
659 arch="i686"
660 target_package=${Target_URL%/}/target-${arch}-${branch}/target-${arch}-${branch}-build1.tar.bz2
661 local user_package=$(basename ${target_package})
662 if [ ${#branch_array[@]} != 0 ]; then
663 target_name="target-$arch-$branch"
664 else
665 target_name="${user_package%%-build*}"
666 fi
667 PreInstallTarget
668 echo "It will be install ${target_package}............"
669 InstallTarget
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 echo "scratbox2 i686 target install fail."
673 exit 1
674 fi
675 echo "scratbox2 i686 target install successfully."
676 fi
677
678}
679
680function print_array()
681{
682 for key in "${!arch_branch_array[@]}"
683 do
684 echo "key::$key value:: ${arch_branch_array[${key}]}"
685 done
686}
687
688function main()
689{
690 local ret
691
692 ArgParse "$@"
693 # print_array
694 ReadPassword
695# sudo_password=$(echo -n $sudo_password |sed -e 's/\$/\\\$/g'|sed -e 's/\}/\\\}/g')
696# sudo_password=$(echo -n $sudo_password |sed -e 's/{/\\\{/g')
697 echo
698 echo "Verify Password......"
699 if [ -f /tmp/test_passwd ]; then
700 SudoExec rm -f /tmp/test_passwd
701 fi
702
703 SudoExec echo "test_passwd" > /tmp/test_passwd
704 ret=$?
705 if [ $ret -ne 0 ]; then
706 echo "maybe you not install expect or password is not correct !!!"
707 exit 1
708 fi
709
710 if [ ${target_package_flag} -eq 1 ] && [ ${sdk_package_flag} -ne 1 ]; then
711 echo "only install target!!!"
712 else
713 if [ ${only_install_target} -ne 1 ]; then
714 PreInstallSDK
715 echo "It will be install ${sdk_package}............"
716 if [ ${sdk_install_path_flag} -ne 1 ]; then
717 echo "***********the default install path is $sdk_install_path****** "
718 fi
719 InstallSDK
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 echo "Platform SDK install fail."
723 exit 1
724 fi
725 echo "Platform SDK install successfully."
726 fi
727 fi
728
729 if [ ${#arch_branch_array[@]} != 0 ]; then
730 only_install_arch_flag=1
731 branch_flag=1
732 for arch_install in "${!arch_branch_array[@]}"
733 do
734 arch=${arch_install%-*}
735 branch=${arch_branch_array[${arch_install}]}
736 exec_install_target
737 done
738 else
739 if [ ${#branch_array[@]} != 0 ]; then
740 for branch_name in ${branch_array[@]}
741 do
742 branch=$branch_name
743 exec_install_target
744 done
745 else
746 exec_install_target
747 fi
748 fi
749
750 ShowResultinfo
751
752
753 return 0
754}
755
756main "$@"