@@ -4,8 +4,8 @@ USER=phablet
4USER_ID=32011
4USER_ID=32011
5PACKAGE=unity8
5PACKAGE=unity8
6BINARY=unity8
6BINARY=unity8
7−TARGET_IP=${TARGET_IP-127.0.0.1}
7+TARGET_IP=127.0.0.1
8−TARGET_SSH_PORT=${TARGET_SSH_PORT-2222}
8+TARGET_SSH_PORT=2222
9TARGET_DEBUG_PORT=3768
9TARGET_DEBUG_PORT=3768
10RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
10RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
11SETUP=false
11SETUP=false
@@ -14,17 +14,22 @@ PINLOCK=false
14KEYLOCK=false
14KEYLOCK=false
15NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
15NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
16FLIPPED=false
16FLIPPED=false
17−CHROOT_PREFIX="/data/ubuntu"
18SSH_WAS_STARTED=0
17SSH_WAS_STARTED=0
19SSH_STARTED=0
18SSH_STARTED=0
22− echo "usage: run_on_device [OPTIONS]\n"
23+ echo "usage: run_on_device -a SUDO_PASSWORD [OPTIONS]"
23− echo "Script to setup a build environment for the shell and sync build and run it on the device\n"
25+ echo "Script to setup a build environment for the shell and sync build and run it on the device"
24 echo "OPTIONS:"
27 echo "OPTIONS:"
28+ echo " -a The sudo password to use"
25− echo " -s, --setup Setup the build environment"
29+ echo " -s Setup the build environment"
30+ echo " -g Run with gdb"
26− echo " -p, --pinlock Enable a PIN lock screen when running"
31+ echo " -p Enable a PIN lock screen when running"
27− echo " -k, --keylock Enable a Keyboard lock screen when running"
32+ echo " -k Enable a Keyboard lock screen when running"
29 echo "IMPORTANT:"
34 echo "IMPORTANT:"
30 echo " * Make sure to have networking setup on the device beforehand."
35 echo " * Make sure to have networking setup on the device beforehand."
@@ -34,7 +39,7 @@ usage() {
35start_ssh() {
40start_ssh() {
36 if [ $SSH_STARTED -eq 0 ]; then
41 if [ $SSH_STARTED -eq 0 ]; then
37− exec_with_adb initctl start ssh
42+ adb_sudo initctl start ssh
38 SSH_STARTED=1
43 SSH_STARTED=1
@@ -44,25 +49,13 @@ exec_with_ssh() {
44 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
49 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
47−exec_with_adb() {
52+adb_sudo() {
48− if $FLIPPED; then
53+ adb shell "SUDO_ASKPASS=${PASSFILE} sudo --askpass $@"
51− adb shell chroot /data/ubuntu /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
60install_ssh_key() {
56install_ssh_key() {
61− ssh-keygen -R $TARGET_IP
62− HOME_DIR="${CHROOT_PREFIX}/home/phablet"
57+ HOME_DIR="/home/phablet"
63 adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
58 adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
64− adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh
65− adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh/authorized_keys
66 adb shell chmod 700 $HOME_DIR/.ssh
59 adb shell chmod 700 $HOME_DIR/.ssh
67 adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
60 adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
@@ -73,8 +66,8 @@ setup_adb_forwarding() {
75install_dependencies() {
68install_dependencies() {
76− exec_with_adb apt-get update
69+ adb_sudo apt-get update
77− exec_with_adb apt-get -y --force-yes install build-essential rsync bzr ccache gdb ninja-build devscripts equivs unity-plugin-scopes
70+ adb_sudo apt-get -y --force-yes install build-essential rsync bzr ccache gdb ninja-build devscripts equivs unity-plugin-scopes
80sync_code() {
73sync_code() {
@@ -108,37 +101,35 @@ run() {
108 exec_with_ssh "start unity8"
101 exec_with_ssh "start unity8"
111−set -- `getopt -n$0 -u -a --longoptions="setup,gdb,pinlock,keylock,help" "sgpkh" "$@"`
104+while getopts "a:sgpkh" OPTION; do
113−# FIXME: giving incorrect arguments does not call usage and exit
116− case "$1" in
105+ case "$OPTION" in
106+ a|password) PASSWORD=$OPTARG;;
117− -s|--setup) SETUP=true;;
107+ s|setup) SETUP=true;;
118− -g|--gdb) GDB=true;;
108+ g|gdb) GDB=true;;
119− -p|--pinlock) PINLOCK=true;;
109+ p|pinlock) PINLOCK=true;;
120− -k|--keylock) KEYLOCK=true;;
110+ k|keylock) KEYLOCK=true;;
121− -h|--help) usage;;
111+ h|help) usage;;
122− --) shift;break;;
112+ ?) echo;usage;;
116+shift $((OPTIND - 1))
128−adb_root
118+if [ -z "${PASSWORD}" ]; then
129−[ "${TARGET_IP}" = "127.0.0.1" ] && setup_adb_forwarding
119+ echo "ERROR: You need to provide a sudo password..."
131−if [ "`adb shell 'grep -q Ubuntu /etc/lsb-release 2> /dev/null && echo -n FLIPPED'`" = "FLIPPED" ]; then
121+ usage
134− if [ "${TARGET_IP}" != "127.0.0.1" ]; then
135− echo "ERROR: Flipped image detected, adb over TCP/IP isn't supported, yet :/"
136− echo "Unset TARGET_IP and try again."
124+PASSFILE=$( adb shell "FILE=\`mktemp\`
125+ echo \"#!/bin/sh\" > \$FILE
126+ echo \"echo \\\"${PASSWORD}\\\"\" >> \$FILE
128+ echo \$FILE" | tr -d '\r' )
141−status_output=$(exec_with_adb initctl status ssh)
132+status_output=$(adb_sudo initctl status ssh)
142if [[ $status_output == "ssh start/running, process "* ]]; then
133if [[ $status_output == "ssh start/running, process "* ]]; then
143 SSH_WAS_STARTED=1
134 SSH_WAS_STARTED=1
@@ -158,6 +149,8 @@ else
152+adb shell "rm ${PASSFILE}"
161if [ $SSH_WAS_STARTED -eq 0 ]; then
154if [ $SSH_WAS_STARTED -eq 0 ]; then
162− exec_with_adb initctl stop ssh
155+ adb_sudo initctl stop ssh