]> git.cworth.org Git - notmuch-wiki/blob - remoteusage/aboriginal.mdwn
Added remoteusage/aboriginal.mdwn -- remoteusage without password-free
[notmuch-wiki] / remoteusage / aboriginal.mdwn
1 ## Remoteusage without password-free login requirement
2
3 This is alternative to [[remoteusage|remoteusage]] where password-free
4 login is not a requirement. See [[remoteusage|remoteusage]] page for
5 other requirements and general information.
6
7 This solution uses one pre-made ssh connection where the client is put
8 into "master" mode (-M) for connection sharing. The wrapper script then
9 uses the control socket created by this pre-made ssh connection for
10 its own connection.
11
12 Write the following code to a file, for example `remote-notmuch.sh`.
13 There is just one line to that normally needs configuration:
14
15         readonly SSH_CONTROL_SOCK='~'/.ssh/master-user@host:22
16
17 the options howto are presented after the script.
18
19 ## The script
20
21         #!/bin/bash
22
23         # http://notmuchmail.org/remoteusage/aboriginal/
24
25         set -eu
26
27         readonly SSH_CONTROL_SOCK='~'/.ssh/master-user@host:22
28
29         readonly notmuch=notmuch
30
31         printf -v ARGS '%q ' "$@" # bash feature
32
33         readonly SSH_CONTROL_ARGS='-oControlMaster=no -S '$SSH_CONTROL_SOCK
34
35         if ssh $SSH_CONTROL_ARGS 0.1 $notmuch $ARGS 2>>/dev/null
36         then exit 0
37         else ev=$?
38         fi
39
40         # continuing here in case ssh exited with nonzero value.
41
42         case $* in
43          'config get user.primary_email') echo 'nobody@nowhere.invalid'; exit 0 ;;
44          'config get user.name') echo 'nobody'; exit 0 ;;
45          'count'*) echo 1; exit 0 ;;
46          'search-tags'*) echo 'errors'; exit 0 ;;
47          'search'*'--output=tags'*) echo 'errors'; exit 0 ;;
48         esac
49
50         if ssh $SSH_CONTROL_ARGS -O check 0.1
51         then
52          echo ' Control socket is alive but something failed during data transmission.'
53          exit $ev
54         fi
55
56         echo " See`sed '1d;2d;s/.//;q' "$0"` for help."
57
58 ## Test
59
60 Easiest way to test this script is to run the pre-made ssh connection
61 using the following command line:
62
63         ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost
64
65 (replace `[user@]remotehost` with your login info). Doing this the
66 above script can be run unmodified. After the above command has been
67 run on one terminal, enter `chmod +x remote-notmuch.sh` in another
68 terminal and then test the script with `./remote-notmuch.sh help`
69
70 Note that the '~' is inside single quotes for a reason. In this
71 case shell never expand it to `$HOME` -- ssh does it by not reading
72 `$HOME` but checking the real user home directory from `/etc/passewd`.
73 For security purposes this is just how it should be.
74
75 ## Tunkkaa
76
77 The path `'~'/.ssh/master-user@host:22` might look too generic to be
78 used as is as the control socket after initial testing (but it can
79 be used). It is presented as a template for what could be configured
80 to `$HOME/.ssh/config`. For example:
81
82         Host *
83             ControlPath ~/.ssh/master-%h@%p:%r
84
85 is a good entry to be written in `$HOME/.ssh/config`;
86 [[remoteusage|remoteusage]] uses the same. Now, let's say you'd
87 make your pre-made ssh connection with command
88
89         ssh -M alice@example.org
90
91 After configuring
92 `readonly SSH_CONTROL_SOCK='~'/.ssh/master-alice@example.org:22`
93 to the `./remote-notmuch.sh` wrapper script testing with
94 `./remote-notmuch.sh help` should work fine.
95
96 ## Configure Emacs on the client computer ##
97
98 See the section *Configure Emacs on the client computer* in
99 [[remoteusage|remoteusage]] how to do this. The instructions are the same.
100
101 ## Fun
102
103 Original [BSD Licence](http://en.wikipedia.org/wiki/BSD_licenses)
104 is 4-clause license.
105 When 3 rd. clause was removed, the new license was not original anymore.
106 Similarly, the requirement for this version are the same as in
107 [[remoteusage|remoteusage]] page except the 3 rd. requirement
108 (password-free login) is not effective here.