~azzar1/unity8/launcher-tooltips

« back to all changes in this revision

Viewing changes to run_on_device.sh

  • Committer: Bileto Bot
  • Author(s): Michael Zanetti
  • Date: 2016-08-11 06:22:51 UTC
  • mfrom: (2542.1.6 unity8-main-build-scripts)
  • Revision ID: ci-train-bot@canonical.com-20160811062251-1qy0g9dt7v0ertu1
Clean up some build script legacy

Approved by: Albert Astals Cid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
CODE_DIR=shell
3
 
USER=phablet
4
 
USER_ID=32011
5
 
PACKAGE=unity8
6
 
BINARY=unity8
7
 
TARGET_IP=127.0.0.1
8
 
TARGET_SSH_PORT=2222
9
 
TARGET_DEBUG_PORT=3768
10
 
RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
11
 
SETUP=false
12
 
GDB=false
13
 
PINLOCK=false
14
 
KEYLOCK=false
15
 
NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
16
 
FLIPPED=false
17
 
SSH_WAS_STARTED=0
18
 
SSH_STARTED=0
19
 
PASSWORD=""
20
 
PASSFILE=""
21
 
 
22
 
usage() {
23
 
    echo "usage: run_on_device -a SUDO_PASSWORD [OPTIONS]"
24
 
    echo
25
 
    echo "Script to setup a build environment for the shell and sync build and run it on the device"
26
 
    echo
27
 
    echo "OPTIONS:"
28
 
    echo "  -a, --password  The sudo password to use"
29
 
    echo "  -s, --setup     Setup the build environment"
30
 
    echo "  -g, --gdb       Run with gdb"
31
 
    echo "  -p, --pinlock   Enable a PIN lock screen when running"
32
 
    echo "  -k, --keylock   Enable a Keyboard lock screen when running"
33
 
    echo
34
 
    echo "IMPORTANT:"
35
 
    echo " * Make sure to have networking setup on the device beforehand."
36
 
    echo " * Execute that script from a directory containing unity8 code."
37
 
    exit 1
38
 
}
39
 
 
40
 
start_ssh() {
41
 
    if [ $SSH_STARTED -eq 0 ]; then
42
 
        adb_sudo initctl start ssh
43
 
        SSH_STARTED=1
44
 
    fi
45
 
}
46
 
 
47
 
exec_with_ssh() {
48
 
    start_ssh
49
 
    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
50
 
}
51
 
 
52
 
adb_sudo() {
53
 
    adb shell "SUDO_ASKPASS=${PASSFILE} sudo --askpass $@"
54
 
}
55
 
 
56
 
install_ssh_key() {
57
 
    HOME_DIR="/home/phablet"
58
 
    adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
59
 
    adb shell chmod 700 $HOME_DIR/.ssh
60
 
    adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
61
 
}
62
 
 
63
 
setup_adb_forwarding() {
64
 
    adb forward tcp:$TARGET_SSH_PORT tcp:22
65
 
    adb forward tcp:$TARGET_DEBUG_PORT tcp:$TARGET_DEBUG_PORT
66
 
}
67
 
 
68
 
install_dependencies() {
69
 
    phablet-config writable-image --remotepassword ${PASSWORD} -p build-essential \
70
 
                                                               -p rsync \
71
 
                                                               -p bzr \
72
 
                                                               -p ccache \
73
 
                                                               -p gdb \
74
 
                                                               -p ninja-build \
75
 
                                                               -p devscripts \
76
 
                                                               -p equivs
77
 
}
78
 
 
79
 
sync_code() {
80
 
    [ -e .bzr ] && bzr export --uncommitted --format=dir /tmp/$CODE_DIR
81
 
    [ -e .git ] && git checkout-index -a -f --prefix=/tmp/$CODE_DIR/
82
 
    start_ssh
83
 
    rsync -crlOzv --delete --exclude builddir -e "ssh -p $TARGET_SSH_PORT -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" /tmp/$CODE_DIR/ $USER@$TARGET_IP:$CODE_DIR/
84
 
    rm -rf /tmp/$CODE_DIR
85
 
}
86
 
 
87
 
build() {
88
 
    exec_with_ssh PATH=/usr/lib/ccache:$PATH "cd $CODE_DIR/ && PATH=/usr/lib/ccache:$PATH ./build.sh"
89
 
}
90
 
 
91
 
run() {
92
 
    ARGS="--nomousetouch"
93
 
    if $GDB; then
94
 
        ARGS="$ARGS --gdb"
95
 
    fi
96
 
    if $PINLOCK; then
97
 
        ARGS="$ARGS -p"
98
 
    fi
99
 
    if $KEYLOCK; then
100
 
        ARGS="$ARGS -k"
101
 
    fi
102
 
 
103
 
    exec_with_ssh "stop unity8"
104
 
    exec_with_ssh "start maliit-server"
105
 
    exec_with_ssh "cd $CODE_DIR/ && ./run.sh $ARGS -- $RUN_OPTIONS"
106
 
    exec_with_ssh "stop maliit-server"
107
 
    exec_with_ssh "start unity8"
108
 
}
109
 
 
110
 
set -- `getopt -n$0 -u -a --longoptions="password:,setup,gdb,pinlock,keylock,help" "a:sgpkh" "$@"`
111
 
 
112
 
# FIXME: giving incorrect arguments does not call usage and exit
113
 
while [ $# -gt 0 ]
114
 
do
115
 
    case "$1" in
116
 
       -a|--password)    PASSWORD=$2;;
117
 
       -s|--setup)   SETUP=true;;
118
 
       -g|--gdb)     GDB=true;;
119
 
       -p|--pinlock)     PINLOCK=true;;
120
 
       -k|--keylock)     KEYLOCK=true;;
121
 
       -h|--help)    usage;;
122
 
       --)           shift;break;;
123
 
    esac
124
 
    shift
125
 
done
126
 
 
127
 
if [ -z "${PASSWORD}" ]; then
128
 
    echo "ERROR: You need to provide a sudo password..."
129
 
    echo
130
 
    usage
131
 
fi
132
 
 
133
 
PASSFILE=$(adb shell 'mktemp' | tr -d '\r')
134
 
adb shell "echo '#!/bin/sh' > ${PASSFILE}"
135
 
adb shell "echo \"echo \\\"${PASSWORD}\\\"\" >> ${PASSFILE}"
136
 
adb shell "chmod +x ${PASSFILE}"
137
 
 
138
 
setup_adb_forwarding
139
 
 
140
 
status_output=$(adb_sudo initctl status ssh)
141
 
if [[ $status_output == "ssh start/running, process "* ]]; then
142
 
    SSH_WAS_STARTED=1
143
 
fi
144
 
SSH_STARTED=$SSH_WAS_STARTED
145
 
 
146
 
if $SETUP; then
147
 
    echo "Setting up environment for building shell.."
148
 
    install_ssh_key
149
 
    install_dependencies
150
 
    sync_code
151
 
else
152
 
    echo "Transferring code.."
153
 
    sync_code
154
 
    echo "Building.."
155
 
    build
156
 
    echo "Running.."
157
 
    run
158
 
fi
159
 
 
160
 
adb shell "rm ${PASSFILE}"
161
 
 
162
 
if [ $SSH_WAS_STARTED -eq 0 ]; then
163
 
    adb_sudo initctl stop ssh
164
 
fi