on xenial help sign in
Make sure we have ssh started when we need it

. Approved by PS Jenkins bot, Michał Sawicz.

commitf47d6878b4a30d056c2c9b7e6d8c16f8947320ac authorAlbert Astals <albert.astals@canonical.com> dateFri 1 Nov 2013, 00:04 (13 years ago) parent4c6a461b840119
1 file changed+24−4
run_on_device+24−4
run_on_device+24−4
@@ -1,4 +1,4 @@
1−#!/bin/sh
1+#!/bin/bash
22CODE_DIR=shell
33USER=phablet
44USER_ID=32011
@@ -17,6 +17,8 @@ SUDO="echo $PASSWORD | sudo -S"
1717NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
1818FLIPPED=false
1919CHROOT_PREFIX="/data/ubuntu"
20+SSH_WAS_STARTED=0
21+SSH_STARTED=0
2022
2123usage() {
2224 echo "usage: run_on_device [OPTIONS]\n"
@@ -32,7 +34,15 @@ usage() {
3234 exit 1
3335}
3436
37+start_ssh() {
38+ if [ $SSH_STARTED -eq 0 ]; then
39+ exec_with_adb initctl start ssh
40+ SSH_STARTED=1
41+ fi
42+}
43+
3544exec_with_ssh() {
45+ start_ssh
3646 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
3747}
3848
@@ -52,7 +62,7 @@ adb_root() {
5262install_ssh_key() {
5363 ssh-keygen -R $TARGET_IP
5464 HOME_DIR="${CHROOT_PREFIX}/home/phablet"
55− adb push ~/.ssh/phone_rsa.pub $HOME_DIR/.ssh/authorized_keys
65+ adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
5666 adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh
5767 adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh/authorized_keys
5868 adb shell chmod 700 $HOME_DIR/.ssh
@@ -65,8 +75,6 @@ setup_adb_forwarding() {
6575}
6676
6777install_dependencies() {
68− exec_with_adb rm /etc/init/ssh.override
69− exec_with_adb service ssh start
7078 exec_with_adb apt-get update
7179 exec_with_ssh $SUDO apt-get -y install build-essential rsync bzr ccache gdb ninja-build devscripts equivs
7280}
@@ -74,6 +82,7 @@ install_dependencies() {
7482sync_code() {
7583 [ -e .bzr ] && bzr export --uncommitted --format=dir /tmp/$CODE_DIR
7684 [ -e .git ] && git checkout-index -a -f --prefix=/tmp/$CODE_DIR/
85+ start_ssh
7786 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/
7887 rm -rf /tmp/$CODE_DIR
7988}
@@ -96,7 +105,9 @@ run() {
96105 fi
97106
98107 exec_with_ssh "stop unity8"
108+ exec_with_ssh "start maliit-server"
99109 exec_with_ssh "cd $CODE_DIR/ && ./run $ARGS -- $RUN_OPTIONS"
110+ exec_with_ssh "stop maliit-server"
100111 exec_with_ssh "start unity8"
101112}
102113
@@ -130,6 +141,12 @@ if [ "`adb shell 'grep -q Ubuntu /etc/lsb-release 2> /dev/null && echo -n FLIPPE
130141 fi
131142fi
132143
144+status_output=$(exec_with_adb initctl status ssh)
145+if [[ $status_output == "ssh start/running, process "* ]]; then
146+ SSH_WAS_STARTED=1
147+fi
148+SSH_STARTED=$SSH_WAS_STARTED
149+
133150if $SETUP; then
134151 echo "Setting up environment for building shell.."
135152 install_ssh_key
@@ -144,3 +161,6 @@ else
144161 run
145162fi
146163
164+if [ $SSH_WAS_STARTED -eq 0 ]; then
165+ exec_with_adb initctl stop ssh
166+fi