~renatofilho/gallery-app/use-mediaplayer-components

« back to all changes in this revision

Viewing changes to runOnDevice.sh

  • Committer: Guenter Schwann
  • Date: 2013-08-16 13:01:43 UTC
  • mto: This revision was merged to the branch mainline in revision 815.
  • Revision ID: guenter.schwann@canonical.com-20130816130143-d7kgvtq2rik11se5
Add script to compile and run gallery on the device

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
CODE_DIR=gallery
 
3
USER=phablet
 
4
USER_ID=32011
 
5
PASSWORD=phablet
 
6
PACKAGE=gallery-app
 
7
BINARY=gallery-app
 
8
TARGET_IP=127.0.0.1
 
9
TARGET_SSH_PORT=2222
 
10
TARGET_DEBUG_PORT=3768
 
11
RUN_OPTIONS="--startup-timer --desktop_file_hint=/usr/share/applications/gallery-app.desktop"
 
12
# -qmljsdebugger=port:$TARGET_DEBUG_PORT"
 
13
SETUP=false
 
14
SUDO="echo $PASSWORD | sudo -S"
 
15
 
 
16
usage() {
 
17
    echo "usage: run_on_device [OPTIONS]\n"
 
18
    echo "Script to setup a build environment for the gallery and sync build and run it on the device\n"
 
19
    echo "OPTIONS:"
 
20
    echo "  -s, --setup   Setup the build environment"
 
21
    echo ""
 
22
    echo "IMPORTANT:"
 
23
    echo " * Make sure to have the networking and PPAs setup on the device beforehand (phablet-deploy-networking && phablet-ppa-fetch)."
 
24
    echo " * Execute that script from a directory containing a branch the shell code."
 
25
    exit 1
 
26
}
 
27
 
 
28
exec_with_ssh() {
 
29
    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT "bash -ic \"$@\""
 
30
}
 
31
 
 
32
exec_with_adb() {
 
33
    adb shell chroot /data/ubuntu /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
 
34
}
 
35
 
 
36
adb_root() {
 
37
    adb root
 
38
    adb wait-for-device
 
39
}
 
40
 
 
41
install_ssh_key() {
 
42
    adb shell "apt-get install openssh-server"
 
43
    ssh-keygen -R $TARGET_IP
 
44
    HOME_DIR=/data/ubuntu/home/phablet
 
45
    adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
 
46
    adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh
 
47
    adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh/authorized_keys
 
48
    adb shell chmod 700 $HOME_DIR/.ssh
 
49
    adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
 
50
}
 
51
 
 
52
install_dependencies() {
 
53
    exec_with_adb apt-get -y install openssh-server
 
54
    exec_with_ssh $SUDO apt-get -y install build-essential rsync bzr ccache gdb libglib2.0-bin
 
55
    exec_with_ssh $SUDO add-apt-repository -y ppa:canonical-qt5-edgers/qt5-proper
 
56
    exec_with_ssh $SUDO add-apt-repository -s -y ppa:phablet-team/ppa
 
57
    exec_with_ssh $SUDO apt-get update
 
58
    exec_with_ssh $SUDO apt-get -y build-dep $PACKAGE
 
59
}
 
60
 
 
61
reset_screen_powerdown() {
 
62
    exec_with_ssh $SUDO dbus-launch gsettings set com.canonical.powerd activity-timeout 600
 
63
    exec_with_ssh $SUDO sudo initctl restart powerd
 
64
}
 
65
 
 
66
setup_adb_forwarding() {
 
67
    adb forward tcp:$TARGET_SSH_PORT tcp:22
 
68
    adb forward tcp:$TARGET_DEBUG_PORT tcp:$TARGET_DEBUG_PORT
 
69
}
 
70
 
 
71
sync_code() {
 
72
    bzr export --uncommitted --format=dir /tmp/$CODE_DIR
 
73
    rsync -crlOzv -e "ssh -p $TARGET_SSH_PORT -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" /tmp/$CODE_DIR/ $USER@$TARGET_IP:$CODE_DIR/
 
74
    rm -rf /tmp/$CODE_DIR
 
75
}
 
76
 
 
77
build() {
 
78
    exec_with_ssh PATH=/usr/lib/ccache:$PATH "cd $CODE_DIR/ && PATH=/usr/lib/ccache:$PATH cmake -DCMAKE_BUILD_TYPE=debug . && PATH=/usr/lib/ccache:$PATH make -j 2"
 
79
}
 
80
 
 
81
run() {
 
82
    adb shell pkill $BINARY
 
83
    exec_with_ssh "cd $CODE_DIR/src && ./$BINARY $RUN_OPTIONS"
 
84
}
 
85
 
 
86
set -- `getopt -n$0 -u -a --longoptions="setup,help" "sh" "$@"`
 
87
 
 
88
# FIXME: giving incorrect arguments does not call usage and exit
 
89
while [ $# -gt 0 ]
 
90
do
 
91
    case "$1" in
 
92
       -s|--setup)   SETUP=true;;
 
93
       -h|--help)    usage;;
 
94
       --)           shift;break;;
 
95
    esac
 
96
    shift
 
97
done
 
98
 
 
99
adb_root
 
100
setup_adb_forwarding
 
101
 
 
102
if $SETUP; then
 
103
    echo "Setting up environment for building shell.."
 
104
    install_ssh_key
 
105
    install_dependencies
 
106
    reset_screen_powerdown
 
107
    sync_code
 
108
else
 
109
    echo "Transferring code.."
 
110
    sync_code
 
111
    echo "Building.."
 
112
    build
 
113
    echo "Running.."
 
114
    run
 
115
fi