Merge lp:~ogra/phablet-tools/phablet-tools-fix-phablet-shell into lp:phablet-tools

Proposed by Oliver Grawert
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 311
Merged at revision: 312
Proposed branch: lp:~ogra/phablet-tools/phablet-tools-fix-phablet-shell
Merge into: lp:phablet-tools
Diff against target: 47 lines (+17/-6)
1 file modified
phablet-shell (+17/-6)
To merge this branch: bzr merge lp:~ogra/phablet-tools/phablet-tools-fix-phablet-shell
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Robert Bruce Park (community) Approve
Benjamin Zeller (community) Approve
Review via email: mp+234976@code.launchpad.net

Commit message

'phablet-shell: only start/stop ssh if it is not already running, do not wipe authorized_keys (breaks the SDK) and instead only append the key if it is not there yet. make sure ~/.ssh exists before trying to do anything with it (LP: #1355286) (LP: #1337289) (LP: #1326805)

Description of the change

phablet-shell: only start/stop ssh if it is not already running, do not wipe authorized_keys (breaks the SDK) and instead only append the key if it is not there yet. make sure ~/.ssh exists before trying to do anything with it

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Benjamin Zeller (zeller-benjamin) wrote :

Works for me:
I can now use phablet-shell and the SDK together

review: Approve
Revision history for this message
Robert Bruce Park (robru) wrote :

Mostly lgtm, check one inline comment below.

review: Needs Fixing
311. By Oliver Grawert

drop the chwoning of the ~/.ssh dir, it should have the right owner already

Revision history for this message
Robert Bruce Park (robru) wrote :

lgtm

review: Approve
Revision history for this message
Oliver Grawert (ogra) wrote :

i dropped teh chown since teh user is in any case correct, but i would like ot keep the chmod since if the .ssh dir or authorized_keys never existed they are created with wide open permissions

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'phablet-shell'
2--- phablet-shell 2014-08-15 12:47:01 +0000
3+++ phablet-shell 2014-09-17 16:29:43 +0000
4@@ -82,10 +82,13 @@
5 adb shell "$CMD >/dev/null"
6 }
7
8+# if sshd is already runing, do not attempt to start it
9+SSH_RUNNING="$(adb shell pgrep sshd)"
10+
11 # Start ssh on the device and use port forwarding to connect to it.
12 # This means that we'll connect to the device through the USB cable
13 # and won't depend on if the device has it's wifi configured or not.
14-toggle_ssh true
15+[ -n "$SSH_RUNNING" ] || toggle_ssh true
16
17 for PORT in `seq 2222 2299`; do
18 adb forward tcp:$PORT tcp:22 && break
19@@ -99,10 +102,18 @@
20
21 # Copy your ssh id down to the device so you never need a password.
22 NEWEST_KEY=$(ls -t ~/.ssh/*.pub | grep -v -- -cert.pub | head -1)
23-adb push $NEWEST_KEY /home/phablet/.ssh/authorized_keys
24-adb shell chown phablet:phablet -R /home/phablet/.ssh/
25-adb shell chmod 700 /home/phablet/.ssh
26-adb shell chmod 600 /home/phablet/.ssh/authorized_keys
27+KEY_CONTENT="$(cat $NEWEST_KEY)"
28+
29+# make sure we have a ~/.ssh/ dir before trying to write to it
30+adb shell "[ -d ~/.ssh ] || mkdir ~/.ssh"
31+
32+# append the key to authorized_keys if it is not there already
33+adb shell "touch ~/.ssh/authorized_keys"
34+if [ -z "$(adb shell "grep \"$KEY_CONTENT\" ~/.ssh/authorized_keys")" ]; then
35+ adb shell "echo $KEY_CONTENT >>~/.ssh/authorized_keys"
36+ adb shell "chmod 700 ~/.ssh"
37+ adb shell "chmod 600 ~/.ssh/authorized_keys"
38+fi
39
40 # Copy your bash config down to the device so you get the benefit of your
41 # colourful $PS1 prompt and any bash aliases that you may be used to from your
42@@ -115,4 +126,4 @@
43 ssh $SSH_OPTS phablet@localhost
44
45 # turn off ssh access again
46-toggle_ssh false
47+[ -n "$SSH_RUNNING" ] || toggle_ssh false

Subscribers

People subscribed via source and target branches