Use third party libxml
[platform/framework/web/chromium-efl.git] / tizen_src / scripts / tizensync.sh
1 #! /bin/bash
2
3 # Fast push/pull with Tizen device (or emulator).
4 # Uses rsync which means faster reupload of libraries after recompilation as only the diff has to be uploaded.
5
6 usage() {
7     cat << EOF
8 usage: $0 (push|pull) src dst
9
10 EOF
11 }
12
13 die() {
14     echo "ERROR at $1:$2"
15     usage
16     exit 1
17 }
18
19 trap 'die $0 $LINENO' ERR SIGINT SIGTERM SIGQUIT
20
21 if echo "$@" | grep -Eqw "\-h|\-\-help"; then
22     usage
23     exit 0
24 fi
25
26 [ "$#" == "3" ]
27
28 src=$2
29 dst=$3
30 if [ "$1" == "push" ]; then
31     src=$(readlink -f $src)
32     [ -f $src ]
33 elif [ "$1" == "pull" ]; then
34     # NOTE: dirname "" is .
35     [ -d $(dirname "$dst") ]
36 else
37     false
38 fi
39
40 SCRIPT_PATH=$(readlink -f "$(dirname $0)")
41
42 # Hard-coded, live with it!
43 PORT=9128
44 USER=root
45
46 sdb start-server
47 sdb root on >/dev/null
48 sdb shell "change-booting-mode.sh --update" >/dev/null
49
50 # Start sshd on device if not running.
51 function startSSHD() {
52 sdb shell << EOF
53 if [ ! -f "/var/run/sshd.pid" ]; then
54     mkdir -m 700 /var/run/sshd &>/dev/null
55     /usr/sbin/sshd
56 fi
57 exit
58 EOF
59 }
60
61 startSSHD >/dev/null
62
63 fileExistsOnDevice() {
64     lsout=$(sdb shell "ls $1 2>/dev/null")
65     ([ -n "$lsout" ] && echo 1) || echo 0
66 }
67
68 if [ "$(fileExistsOnDevice /root/.ssh/authorized_keys)" -eq 0 ]; then
69     echo "setting up /root/.ssh/authorized_keys"
70     sdb shell "mkdir /root/.ssh" &>/dev/null
71     sdb push "$HOME/.ssh/id_rsa.pub" "/root/.ssh/authorized_keys"
72 fi
73 if [ "$(fileExistsOnDevice /usr/local/bin/rsync)" -eq 0 ]; then
74     echo "installing rsync on device"
75     PREBUILD_PATH=$(readlink -f $SCRIPT_PATH/../build/prebuild)
76     sdb push "$PREBUILD_PATH/rsync" /usr/local/bin
77 fi
78
79 # It's ok to do the forwarding multiple times.
80 sdb forward tcp:$PORT tcp:22 || (\
81     >&2 echo "ERROR: sdb port forward failed"; \
82     >&2 echo "Hint: if you have /root/.ssh/authorized_keys file on your device make sure it contains your public key."; \
83     false)
84
85 do_rsync() {
86     rsync -axzH -e "ssh -oStrictHostKeyChecking=no -p $PORT" $1 $2
87 }
88
89 if [ "$1" == "push" ]; then
90     do_rsync $src $USER@localhost:$dst
91 else
92     do_rsync $USER@localhost:$src $dst
93 fi