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