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