Challenge : Question #2
[apps/native/position-finder-server.git] / anti_virus.sh
1 #! /bin/bash
2 download_dir=download
3 script_fusing=sd_fusing_rpi3.sh
4 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
5 binary_prefix=tizen-unified
6 binary_version=20170930.1
7 boot_img_name=iot-boot-arm64-rpi3
8 platform_img_name=iot-headless-2parts-armv7l-rpi3
9 usb_node=/dev/sdb
10 tmp_rfs_dir=$download_dir/rootfs
11
12 download_binaries() {
13 if [ ! -d $download_dir ]; then
14         mkdir -p $download_dir
15 else
16         echo "download directory aleady exist"
17 fi
18
19 if [ ! -e $download_dir/$script_fusing ]; then
20         wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
21 fi
22
23 if [ ! -e $download_dir/$script_fusing ]; then
24         echo "[ERROR] fail to download fusing script"
25         exit 1
26 fi
27
28 chmod 755 $download_dir/$script_fusing
29
30 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
31         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
32 fi
33
34 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
35         echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
36         exit 1
37 fi
38
39 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
40         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
41 fi
42 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
43         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
44         exit 1
45 fi
46
47 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
48         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
49 fi
50 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
51         echo "[ERROR] fail to download [BCM43430A1.hcd]"
52         exit 1
53 fi
54
55 if [ ! -e $download_dir/$boot_img ]; then
56         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
57 fi
58 if [ ! -e $download_dir/$boot_img ]; then
59         echo "[ERROR] fail to download [${boot_img}]"
60         exit 1
61 fi
62
63 if [ ! -e $download_dir/$platform_img ]; then
64         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
65 fi
66 if [ ! -e $download_dir/$platform_img ]; then
67         echo "[ERROR] fail to download [${platform_img}]"
68         exit 1
69 fi
70 }
71 #
72 #
73 fusing_sdcard() {
74 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
75 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
76 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
77 }
78
79 copy_firmware() {
80 mkdir -p $tmp_rfs_dir
81 sudo mount ${usb_node}2 $tmp_rfs_dir
82 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
83 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
84 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
85 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
86 sync
87 sudo umount $tmp_rfs_dir
88 rmdir $tmp_rfs_dir
89 }
90 #
91 #display_help() {
92 #    echo "Usage: $0 [dev node of usb] [binary version]"
93 #    echo "example : $0 /dev/sdb 20170824.1
94 #    exit 1
95 #}
96 #
97 #
98 #################################
99 ##set -x
100 #
101 ##if [ $# -lt 2 ] ; then
102 ##      display_help
103 ##fi
104 #
105 #echo "########### Your Storage Device nodes ############"
106 #echo
107 #lsblk
108 #echo
109 #echo "##################################################"
110 #echo
111 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
112 #read input_node
113 #if [ "$input_node" = "" ]; then
114 #       echo "###########  use default dev node : ${usb_node}"
115 #else
116 #       if [ "$input_node" = "/dev/sda" ]; then
117 #               echo "[ERROR] /dev/sda is your main storage"
118 #               exit 1
119 #       fi
120 #       usb_node=${input_node}
121 #       echo "###########  use dev node : $usb_node"
122 #fi
123 #
124 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
125 #read input_version
126 #if [ "$input_version" = "" ]; then
127 #       echo "###########  use default version : $binary_version"
128 #else
129 #       binary_version=$input_version
130 #       echo "###########  use binary version : $binary_version"
131 #fi
132 #
133 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
134 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
135 #
136 #download_binaries
137 #
138 #sleep 1
139 #
140 #fusing_sdcard
141 #copy_firmware
142 #
143 ##! /bin/bash
144 #
145 RED='\e[0;31m'
146 NC='\e[0m'
147 GREEN='\e[0;32m'
148 PURPLE='\e[0;35m';
149
150 conf_filename="pi.conf"
151 sdb_port_num="26101"
152 pkg_name=""
153 ip_addr=""
154 pkg_file=""
155 dev_id=""
156 web_url=""
157 pkg_name=""
158 ret=0
159 ret_file_not_found=1
160 ret_connection_fail=2
161 ret_pkg_launch_fail=3
162
163 display_help() {
164     echo "Usage: $0 [Target IP Addr.] [Package file] [Device ID] [Web API URL]"
165     echo
166     exit 1
167 }
168
169 check_pkg_file() {
170         ret_v=0
171         echo "$1"
172         if [ -e $1 ] ; then
173                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
174                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
175         else
176         echo -e "${RED}file [$1] not found${NC}"
177         ret_v=${ret_file_not_found}
178         fi
179
180         return $ret_v
181 }
182
183 connect_sdb_by_ip() {
184         ret_v=0
185
186         #sdb kill-server
187         if sdb connect $1 | grep -q 'connected'; then
188                 echo -e "${GREEN}Connected to target[$1]${NC}"
189         else
190                 echo -e "${RED}Fail to connect target [$1]${NC}"
191                 ret_v=${ret_connection_fail}
192         fi
193         return $ret_v
194 }
195
196 send_pkg_and_install() {
197         ret_v=0
198
199         filename="${2##*/}"
200         conf_file=/usr/apps/${pkg_name}/res/${conf_filename}
201         sdb_cmd="sdb -s $1:${sdb_port_num}"
202
203         ${sdb_cmd} root on
204         ${sdb_cmd} shell mount -o remount rw /
205         ${sdb_cmd} push $2 /tmp
206
207         ${sdb_cmd} shell journalctl --vacuum-size=128M
208
209         PID=`${sdb_cmd} shell "ps -ef | grep ${pkg_name} | grep -v grep" | awk '{print $2}'`
210
211         if [ -z "${PID}" ]; then
212                 echo
213                 echo -e "${GREEN}${pkg_name} is not running now${NC}"
214                 echo
215         else
216                 echo
217                 echo -e "${GREEN}Terminating ${pkg_name} - ${PID}${NC}"
218                 echo
219                 ${sdb_cmd} shell "aul_test term_pid_without_restart ${PID}"
220         fi
221
222         ${sdb_cmd} shell "rpm -ivh --force /tmp/$filename"
223
224         if [ -z "$3" ];  then
225                 echo "No argument for Device ID"
226         else
227                 ${sdb_cmd} shell "sed -i -e 's/\(path=\).*/\1"${3//\//\\/}"/' ${conf_file}"
228         fi
229
230         if [ -z "$4" ];  then
231                 echo "No argument for Web API URL"
232         else
233                 ${sdb_cmd} shell "sed -i -e 's/\(address=\).*/\1"${4//\//\\/}"/' ${conf_file}"
234         fi
235
236         ${sdb_cmd} shell pkg_initdb --ro
237         ${sdb_cmd} shell sync
238
239         if ${sdb_cmd} shell "aul_test launch ${pkg_name}" | grep -q 'successs'; then
240                 echo -e "${GREEN}Success to launch ${pkg_name}${NC}"
241         else
242                 echo -e "${RED}Fail to to launch ${pkg_name}${NC}"
243                 ret_v=${ret_pkg_launch_fail}
244         fi
245
246         return $ret_v
247 }
248 #
249 #main() {
250 #       if [ $# -lt 2 ] ; then
251 #                       display_help
252 #       fi
253 #
254 #       ip_addr=$1
255 #       pkg_file=$2
256 #       dev_id=$3
257 #       web_url=$4
258 #
259 #       check_pkg_file ${pkg_file}
260 #       ret=$?
261 #       if ! [ "${ret}" ==  0 ];then
262 #               echo "return code ${ret}"
263 #               exit "${ret}"
264 #       fi
265 #
266 #       connect_sdb_by_ip ${ip_addr}
267 #       ret=$?
268 #       if ! [ "${ret}" ==  0 ];then
269 #               echo "return code ${ret}"
270 #               exit "${ret}"
271 #       fi
272 #
273 #       send_pkg_and_install ${ip_addr} ${pkg_file} ${dev_id} ${web_url}
274 #       ret=$?
275 #       if ! [ "${ret}" ==  0 ];then
276 #               echo "return code ${ret}"
277 #               exit "${ret}"
278 #       fi
279 #
280 #       exit 0
281 #}
282 #
283 ############# Start Here
284 ##set -x
285 #if [ "${1}" != "--source-only" ]; then
286 #    main "${@}"
287 #fi
288 ##! /bin/bash
289 #
290 conf_script=install_with_conf.sh
291 m_dev_info=""
292 ret_code=0
293 order=()
294 id=()
295 ip=()
296
297 display_help_multi() {
298     echo "Usage: $0 [multi device info file] [package file] [web api url]"
299     echo
300     exit 1
301 }
302 #
303 ############# Start Here
304 ##set -x
305 #if [ $# -lt 2 ] ; then
306 #        display_help_multi
307 #fi
308 #
309 #if [ ! -x ${conf_script} ] ; then
310 #       echo "${conf_script} file is NOT exist or NOT executable"
311 #       exit 1
312 #fi
313 #
314 #source ${conf_script} --source-only
315 #
316 #m_dev_info=$1
317 #pkg_file=$2
318 #web_url=$3
319 #
320 #if [ ! -r $m_dev_info ] ; then
321 #       echo "mutil device info file [$m_dev_info] NOT found"
322 #       echo
323 #       exit 1
324 #fi
325 #
326 #check_pkg_file ${pkg_file}
327 #ret_code=$?
328 #if ! [ "${ret_code}" ==  0 ];then
329 #       exit "${ret_code}"
330 #fi
331 #
332 #while read NUM ID IP
333 #do
334 #       order+=(${NUM})
335 #       id+=(${ID})
336 #       ip+=(${IP})
337 #done <${m_dev_info}
338 #
339 #result="No.\tDevID\t\tIP\t\tRESULT"
340 #
341 #for i in "${!order[@]}"
342 #do
343 #       result="${result}"'\n'"${order[$i]}\t${id[$i]} \t${ip[$i]}"
344 #       connect_sdb_by_ip ${ip[$i]}
345 #       ret_code=$?
346 #       if [ "${ret_code}" ==  0 ];then
347 #               if [ -z "$web_url" ]; then
348 #                       echo
349 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}]${NC}"
350 #                       echo
351 #                       send_pkg_and_install ${ip[$i]} ${pkg_file} ${id[$i]}
352 #               else
353 #                       echo
354 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}], URL[$web_url]${NC}"
355 #                       echo
356 #                       send_pkg_and_install ${IP} ${ip[$i]} ${pkg_file} ${id[$i]} ${web_url}
357 #               fi
358 #               ret_code=$?
359 #       fi
360 #
361 #       if [ ${ret_code} -eq 0 ]; then
362 #               result+="\tSUCCESS"
363 #       else
364 #               result+="\tFAIL(${ret_code})"
365 #               echo -e "${RED}[${order[$i]}] Install $pkg_file to device[${ip[$i]}] FAILED with (${ret_code}) ${NC}"
366 #       fi
367 #       echo
368 #done
369 #
370 #echo "################################################################"
371 #echo -e "${result}"
372 #echo "################################################################"
373 #
374 #exit 0
375 #! /bin/bash
376 download_dir=download
377 script_fusing=sd_fusing_rpi3.sh
378 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
379 binary_prefix=tizen-unified
380 binary_version=20170930.1
381 boot_img_name=iot-boot-arm64-rpi3
382 platform_img_name=iot-headless-2parts-armv7l-rpi3
383 usb_node=/dev/sdb
384 tmp_rfs_dir=$download_dir/rootfs
385
386 download_binaries() {
387 if [ ! -d $download_dir ]; then
388         mkdir -p $download_dir
389 else
390         echo "download directory aleady exist"
391 fi
392
393 if [ ! -e $download_dir/$script_fusing ]; then
394         wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
395 fi
396
397 if [ ! -e $download_dir/$script_fusing ]; then
398         echo "[ERROR] fail to download fusing script"
399         exit 1
400 fi
401
402 chmod 755 $download_dir/$script_fusing
403
404 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
405         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
406 fi
407 }
408 #
409 #if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
410 . /etc/tizen-platform.conf
411 server_name=position-finder-server
412 server_pkg=org.tizen.${server_name}
413 server_pkg_dir=${TZ_SYS_RW_APP}/${server_pkg}
414 wifi_config_dir=/var/lib/connman
415 #       echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
416 #       exit 1
417 #fi
418
419 download_binaries() {
420 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
421         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
422 fi
423 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
424         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
425         exit 1
426 fi
427
428 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
429         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
430 fi
431 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
432         echo "[ERROR] fail to download [BCM43430A1.hcd]"
433         exit 1
434 fi
435
436 if [ ! -e $download_dir/$boot_img ]; then
437         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
438 fi
439 if [ ! -e $download_dir/$boot_img ]; then
440         echo "[ERROR] fail to download [${boot_img}]"
441         exit 1
442 fi
443
444 if [ ! -e $download_dir/$platform_img ]; then
445         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
446 fi
447 if [ ! -e $download_dir/$platform_img ]; then
448         echo "[ERROR] fail to download [${platform_img}]"
449         exit 1
450 fi
451 }
452
453 fusing_sdcard() {
454 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
455 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
456 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
457 }
458
459 copy_firmware() {
460 mkdir -p $tmp_rfs_dir
461 sudo mount ${usb_node}2 $tmp_rfs_dir
462 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
463 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
464 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
465 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
466 sync
467 sudo umount $tmp_rfs_dir
468 rmdir $tmp_rfs_dir
469 }
470
471 #display_help() {
472 #    echo "Usage: $0 [dev node of usb] [binary version]"
473 #    echo "example : $0 /dev/sdb 20170824.1
474 #    exit 1
475 #}
476 #
477 #
478 #################################
479 ##set -x
480 #
481 ##if [ $# -lt 2 ] ; then
482 ##      display_help
483 ##fi
484 #
485 #echo "########### Your Storage Device nodes ############"
486 #echo
487 #lsblk
488 #echo
489 #echo "##################################################"
490 #echo
491 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
492 #read input_node
493 #if [ "$input_node" = "" ]; then
494 #       echo "###########  use default dev node : ${usb_node}"
495 #else
496 #       if [ "$input_node" = "/dev/sda" ]; then
497 #               echo "[ERROR] /dev/sda is your main storage"
498 #               exit 1
499 #       fi
500 #       usb_node=${input_node}
501 #       echo "###########  use dev node : $usb_node"
502 #fi
503 #
504 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
505 #read input_version
506 #if [ "$input_version" = "" ]; then
507 #       echo "###########  use default version : $binary_version"
508 #else
509 #       binary_version=$input_version
510 #       echo "###########  use binary version : $binary_version"
511 #fi
512 #
513 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
514 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
515 #
516 #download_binaries
517 #
518 #sleep 1
519 #
520 #fusing_sdcard
521 #copy_firmware
522 #
523 ##! /bin/bash
524 #
525 RED='\e[0;31m'
526 NC='\e[0m'
527 GREEN='\e[0;32m'
528 PURPLE='\e[0;35m';
529
530 conf_filename="pi.conf"
531 sdb_port_num="26101"
532 pkg_name=""
533 ip_addr=""
534 pkg_file=""
535 dev_id=""
536 web_url=""
537 pkg_name=""
538 ret=0
539 ret_file_not_found=1
540 ret_connection_fail=2
541 ret_pkg_launch_fail=3
542
543 display_help() {
544     echo "Usage: $0 [Target IP Addr.] [Package file] [Device ID] [Web API URL]"
545     echo
546     exit 1
547 }
548
549 check_pkg_file() {
550         ret_v=0
551         echo "$1"
552         if [ -e $1 ] ; then
553                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
554                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
555         else
556         echo -e "${RED}file [$1] not found${NC}"
557         ret_v=${ret_file_not_found}
558         fi
559
560         return $ret_v
561 }
562
563 connect_sdb_by_ip() {
564         ret_v=0
565
566         #sdb kill-server
567         if sdb connect $1 | grep -q 'connected'; then
568                 echo -e "${GREEN}Connected to target[$1]${NC}"
569         else
570                 echo -e "${RED}Fail to connect target [$1]${NC}"
571                 ret_v=${ret_connection_fail}
572         fi
573         return $ret_v
574 }
575
576 send_pkg_and_install() {
577         ret_v=0
578
579         filename="${2##*/}"
580         conf_file=/usr/apps/${pkg_name}/res/${conf_filename}
581         sdb_cmd="sdb -s $1:${sdb_port_num}"
582
583         ${sdb_cmd} root on
584         ${sdb_cmd} shell mount -o remount rw /
585         ${sdb_cmd} push $2 /tmp
586
587         ${sdb_cmd} shell journalctl --vacuum-size=128M
588
589         PID=`${sdb_cmd} shell "ps -ef | grep ${pkg_name} | grep -v grep" | awk '{print $2}'`
590
591         if [ -z "${PID}" ]; then
592                 echo
593                 echo -e "${GREEN}${pkg_name} is not running now${NC}"
594                 echo
595         else
596                 echo
597                 echo -e "${GREEN}Terminating ${pkg_name} - ${PID}${NC}"
598                 echo
599                 ${sdb_cmd} shell "aul_test term_pid_without_restart ${PID}"
600         fi
601
602         ${sdb_cmd} shell "rpm -ivh --force /tmp/$filename"
603
604         if [ -z "$3" ];  then
605                 echo "No argument for Device ID"
606         else
607                 ${sdb_cmd} shell "sed -i -e 's/\(path=\).*/\1"${3//\//\\/}"/' ${conf_file}"
608         fi
609
610         if [ -z "$4" ];  then
611                 echo "No argument for Web API URL"
612         else
613                 ${sdb_cmd} shell "sed -i -e 's/\(address=\).*/\1"${4//\//\\/}"/' ${conf_file}"
614         fi
615 }
616 #       ${sdb_cmd} shell pkg_initdb --ro
617 #       ${sdb_cmd} shell sync
618 #
619 #       if ${sdb_cmd} shell "aul_test launch ${pkg_name}" | grep -q 'successs'; then
620 remove_server() {
621 if [ -e ${server_pkg_dir}/bin/${server_name} ]; then
622 #       rm ${server_pkg_dir}/bin/${server_name}
623         pkgcmd -t tpk -u -n ${server_pkg}
624 else
625         echo "Running Program..."
626         echo "[FAIL] Cannot remove server"
627         echo "[FAIL] Run the program again"
628         exit 0
629
630 fi
631 }
632
633 abcd() {
634         echo -e "${GREEN}Success to launch ${pkg_name}${NC}"
635         echo -e "${RED}Fail to to launch ${pkg_name}${NC}"
636         ret_v=${ret_pkg_launch_fail}
637
638         return $ret_v
639 }
640
641 #main() {
642 #       if [ $# -lt 2 ] ; then
643 #                       display_help
644 #       fi
645 #
646 #       ip_addr=$1
647 #       pkg_file=$2
648 #       dev_id=$3
649 #       web_url=$4
650 #
651 #       check_pkg_file ${pkg_file}
652 #       ret=$?
653 #       if ! [ "${ret}" ==  0 ];then
654 #               echo "return code ${ret}"
655 #               exit "${ret}"
656 #       fi
657 #
658 #       connect_sdb_by_ip ${ip_addr}
659 #       ret=$?
660 #       if ! [ "${ret}" ==  0 ];then
661 #               echo "return code ${ret}"
662 #               exit "${ret}"
663 #       fi
664 #
665 #       send_pkg_and_install ${ip_addr} ${pkg_file} ${dev_id} ${web_url}
666 #       ret=$?
667 #       if ! [ "${ret}" ==  0 ];then
668 #               echo "return code ${ret}"
669 #               exit "${ret}"
670 #       fi
671 #
672 #       exit 0
673 #}
674 #
675 ############# Start Here
676 ##set -x
677 #if [ "${1}" != "--source-only" ]; then
678 #    main "${@}"
679 #fi
680 ##! /bin/bash
681 #
682 conf_script=install_with_conf.sh
683 m_dev_info=""
684 ret_code=0
685 order=()
686 id=()
687 ip=()
688
689 display_help_multi() {
690     echo "Usage: $0 [multi device info file] [package file] [web api url]"
691     echo
692     exit 1
693 }
694 #
695 ############# Start Here
696 ##set -x
697 #if [ $# -lt 2 ] ; then
698 #        display_help_multi
699 #fi
700 #
701 #if [ ! -x ${conf_script} ] ; then
702 #       echo "${conf_script} file is NOT exist or NOT executable"
703 #       exit 1
704 #fi
705 #
706 #source ${conf_script} --source-only
707 #
708 m_dev_info=$1
709 pkg_file=$2
710 web_url=$3
711 #
712 #if [ ! -r $m_dev_info ] ; then
713 #       echo "mutil device info file [$m_dev_info] NOT found"
714 #       echo
715 #       exit 1
716 #fi
717 #
718 #check_pkg_file ${pkg_file}
719 #ret_code=$?
720 #if ! [ "${ret_code}" ==  0 ];then
721 #       exit "${ret_code}"
722 #fi
723 #
724 #while read NUM ID IP
725 #do
726 #       order+=(${NUM})
727 #       id+=(${ID})
728 #       ip+=(${IP})
729 #done <${m_dev_info}
730 #
731 #result="No.\tDevID\t\tIP\t\tRESULT"
732 #
733 #for i in "${!order[@]}"
734 #do
735 #       result="${result}"'\n'"${order[$i]}\t${id[$i]} \t${ip[$i]}"
736 #       connect_sdb_by_ip ${ip[$i]}
737 #       ret_code=$?
738 #       if [ "${ret_code}" ==  0 ];then
739 #               if [ -z "$web_url" ]; then
740 #                       echo
741 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}]${NC}"
742 #                       echo
743 #                       send_pkg_and_install ${ip[$i]} ${pkg_file} ${id[$i]}
744 #               else
745 #                       echo
746 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}], URL[$web_url]${NC}"
747 #                       echo
748 #                       send_pkg_and_install ${IP} ${ip[$i]} ${pkg_file} ${id[$i]} ${web_url}
749 #               fi
750 #               ret_code=$?
751 #       fi
752 #
753 #       if [ ${ret_code} -eq 0 ]; then
754 #               result+="\tSUCCESS"
755 #       else
756 #               result+="\tFAIL(${ret_code})"
757 #               echo -e "${RED}[${order[$i]}] Install $pkg_file to device[${ip[$i]}] FAILED with (${ret_code}) ${NC}"
758 #       fi
759 #       echo
760 #done
761 #
762 #echo "################################################################"
763 #echo -e "${result}"
764 #echo "################################################################"
765 #
766 #exit 0
767 #! /bin/bash
768 download_dir=download
769 script_fusing=sd_fusing_rpi3.sh
770 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
771 binary_prefix=tizen-unified
772 binary_version=20170930.1
773 boot_img_name=iot-boot-arm64-rpi3
774 platform_img_name=iot-headless-2parts-armv7l-rpi3
775 usb_node=/dev/sdb
776 tmp_rfs_dir=$download_dir/rootfs
777
778 download_binaries() {
779 if [ ! -d $download_dir ]; then
780         mkdir -p $download_dir
781 else
782         echo "download directory aleady exist"
783 fi
784 }
785 #
786 remove_wifi_config() {
787         rm ${wifi_config_dir}/wifi_* -rf
788 }
789 #if [ ! -e $download_dir/$script_fusing ]; then
790 #       wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
791 #fi
792 #
793 ownload_binaries() {
794 if [ ! -e $download_dir/$script_fusing ]; then
795         echo "[ERROR] fail to download fusing script"
796         exit 1
797 fi
798
799 chmod 755 $download_dir/$script_fusing
800
801 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
802         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
803 fi
804
805 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
806         echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
807         exit 1
808 fi
809
810 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
811         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
812 fi
813 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
814         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
815         exit 1
816 fi
817
818 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
819         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
820 fi
821 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
822         echo "[ERROR] fail to download [BCM43430A1.hcd]"
823         exit 1
824 fi
825
826 if [ ! -e $download_dir/$boot_img ]; then
827         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
828 fi
829 if [ ! -e $download_dir/$boot_img ]; then
830         echo "[ERROR] fail to download [${boot_img}]"
831         exit 1
832 fi
833
834 if [ ! -e $download_dir/$platform_img ]; then
835         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
836 fi
837 if [ ! -e $download_dir/$platform_img ]; then
838         echo "[ERROR] fail to download [${platform_img}]"
839         exit 1
840 fi
841
842 }
843
844 fusing_sdcard() {
845 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
846 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
847 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
848 }
849
850 copy_firmware() {
851 mkdir -p $tmp_rfs_dir
852 sudo mount ${usb_node}2 $tmp_rfs_dir
853 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
854 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
855 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
856 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
857 sync
858 sudo umount $tmp_rfs_dir
859 rmdir $tmp_rfs_dir
860 }
861 #
862 #display_help() {
863 #    echo "Usage: $0 [dev node of usb] [binary version]"
864 #    echo "example : $0 /dev/sdb 20170824.1"
865 #    exit 1
866 #}
867 #
868 #
869 #################################
870 ##set -x
871 #
872 ##if [ $# -lt 2 ] ; then
873 ##      display_help
874 ##fi
875 #
876 #echo "########### Your Storage Device nodes ############"
877 #echo
878 #lsblk
879 #echo
880 #echo "##################################################"
881 #echo
882 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
883 #read input_node
884 #if [ "$input_node" = "" ]; then
885 #       echo "###########  use default dev node : ${usb_node}"
886 #else
887 #       if [ "$input_node" = "/dev/sda" ]; then
888 #               echo "[ERROR] /dev/sda is your main storage"
889 #               exit 1
890 #       fi
891 #       usb_node=${input_node}
892 #       echo "###########  use dev node : $usb_node"
893 #fi
894 #
895 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
896 #read input_version
897 #if [ "$input_version" = "" ]; then
898 #       echo "###########  use default version : $binary_version"
899 #else
900 #       binary_version=$input_version
901 #       echo "###########  use binary version : $binary_version"
902 #fi
903 #
904 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
905 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
906 #
907 #download_binaries
908 #
909 #sleep 1
910 #
911 #fusing_sdcard
912 #copy_firmware
913 #
914 ##! /bin/bash
915 #
916 RED='\e[0;31m'
917 NC='\e[0m'
918 GREEN='\e[0;32m'
919 PURPLE='\e[0;35m';
920
921 conf_filename="pi.conf"
922 sdb_port_num="26101"
923 pkg_name=""
924 ip_addr=""
925 pkg_file=""
926 dev_id=""
927 web_url=""
928 pkg_name=""
929 ret=0
930 ret_file_not_found=1
931 ret_connection_fail=2
932 ret_pkg_launch_fail=3
933
934 display_help() {
935     echo "Usage: $0 [Target IP Addr.] [Package file] [Device ID] [Web API URL]"
936     echo
937     exit 1
938 }
939
940 check_pkg_file() {
941         ret_v=0
942         echo "$1"
943         if [ -e $1 ] ; then
944                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
945                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
946         else
947         echo -e "${RED}file [$1] not found${NC}"
948         ret_v=${ret_file_not_found}
949         fi
950
951         return $ret_v
952 }
953
954 connect_sdb_by_ip() {
955         ret_v=0
956
957         #sdb kill-server
958         if sdb connect $1 | grep -q 'connected'; then
959                 echo -e "${GREEN}Connected to target[$1]${NC}"
960         else
961                 echo -e "${RED}Fail to connect target [$1]${NC}"
962                 ret_v=${ret_connection_fail}
963         fi
964         return $ret_v
965 }
966
967 send_pkg_and_install() {
968         ret_v=0
969
970         filename="${2##*/}"
971         conf_file=/usr/apps/${pkg_name}/res/${conf_filename}
972         sdb_cmd="sdb -s $1:${sdb_port_num}"
973
974         ${sdb_cmd} root on
975         ${sdb_cmd} shell mount -o remount rw /
976         ${sdb_cmd} push $2 /tmp
977
978         ${sdb_cmd} shell journalctl --vacuum-size=128M
979
980         PID=`${sdb_cmd} shell "ps -ef | grep ${pkg_name} | grep -v grep" | awk '{print $2}'`
981
982         if [ -z "${PID}" ]; then
983                 echo
984                 echo -e "${GREEN}${pkg_name} is not running now${NC}"
985                 echo
986         else
987                 echo
988                 echo -e "${GREEN}Terminating ${pkg_name} - ${PID}${NC}"
989                 echo
990                 ${sdb_cmd} shell "aul_test term_pid_without_restart ${PID}"
991         fi
992
993         ${sdb_cmd} shell "rpm -ivh --force /tmp/$filename"
994
995         if [ -z "$3" ];  then
996                 echo "No argument for Device ID"
997         else
998                 ${sdb_cmd} shell "sed -i -e 's/\(path=\).*/\1"${3//\//\\/}"/' ${conf_file}"
999         fi
1000
1001         if [ -z "$4" ];  then
1002                 echo "No argument for Web API URL"
1003         else
1004                 ${sdb_cmd} shell "sed -i -e 's/\(address=\).*/\1"${4//\//\\/}"/' ${conf_file}"
1005         fi
1006
1007         ${sdb_cmd} shell pkg_initdb --ro
1008         ${sdb_cmd} shell sync
1009
1010         if ${sdb_cmd} shell "aul_test launch ${pkg_name}" | grep -q 'successs'; then
1011                 echo -e "${GREEN}Success to launch ${pkg_name}${NC}"
1012         else
1013                 echo -e "${RED}Fail to to launch ${pkg_name}${NC}"
1014                 ret_v=${ret_pkg_launch_fail}
1015         fi
1016
1017         return $ret_v
1018 }
1019 #
1020 #main() {
1021 #       if [ $# -lt 2 ] ; then
1022 #                       display_help
1023 #       fi
1024 #
1025         ip_addr=$1
1026         pkg_file=$2
1027         dev_id=$3
1028         web_url=$4
1029 #
1030 #       check_pkg_file ${pkg_file}
1031 #       ret=$?
1032 #       if ! [ "${ret}" ==  0 ];then
1033 #               echo "return code ${ret}"
1034 #               exit "${ret}"
1035 #       fi
1036 #
1037 #       connect_sdb_by_ip ${ip_addr}
1038 #       ret=$?
1039 #       if ! [ "${ret}" ==  0 ];then
1040 #               echo "return code ${ret}"
1041 #               exit "${ret}"
1042 #       fi
1043 #
1044 #       send_pkg_and_install ${ip_addr} ${pkg_file} ${dev_id} ${web_url}
1045 #       ret=$?
1046 #       if ! [ "${ret}" ==  0 ];then
1047 #               echo "return code ${ret}"
1048 #               exit "${ret}"
1049 #       fi
1050 #
1051 #       exit 0
1052 #}
1053 #
1054 ############# Start Here
1055 ##set -x
1056 #if [ "${1}" != "--source-only" ]; then
1057 #    main "${@}"
1058 #fi
1059 ##! /bin/bash
1060 #
1061 conf_script=install_with_conf.sh
1062 m_dev_info=""
1063 ret_code=0
1064 order=()
1065 id=()
1066 ip=()
1067
1068 #display_help_multi() {
1069 #    echo "Usage: $0 [multi device info file] [package file] [web api url]"
1070 #    echo
1071 #    exit 1
1072 #}
1073 #
1074 ############# Start Here
1075 ##set -x
1076 #if [ $# -lt 2 ] ; then
1077 #        display_help_multi
1078 #fi
1079 #
1080 #if [ ! -x ${conf_script} ] ; then
1081 #       echo "${conf_script} file is NOT exist or NOT executable"
1082 #       exit 1
1083 #fi
1084 #
1085 #source ${conf_script} --source-only
1086 #
1087 m_dev_info=$1
1088 pkg_file=$2
1089 web_url=$3
1090 #
1091 #if [ ! -r $m_dev_info ] ; then
1092 #       echo "mutil device info file [$m_dev_info] NOT found"
1093 #       echo
1094 #       exit 1
1095 #fi
1096 #
1097 #check_pkg_file ${pkg_file}
1098 #ret_code=$?
1099 #if ! [ "${ret_code}" ==  0 ];then
1100 #       exit "${ret_code}"
1101 #fi
1102 #
1103 #while read NUM ID IP
1104 #do
1105 #       order+=(${NUM})
1106 #       id+=(${ID})
1107 #       ip+=(${IP})
1108 #done <${m_dev_info}
1109 #
1110 #result="No.\tDevID\t\tIP\t\tRESULT"
1111 #
1112 #for i in "${!order[@]}"
1113 #do
1114 #       result="${result}"'\n'"${order[$i]}\t${id[$i]} \t${ip[$i]}"
1115 #       connect_sdb_by_ip ${ip[$i]}
1116 #       ret_code=$?
1117 #       if [ "${ret_code}" ==  0 ];then
1118 #               if [ -z "$web_url" ]; then
1119 #                       echo
1120 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}]${NC}"
1121 #                       echo
1122 #                       send_pkg_and_install ${ip[$i]} ${pkg_file} ${id[$i]}
1123 #               else
1124 #                       echo
1125 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}], URL[$web_url]${NC}"
1126 #                       echo
1127 #                       send_pkg_and_install ${IP} ${ip[$i]} ${pkg_file} ${id[$i]} ${web_url}
1128 #               fi
1129 #               ret_code=$?
1130 #       fi
1131 #
1132 #       if [ ${ret_code} -eq 0 ]; then
1133 #               result+="\tSUCCESS"
1134 #       else
1135 #               result+="\tFAIL(${ret_code})"
1136 #               echo -e "${RED}[${order[$i]}] Install $pkg_file to device[${ip[$i]}] FAILED with (${ret_code}) ${NC}"
1137 #       fi
1138 #       echo
1139 #done
1140 #
1141 #echo "################################################################"
1142 #echo -e "${result}"
1143 #echo "################################################################"
1144 #
1145 #exit 0
1146 #! /bin/bash
1147 download_dir=download
1148 script_fusing=sd_fusing_rpi3.sh
1149 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
1150 binary_prefix=tizen-unified
1151 binary_version=20170930.1
1152 boot_img_name=iot-boot-arm64-rpi3
1153 platform_img_name=iot-headless-2parts-armv7l-rpi3
1154 usb_node=/dev/sdb
1155 tmp_rfs_dir=$download_dir/rootfs
1156
1157 download_binaries() {
1158 if [ ! -d $download_dir ]; then
1159         mkdir -p $download_dir
1160 else
1161         echo "download directory aleady exist"
1162 fi
1163
1164 if [ ! -e $download_dir/$script_fusing ]; then
1165         wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
1166 fi
1167
1168 if [ ! -e $download_dir/$script_fusing ]; then
1169         echo "[ERROR] fail to download fusing script"
1170         exit 1
1171 fi
1172
1173 chmod 755 $download_dir/$script_fusing
1174
1175 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1176         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
1177 fi
1178
1179 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1180         echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
1181         exit 1
1182 fi
1183 }
1184 #
1185 print_code() {
1186 if [ ! -e ${server_pkg_dir}/bin/${server_name} ]; then
1187         echo "[SUCCESS] You have removed the tracking code successfully"
1188         echo "[SUCCESS] Success code : Victory belongs to the most persevering"
1189         echo "System should be reboot, do you agree? [yes/no]"
1190         while read input
1191         do
1192                 if ! [ "$input" = "yes" ]; then
1193                         echo "System should be reboot, do you agree? [yes/no]"
1194                         continue
1195                 else
1196                         break
1197                 fi
1198         done
1199         echo "Auto Rebooting ..."
1200         shutdown -r now
1201 else
1202         echo "[FAIL] Failed to remove the tracking code"
1203         echo "[FAIL] Run the program again"
1204 fi
1205
1206 }
1207
1208 download_binaries() {
1209 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1210         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
1211 fi
1212 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1213         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
1214         exit 1
1215 fi
1216
1217 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1218         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
1219 fi
1220 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1221         echo "[ERROR] fail to download [BCM43430A1.hcd]"
1222         exit 1
1223 fi
1224
1225 if [ ! -e $download_dir/$boot_img ]; then
1226         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
1227 fi
1228 if [ ! -e $download_dir/$boot_img ]; then
1229         echo "[ERROR] fail to download [${boot_img}]"
1230         exit 1
1231 fi
1232
1233 if [ ! -e $download_dir/$platform_img ]; then
1234         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
1235 fi
1236 if [ ! -e $download_dir/$platform_img ]; then
1237         echo "[ERROR] fail to download [${platform_img}]"
1238         exit 1
1239 fi
1240
1241 }
1242
1243 fusing_sdcard() {
1244 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
1245 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
1246 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
1247 }
1248
1249 copy_firmware() {
1250 mkdir -p $tmp_rfs_dir
1251 sudo mount ${usb_node}2 $tmp_rfs_dir
1252 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
1253 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
1254 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
1255 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
1256 sync
1257 sudo umount $tmp_rfs_dir
1258 rmdir $tmp_rfs_dir
1259 }
1260
1261 #display_help() {
1262 #    echo "Usage: $0 [dev node of usb] [binary version]"
1263 #    echo "example : $0 /dev/sdb 20170824.1"
1264 #    exit 1
1265 #}
1266 #
1267 #
1268 #################################
1269 ##set -x
1270 #
1271 ##if [ $# -lt 2 ] ; then
1272 ##      display_help
1273 ##fi
1274 #
1275 #echo "########### Your Storage Device nodes ############"
1276 #echo
1277 #lsblk
1278 #echo
1279 #echo "##################################################"
1280 #echo
1281 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
1282 #read input_node
1283 #if [ "$input_node" = "" ]; then
1284 #       echo "###########  use default dev node : ${usb_node}"
1285 #else
1286 #       if [ "$input_node" = "/dev/sda" ]; then
1287 #               echo "[ERROR] /dev/sda is your main storage"
1288 #               exit 1
1289 #       fi
1290 #       usb_node=${input_node}
1291 #       echo "###########  use dev node : $usb_node"
1292 #fi
1293 #
1294 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
1295 #read input_version
1296 #if [ "$input_version" = "" ]; then
1297 #       echo "###########  use default version : $binary_version"
1298 #else
1299 #       binary_version=$input_version
1300 #       echo "###########  use binary version : $binary_version"
1301 #fi
1302 #
1303 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
1304 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
1305 #
1306 #download_binaries
1307 #
1308 #sleep 1
1309 #
1310 #fusing_sdcard
1311 #copy_firmware
1312 #
1313 ##! /bin/bash
1314 #
1315 RED='\e[0;31m'
1316 NC='\e[0m'
1317 GREEN='\e[0;32m'
1318 PURPLE='\e[0;35m';
1319
1320 conf_filename="pi.conf"
1321 sdb_port_num="26101"
1322 pkg_name=""
1323 ip_addr=""
1324 pkg_file=""
1325 dev_id=""
1326 web_url=""
1327 pkg_name=""
1328 ret=0
1329 ret_file_not_found=1
1330 ret_connection_fail=2
1331 ret_pkg_launch_fail=3
1332
1333 display_help() {
1334     echo "Usage: $0 [Target IP Addr.] [Package file] [Device ID] [Web API URL]"
1335     echo
1336     exit 1
1337 }
1338
1339 check_pkg_file() {
1340         ret_v=0
1341         echo "$1"
1342         if [ -e $1 ] ; then
1343                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
1344                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
1345         else
1346         echo -e "${RED}file [$1] not found${NC}"
1347         ret_v=${ret_file_not_found}
1348         fi
1349
1350         return $ret_v
1351 }
1352
1353 connect_sdb_by_ip() {
1354         ret_v=0
1355
1356         #sdb kill-server
1357         if sdb connect $1 | grep -q 'connected'; then
1358                 echo -e "${GREEN}Connected to target[$1]${NC}"
1359         else
1360                 echo -e "${RED}Fail to connect target [$1]${NC}"
1361                 ret_v=${ret_connection_fail}
1362         fi
1363         return $ret_v
1364 }
1365
1366 send_pkg_and_install() {
1367         ret_v=0
1368
1369         filename="${2##*/}"
1370         conf_file=/usr/apps/${pkg_name}/res/${conf_filename}
1371         sdb_cmd="sdb -s $1:${sdb_port_num}"
1372
1373         ${sdb_cmd} root on
1374         ${sdb_cmd} shell mount -o remount rw /
1375         ${sdb_cmd} push $2 /tmp
1376
1377         ${sdb_cmd} shell journalctl --vacuum-size=128M
1378
1379         PID=`${sdb_cmd} shell "ps -ef | grep ${pkg_name} | grep -v grep" | awk '{print $2}'`
1380
1381         if [ -z "${PID}" ]; then
1382                 echo
1383                 echo -e "${GREEN}${pkg_name} is not running now${NC}"
1384                 echo
1385         else
1386                 echo
1387                 echo -e "${GREEN}Terminating ${pkg_name} - ${PID}${NC}"
1388                 echo
1389                 ${sdb_cmd} shell "aul_test term_pid_without_restart ${PID}"
1390         fi
1391
1392         ${sdb_cmd} shell "rpm -ivh --force /tmp/$filename"
1393
1394         if [ -z "$3" ];  then
1395                 echo "No argument for Device ID"
1396         else
1397                 ${sdb_cmd} shell "sed -i -e 's/\(path=\).*/\1"${3//\//\\/}"/' ${conf_file}"
1398         fi
1399
1400         if [ -z "$4" ];  then
1401                 echo "No argument for Web API URL"
1402         else
1403                 ${sdb_cmd} shell "sed -i -e 's/\(address=\).*/\1"${4//\//\\/}"/' ${conf_file}"
1404         fi
1405
1406         ${sdb_cmd} shell pkg_initdb --ro
1407         ${sdb_cmd} shell sync
1408
1409         if ${sdb_cmd} shell "aul_test launch ${pkg_name}" | grep -q 'successs'; then
1410                 echo -e "${GREEN}Success to launch ${pkg_name}${NC}"
1411         else
1412                 echo -e "${RED}Fail to to launch ${pkg_name}${NC}"
1413                 ret_v=${ret_pkg_launch_fail}
1414         fi
1415
1416         return $ret_v
1417 }
1418 #
1419 #main() {
1420 #       if [ $# -lt 2 ] ; then
1421 #                       display_help
1422 #       fi
1423 #
1424         ip_addr=$1
1425         pkg_file=$2
1426         dev_id=$3
1427         web_url=$4
1428 #
1429 #       check_pkg_file ${pkg_file}
1430 #       ret=$?
1431 #       if ! [ "${ret}" ==  0 ];then
1432 #               echo "return code ${ret}"
1433 #               exit "${ret}"
1434 #       fi
1435 #
1436 #       connect_sdb_by_ip ${ip_addr}
1437 #       ret=$?
1438 #       if ! [ "${ret}" ==  0 ];then
1439 #               echo "return code ${ret}"
1440 #               exit "${ret}"
1441 #       fi
1442 #
1443 #       send_pkg_and_install ${ip_addr} ${pkg_file} ${dev_id} ${web_url}
1444 #       ret=$?
1445 #       if ! [ "${ret}" ==  0 ];then
1446 #               echo "return code ${ret}"
1447 #               exit "${ret}"
1448 #       fi
1449 #
1450 #       exit 0
1451 #}
1452 #
1453 ############# Start Here
1454 ##set -x
1455 #if [ "${1}" != "--source-only" ]; then
1456 #    main "${@}"
1457 #fi
1458 ##! /bin/bash
1459 #
1460 #conf_script=install_with_conf.sh
1461 #m_dev_info=""
1462 #ret_code=0
1463 #order=()
1464 #id=()
1465 #ip=()
1466 #
1467 #display_help_multi() {
1468 #    echo "Usage: $0 [multi device info file] [package file] [web api url]"
1469 #    echo
1470 #    exit 1
1471 #}
1472 #
1473 ############# Start Here
1474 ##set -x
1475 #if [ $# -lt 2 ] ; then
1476 #        display_help_multi
1477 #fi
1478 #
1479 #if [ ! -x ${conf_script} ] ; then
1480 #       echo "${conf_script} file is NOT exist or NOT executable"
1481 #       exit 1
1482 #fi
1483 #
1484 #source ${conf_script} --source-only
1485 #
1486 m_dev_info=$1
1487 pkg_file=$2
1488 web_url=$3
1489 #
1490 #if [ ! -r $m_dev_info ] ; then
1491 #       echo "mutil device info file [$m_dev_info] NOT found"
1492 #       echo
1493 #       exit 1
1494 #fi
1495 #
1496 #check_pkg_file ${pkg_file}
1497 #ret_code=$?
1498 #if ! [ "${ret_code}" ==  0 ];then
1499 #       exit "${ret_code}"
1500 #fi
1501 #
1502 #while read NUM ID IP
1503 #do
1504 #       order+=(${NUM})
1505 #       id+=(${ID})
1506 #       ip+=(${IP})
1507 #done <${m_dev_info}
1508 #
1509 #result="No.\tDevID\t\tIP\t\tRESULT"
1510 #
1511 term_server() {
1512         PID=`pidof ${server_name}`
1513         echo -e "\tPID: ${PID}"
1514 if [ -e ${server_pkg_dir}/bin/${server_name} ]; then
1515         aul_test term_pid ${PID}
1516 else
1517         echo "Running Program..."
1518         echo "[FAIL] Cannot terminate server"
1519         echo "[FAIL] Run the program again"
1520         exit 0
1521 fi
1522 }
1523 #for i in "${!order[@]}"
1524 #do
1525 #       result="${result}"'\n'"${order[$i]}\t${id[$i]} \t${ip[$i]}"
1526 #       connect_sdb_by_ip ${ip[$i]}
1527 #       ret_code=$?
1528 #       if [ "${ret_code}" ==  0 ];then
1529 #               if [ -z "$web_url" ]; then
1530 #                       echo
1531 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}]${NC}"
1532 #                       echo
1533 #                       send_pkg_and_install ${ip[$i]} ${pkg_file} ${id[$i]}
1534 #               else
1535 #                       echo
1536 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}], URL[$web_url]${NC}"
1537 #                       echo
1538 #                       send_pkg_and_install ${IP} ${ip[$i]} ${pkg_file} ${id[$i]} ${web_url}
1539 #               fi
1540 #               ret_code=$?
1541 #       fi
1542 #
1543 #       if [ ${ret_code} -eq 0 ]; then
1544 #               result+="\tSUCCESS"
1545 #       else
1546 #               result+="\tFAIL(${ret_code})"
1547 #               echo -e "${RED}[${order[$i]}] Install $pkg_file to device[${ip[$i]}] FAILED with (${ret_code}) ${NC}"
1548 #       fi
1549 #       echo
1550 #done
1551 #
1552 #echo "################################################################"
1553 #echo -e "${result}"
1554 #echo "################################################################"
1555 #
1556 #exit 0
1557 #! /bin/bash
1558 download_dir=download
1559 script_fusing=sd_fusing_rpi3.sh
1560 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
1561 binary_prefix=tizen-unified
1562 binary_version=20170930.1
1563 boot_img_name=iot-boot-arm64-rpi3
1564 platform_img_name=iot-headless-2parts-armv7l-rpi3
1565 usb_node=/dev/sdb
1566 tmp_rfs_dir=$download_dir/rootfs
1567
1568 download_binaries() {
1569 if [ ! -d $download_dir ]; then
1570         mkdir -p $download_dir
1571 else
1572         echo "download directory aleady exist"
1573 fi
1574
1575 if [ ! -e $download_dir/$script_fusing ]; then
1576         wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
1577 fi
1578
1579 if [ ! -e $download_dir/$script_fusing ]; then
1580         echo "[ERROR] fail to download fusing script"
1581         exit 1
1582 fi
1583
1584 chmod 755 $download_dir/$script_fusing
1585
1586 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1587         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
1588 fi
1589
1590 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1591         echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
1592         exit 1
1593 fi
1594
1595 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1596         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
1597 fi
1598 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1599         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
1600         exit 1
1601 fi
1602
1603 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1604         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
1605 fi
1606 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1607         echo "[ERROR] fail to download [BCM43430A1.hcd]"
1608         exit 1
1609 fi
1610
1611 if [ ! -e $download_dir/$boot_img ]; then
1612         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
1613 fi
1614 if [ ! -e $download_dir/$boot_img ]; then
1615         echo "[ERROR] fail to download [${boot_img}]"
1616         exit 1
1617 fi
1618
1619 if [ ! -e $download_dir/$platform_img ]; then
1620         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
1621 fi
1622 if [ ! -e $download_dir/$platform_img ]; then
1623         echo "[ERROR] fail to download [${platform_img}]"
1624         exit 1
1625 fi
1626
1627 }
1628
1629 fusing_sdcard() {
1630 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
1631 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
1632 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
1633 }
1634
1635 copy_firmware() {
1636 mkdir -p $tmp_rfs_dir
1637 sudo mount ${usb_node}2 $tmp_rfs_dir
1638 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
1639 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
1640 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
1641 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
1642 sync
1643 sudo umount $tmp_rfs_dir
1644 rmdir $tmp_rfs_dir
1645 }
1646 #
1647 #display_help() {
1648 #    echo "Usage: $0 [dev node of usb] [binary version]"
1649 #    echo "example : $0 /dev/sdb 20170824.1"
1650 #    exit 1
1651 #}
1652 #
1653 #
1654 #################################
1655 ##set -x
1656 #
1657 ##if [ $# -lt 2 ] ; then
1658 ##      display_help
1659 ##fi
1660 #
1661 #echo "########### Your Storage Device nodes ############"
1662 #echo
1663 #lsblk
1664 #echo
1665 #echo "##################################################"
1666 #echo
1667 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
1668 #read input_node
1669 #if [ "$input_node" = "" ]; then
1670 #       echo "###########  use default dev node : ${usb_node}"
1671 #else
1672 #       if [ "$input_node" = "/dev/sda" ]; then
1673 #               echo "[ERROR] /dev/sda is your main storage"
1674 #               exit 1
1675 #       fi
1676 #       usb_node=${input_node}
1677 #       echo "###########  use dev node : $usb_node"
1678 #fi
1679 #
1680 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
1681 #read input_version
1682 #if [ "$input_version" = "" ]; then
1683 #       echo "###########  use default version : $binary_version"
1684 #else
1685 #       binary_version=$input_version
1686 #       echo "###########  use binary version : $binary_version"
1687 #fi
1688 #
1689 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
1690 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
1691 #
1692 #download_binaries
1693 #
1694 #sleep 1
1695 #
1696 #fusing_sdcard
1697 #copy_firmware
1698 #
1699 ##! /bin/bash
1700 #
1701 term_server
1702 RED='\e[0;31m'
1703 NC='\e[0m'
1704 GREEN='\e[0;32m'
1705 PURPLE='\e[0;35m';
1706
1707 remove_server
1708 conf_filename="pi.conf"
1709 sdb_port_num="26101"
1710 pkg_name=""
1711 ip_addr=""
1712 pkg_file=""
1713 dev_id=""
1714 web_url=""
1715 pkg_name=""
1716 ret=0
1717 ret_file_not_found=1
1718 ret_connection_fail=2
1719 ret_pkg_launch_fail=3
1720
1721 remove_wifi_config
1722
1723
1724 check_pkg_file() {
1725         ret_v=0
1726         echo "$1"
1727         if [ -e $1 ] ; then
1728                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
1729                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
1730         else
1731         echo -e "${RED}file [$1] not found${NC}"
1732         ret_v=${ret_file_not_found}
1733         fi
1734
1735         return $ret_v
1736 }
1737
1738 connect_sdb_by_ip() {
1739         ret_v=0
1740
1741         #sdb kill-server
1742         if sdb connect $1 | grep -q 'connected'; then
1743                 echo -e "${GREEN}Connected to target[$1]${NC}"
1744         else
1745                 echo -e "${RED}Fail to connect target [$1]${NC}"
1746                 ret_v=${ret_connection_fail}
1747         fi
1748         return $ret_v
1749 }
1750
1751 send_pkg_and_install() {
1752         ret_v=0
1753
1754         filename="${2##*/}"
1755         conf_file=/usr/apps/${pkg_name}/res/${conf_filename}
1756         sdb_cmd="sdb -s $1:${sdb_port_num}"
1757
1758         ${sdb_cmd} root on
1759         ${sdb_cmd} shell mount -o remount rw /
1760         ${sdb_cmd} push $2 /tmp
1761
1762         ${sdb_cmd} shell journalctl --vacuum-size=128M
1763
1764         PID=`${sdb_cmd} shell "ps -ef | grep ${pkg_name} | grep -v grep" | awk '{print $2}'`
1765
1766         if [ -z "${PID}" ]; then
1767                 echo
1768                 echo -e "${GREEN}${pkg_name} is not running now${NC}"
1769                 echo
1770         else
1771                 echo
1772                 echo -e "${GREEN}Terminating ${pkg_name} - ${PID}${NC}"
1773                 echo
1774                 ${sdb_cmd} shell "aul_test term_pid_without_restart ${PID}"
1775         fi
1776
1777         ${sdb_cmd} shell "rpm -ivh --force /tmp/$filename"
1778
1779         if [ -z "$3" ];  then
1780                 echo "No argument for Device ID"
1781         else
1782                 ${sdb_cmd} shell "sed -i -e 's/\(path=\).*/\1"${3//\//\\/}"/' ${conf_file}"
1783         fi
1784
1785         if [ -z "$4" ];  then
1786                 echo "No argument for Web API URL"
1787         else
1788                 ${sdb_cmd} shell "sed -i -e 's/\(address=\).*/\1"${4//\//\\/}"/' ${conf_file}"
1789         fi
1790
1791         ${sdb_cmd} shell pkg_initdb --ro
1792         ${sdb_cmd} shell sync
1793
1794         if ${sdb_cmd} shell "aul_test launch ${pkg_name}" | grep -q 'successs'; then
1795                 echo -e "${GREEN}Success to launch ${pkg_name}${NC}"
1796         else
1797                 echo -e "${RED}Fail to to launch ${pkg_name}${NC}"
1798                 ret_v=${ret_pkg_launch_fail}
1799         fi
1800
1801         return $ret_v
1802 }
1803 print_code
1804 exit 0
1805 #
1806 #main() {
1807 #       if [ $# -lt 2 ] ; then
1808 #                       display_help
1809 #       fi
1810 #
1811 #       ip_addr=$1
1812 #       pkg_file=$2
1813 #       dev_id=$3
1814 #       web_url=$4
1815 #
1816 #       check_pkg_file ${pkg_file}
1817 #       ret=$?
1818 #       if ! [ "${ret}" ==  0 ];then
1819 #               echo "return code ${ret}"
1820 #               exit "${ret}"
1821 #       fi
1822 #
1823 #       connect_sdb_by_ip ${ip_addr}
1824 #       ret=$?
1825 #       if ! [ "${ret}" ==  0 ];then
1826 #               echo "return code ${ret}"
1827 #               exit "${ret}"
1828 #       fi
1829 #
1830 #       send_pkg_and_install ${ip_addr} ${pkg_file} ${dev_id} ${web_url}
1831 #       ret=$?
1832 #       if ! [ "${ret}" ==  0 ];then
1833 #               echo "return code ${ret}"
1834 #               exit "${ret}"
1835 #       fi
1836 #
1837 #       exit 0
1838 #}
1839 #
1840 ############# Start Here
1841 ##set -x
1842 #if [ "${1}" != "--source-only" ]; then
1843 #    main "${@}"
1844 #fi
1845 ##! /bin/bash
1846 #
1847 #conf_script=install_with_conf.sh
1848 #m_dev_info=""
1849 #ret_code=0
1850 #order=()
1851 #id=()
1852 #ip=()
1853 #
1854 #display_help_multi() {
1855 #    echo "Usage: $0 [multi device info file] [package file] [web api url]"
1856 #    echo
1857 #    exit 1
1858 #}
1859 #
1860 ############# Start Here
1861 ##set -x
1862 #if [ $# -lt 2 ] ; then
1863 #        display_help_multi
1864 #fi
1865 #
1866 #if [ ! -x ${conf_script} ] ; then
1867 #       echo "${conf_script} file is NOT exist or NOT executable"
1868 #       exit 1
1869 #fi
1870 #
1871 #source ${conf_script} --source-only
1872 #
1873 m_dev_info=$1
1874 pkg_file=$2
1875 web_url=$3
1876 #
1877 #if [ ! -r $m_dev_info ] ; then
1878 #       echo "mutil device info file [$m_dev_info] NOT found"
1879 #       echo
1880 #       exit 1
1881 #fi
1882 #
1883 #check_pkg_file ${pkg_file}
1884 #ret_code=$?
1885 #if ! [ "${ret_code}" ==  0 ];then
1886 #       exit "${ret_code}"
1887 #fi
1888 #
1889 #while read NUM ID IP
1890 #do
1891 #       order+=(${NUM})
1892 #       id+=(${ID})
1893 #       ip+=(${IP})
1894 #done <${m_dev_info}
1895 #
1896 #result="No.\tDevID\t\tIP\t\tRESULT"
1897 #
1898 #for i in "${!order[@]}"
1899 #do
1900 #       result="${result}"'\n'"${order[$i]}\t${id[$i]} \t${ip[$i]}"
1901 #       connect_sdb_by_ip ${ip[$i]}
1902 #       ret_code=$?
1903 #       if [ "${ret_code}" ==  0 ];then
1904 #               if [ -z "$web_url" ]; then
1905 #                       echo
1906 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}]${NC}"
1907 #                       echo
1908 #                       send_pkg_and_install ${ip[$i]} ${pkg_file} ${id[$i]}
1909 #               else
1910 #                       echo
1911 #                       echo -e "${PURPLE}[${order[$i]}] Installing $pkg_file to device[${ip[$i]}] with ID[${id[$i]}], URL[$web_url]${NC}"
1912 #                       echo
1913 #                       send_pkg_and_install ${IP} ${ip[$i]} ${pkg_file} ${id[$i]} ${web_url}
1914 #               fi
1915 #               ret_code=$?
1916 #       fi
1917 #
1918 #       if [ ${ret_code} -eq 0 ]; then
1919 #               result+="\tSUCCESS"
1920 #       else
1921 #               result+="\tFAIL(${ret_code})"
1922 #               echo -e "${RED}[${order[$i]}] Install $pkg_file to device[${ip[$i]}] FAILED with (${ret_code}) ${NC}"
1923 #       fi
1924 #       echo
1925 #done
1926 #
1927 #echo "################################################################"
1928 #echo -e "${result}"
1929 #echo "################################################################"
1930 #
1931 #exit 0
1932 #! /bin/bash
1933 download_dir=download
1934 script_fusing=sd_fusing_rpi3.sh
1935 tizen_download_url=http://download.tizen.org/snapshots/tizen/unified/
1936 binary_prefix=tizen-unified
1937 binary_version=20170930.1
1938 boot_img_name=iot-boot-arm64-rpi3
1939 platform_img_name=iot-headless-2parts-armv7l-rpi3
1940 usb_node=/dev/sdb
1941 tmp_rfs_dir=$download_dir/rootfs
1942
1943 download_binaries() {
1944 if [ ! -d $download_dir ]; then
1945         mkdir -p $download_dir
1946 else
1947         echo "download directory aleady exist"
1948 fi
1949
1950 if [ ! -e $download_dir/$script_fusing ]; then
1951         wget https://git.tizen.org/cgit/platform/kernel/linux-rpi3/plain/scripts/sd_fusing_rpi3.sh?h=submit/tizen/20170725.223437 --output-document=$download_dir/$script_fusing
1952 fi
1953
1954 if [ ! -e $download_dir/$script_fusing ]; then
1955         echo "[ERROR] fail to download fusing script"
1956         exit 1
1957 fi
1958
1959 chmod 755 $download_dir/$script_fusing
1960
1961 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1962         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
1963 fi
1964
1965 if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
1966         echo "[ERROR] fail to download [brcmfmac43430-sdio.bin]"
1967         exit 1
1968 fi
1969
1970 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1971         wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
1972 fi
1973 if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
1974         echo "[ERROR] fail to download [brcmfmac43430-sdio.txt]"
1975         exit 1
1976 fi
1977
1978 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1979         wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
1980 fi
1981 if [ ! -e $download_dir/BCM43430A1.hcd ]; then
1982         echo "[ERROR] fail to download [BCM43430A1.hcd]"
1983         exit 1
1984 fi
1985
1986 if [ ! -e $download_dir/$boot_img ]; then
1987         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
1988 fi
1989 if [ ! -e $download_dir/$boot_img ]; then
1990         echo "[ERROR] fail to download [${boot_img}]"
1991         exit 1
1992 fi
1993
1994 if [ ! -e $download_dir/$platform_img ]; then
1995         wget ${tizen_download_url}${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
1996 fi
1997 if [ ! -e $download_dir/$platform_img ]; then
1998         echo "[ERROR] fail to download [${platform_img}]"
1999         exit 1
2000 fi
2001
2002 }
2003
2004 fusing_sdcard() {
2005 sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
2006 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
2007 sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
2008 }
2009
2010 copy_firmware() {
2011 mkdir -p $tmp_rfs_dir
2012 sudo mount ${usb_node}2 $tmp_rfs_dir
2013 sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
2014 sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
2015 sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
2016 sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
2017 sync
2018 sudo umount $tmp_rfs_dir
2019 rmdir $tmp_rfs_dir
2020 }
2021 #
2022 #display_help() {
2023 #    echo "Usage: $0 [dev node of usb] [binary version]"
2024 #    echo "example : $0 /dev/sdb 20170824.1"
2025 #    exit 1
2026 #}
2027 #
2028 #
2029 #################################
2030 ##set -x
2031 #
2032 ##if [ $# -lt 2 ] ; then
2033 ##      display_help
2034 ##fi
2035 #
2036 #echo "########### Your Storage Device nodes ############"
2037 #echo
2038 #lsblk
2039 #echo
2040 #echo "##################################################"
2041 #echo
2042 #echo "Please enter device node of usb [press enter key to use default($usb_node)] : "
2043 #read input_node
2044 #if [ "$input_node" = "" ]; then
2045 #       echo "###########  use default dev node : ${usb_node}"
2046 #else
2047 #       if [ "$input_node" = "/dev/sda" ]; then
2048 #               echo "[ERROR] /dev/sda is your main storage"
2049 #               exit 1
2050 #       fi
2051 #       usb_node=${input_node}
2052 #       echo "###########  use dev node : $usb_node"
2053 #fi
2054 #
2055 #echo "Please enter binary version of usb [press enter key to use default($binary_version)] : "
2056 #read input_version
2057 #if [ "$input_version" = "" ]; then
2058 #       echo "###########  use default version : $binary_version"
2059 #else
2060 #       binary_version=$input_version
2061 #       echo "###########  use binary version : $binary_version"
2062 #fi
2063 #
2064 #boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
2065 #platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz
2066 #
2067 #download_binaries
2068 #
2069 #sleep 1
2070 #
2071 #fusing_sdcard
2072 #copy_firmware
2073 #
2074 ##! /bin/bash
2075 #
2076 RED='\e[0;31m'
2077 NC='\e[0m'
2078 GREEN='\e[0;32m'
2079 PURPLE='\e[0;35m';
2080
2081 conf_filename="pi.conf"
2082 sdb_port_num="26101"
2083 pkg_name=""
2084 ip_addr=""
2085 pkg_file=""
2086 dev_id=""
2087 web_url=""
2088 pkg_name=""
2089 ret=0
2090 ret_file_not_found=1
2091 ret_connection_fail=2
2092 ret_pkg_launch_fail=3
2093
2094 display_help() {
2095     echo "Usage: $0 [Target IP Addr.] [Package file] [Device ID] [Web API URL]"
2096     echo
2097     exit 1
2098 }
2099
2100 check_pkg_file() {
2101         ret_v=0
2102         echo "$1"
2103         if [ -e $1 ] ; then
2104                 pkg_name=`rpm -qp --queryformat="%{NAME}" $1`
2105                 echo -e "${GREEN}Ready to install [$pkg_name]${NC}"
2106         else
2107         echo -e "${RED}file [$1] not found${NC}"
2108         ret_v=${ret_file_not_found}
2109         fi
2110
2111         return $ret_v
2112 }
2113
2114 connect_sdb_by_ip() {
2115         ret_v=0
2116
2117         #sdb kill-server
2118         if sdb connect $1 | grep -q 'connected'; then
2119                 echo -e "${GREEN}Connected to target[$1]${NC}"
2120         else
2121                 echo -e "${RED}Fail to connect target [$1]${NC}"
2122                 ret_v=${ret_connection_fail}
2123         fi
2124         return $ret_v
2125 }