Sunday, September 13, 2015

Setting up SSH on Cynogenmod 12.1 for Emacs Tramp

I found the information at https://wiki.cyanogenmod.org/w/Doc:_sshd did not contain enough details for me to be able to be able to do what I wanted, which was to use Tramp from within Emacs.

Setting up the phone for ADB and root access


Unplug phone from USB
Enable "Developer options" settings (tap 7 times on "Settings->About phone->Build number")
Enable Android debugging over USB (Settings->Developer Options->Android debugging)
Enable root for ADB (Settings->Developer Options->Root access, "Apps and ADB" or "ADB only")
Plug in phone via USB
Choose to "Allow android debugging", and hit "Ok".

(Setting up adb is beyond the scope of these instructions.)

Run, "adb devices" to confirm the device can be seen.

adb root
adb push ~/.ssh/id_rsa.pub /data/.ssh/authorized_keys
adb shell


(the following commands are all run in the root shell via ADB)
chmod 640 /data/.ssh/authorized_keys
chown root:shell /data/.ssh/authorized_keys

mkdir -p /data/ssh/empty
chmod -R 700 /data/ssh

cat /system/etc/ssh/sshd_config | \
        sed 's/#PermitRootLogin yes$/PermitRootLogin no/' | \
        sed 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' | \
        sed 's/#PasswordAuthentication yes/PasswordAuthentication no/' | \
        sed 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' | \
        sed 's/#ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/' | \
        sed 's;/usr/libexec/sftp-server;internal-sftp;' > \
        /data/ssh/sshd_config
chmod 600 /data/ssh/sshd_config

cat /system/bin/start-ssh | \
 sed 's;/system/etc/ssh/sshd_config;/data/ssh/sshd_config;' > \
 /data/local/start-ssh
chmod 755 /data/local/start-ssh

exit

Starting SSH

adb root
adb shell /data/local/start-ssh &

At this point the phone can be unplugged and SSH should still be running.

Setting up Tramp

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "192.168.1.9") "remote-shell" "/system/xbin/bash"))
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-to-list 'tramp-remote-path "/system/xbin")
(add-to-list 'tramp-remote-process-environment "TMPDIR=/data/local/tmp")
(add-to-list 'tramp-remote-process-environment "ANDROID_ROOT=/system") 
 

Setting up $HOME/.ssh/config

Make "shell" the default user for this host.

Host 192.168.1.9
User shell

Thursday, September 4, 2014

Fixing Wanderlust Next/Previous Navigation

Navigating with Wanderlust can be a painful experience if you have the expectation that keystrokes sent to a particular window will not move you to another window unless you explicitly execute a command whose sole purpose is to cause the Window focus to move.

Wanderlust comes with a default configuration such that pressing space or n or p (or N or P) in the Summary Window or the Message Window can service two purposes: it can move you to the next "element" or close the current window and navigate to the next "element" in the "parent" window.

For example, if done at the beginning or end of the summary window, typing "n" in the summary window can close the current summary and move you to the summary of the next folder (depending on whether you have wl-auto-select-next set, but even if that is set to nil, it still closes the current summary -- nil only prevents opening the next folder, not closing the current one).  This can be quite irritating.  At least in my experience, you never know when you are at the top or bottom -- whether the next n or p (or space or backspace) will scroll up or close the buffer you are navigating.  Likewise, hitting space at the end of a Message window could take you to the next MIME element (if there is one -- and you do not know if there is one if you cannot see all the elements), or it could take you to the next message in the Summary window (you just thought you were done reading that email, right? It's really fun having to navigate back to where you were after this happens in a lengthy email.)

While I can see the need for the default settings for someone who has five to ten emails whose entire content always fits in the Message Window, I personally think this feature should have been optional.

I worked around this issue with the following hooks:

(defun my-wl-end-of-list ()
  (message "End of list.")
  t)

(add-hook
 'wl-message-buffer-created-hook
 '(lambda ()
    (setq mime-preview-over-to-next-method-alist nil)
    (setq mime-preview-over-to-previous-method-alist nil)
    ))

(add-hook
 'wl-summary-mode-hook
 '(lambda ()
    (set 'wl-summary-buffer-next-folder-function 'my-wl-end-of-list)
    (set 'wl-summary-buffer-prev-folder-function 'my-wl-end-of-list)
    ))

I do not know if there is a better way to approach this, but, it works for me.