X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=remoteusage%2Faboriginal.mdwn;h=ccaded1c6101895c9416d5372f4790fb602b2170;hb=72251dc226ae254962ca0b0ac8c0039e8570c864;hp=569b338fddafdbe5b71a8f4c960cee313f330bd5;hpb=b370ccb1d5ef97c482fe42840ff8aee75e249e0a;p=notmuch-wiki diff --git a/remoteusage/aboriginal.mdwn b/remoteusage/aboriginal.mdwn index 569b338..ccaded1 100644 --- a/remoteusage/aboriginal.mdwn +++ b/remoteusage/aboriginal.mdwn @@ -11,46 +11,52 @@ its own connection. As long as master ssh connection is live, slave can use it. Disconnecting master all future attempts to connect from the script will fail. +At the end of this document there is information for some possible ways +how master ssh connection can be done. + ## The script Write the following code to a file, for example `remote-notmuch.sh`. - #!/bin/bash + #!/bin/bash - # http://notmuchmail.org/remoteusage/aboriginal/ + # http://notmuchmail.org/remoteusage/aboriginal/ - set -eu + set -eu + # To trace execution, outcomment next line. Note that emacs input may ... + #exec 2>>remote-errors; echo -- >&2; set -x # ... change (no stderr). - readonly SSH_CONTROL_SOCK='~'/.ssh/master-user@host:22 + readonly SSH_CONTROL_SOCK='~'/.ssh/master-user@host:22 - readonly notmuch=notmuch + readonly notmuch=notmuch - printf -v ARGS '%q ' "$@" # bash feature + printf -v ARGS '%q ' "$@" # bash feature - readonly SSH_CONTROL_ARGS='-oControlMaster=no -S '$SSH_CONTROL_SOCK + readonly SSH_CONTROL_ARGS='-oControlMaster=no -S '$SSH_CONTROL_SOCK - if ssh $SSH_CONTROL_ARGS 0.1 $notmuch $ARGS 2>>/dev/null - then exit 0 - else ev=$? - fi + if ssh -q $SSH_CONTROL_ARGS 0.1 $notmuch $ARGS + then exit 0 + else ev=$? + fi - # continuing here in case ssh exited with nonzero value. + # continuing here in case ssh exited with nonzero value. - case $* in - 'config get user.primary_email') echo 'nobody@nowhere.invalid'; exit 0 ;; - 'config get user.name') echo 'nobody'; exit 0 ;; - 'count'*) echo 1; exit 0 ;; - 'search-tags'*) echo 'errors'; exit 0 ;; - 'search'*'--output=tags'*) echo 'errors'; exit 0 ;; - esac + case $* in + 'config get user.primary_email') echo 'nobody@nowhere.invalid'; exit 0 ;; + 'config get user.name') echo 'nobody'; exit 0 ;; + 'count'*'--batch'*) while read line; do echo 1; done; exit 0 ;; + 'count'*) echo 1; exit 0 ;; + 'search-tags'*) echo 'errors'; exit 0 ;; + 'search'*'--output=tags'*) echo 'errors'; exit 0 ;; + esac - if ssh $SSH_CONTROL_ARGS -O check 0.1 - then - echo ' Control socket is alive but something failed during data transmission.' - exit $ev - fi + if ssh $SSH_CONTROL_ARGS -O check 0.1 + then + echo ' Control socket is alive but something failed during data transmission.' + exit $ev + fi - echo " See`sed '1d;2d;s/.//;q' "$0"` for help." + echo " See`sed '1d;2d;s/.//;q' "$0"` for help." Note the `0.1` in ssh command line. It is used to avoid any opportunistic behaviour ssh might do; for example if control socket is not alive ssh @@ -62,12 +68,12 @@ address `0.1` is invalid this attempt will fail early. Easiest way to test this script is to run the pre-made ssh connection using the following command line: - ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost + ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 600 (replace `[user@]remotehost` with your login info). Doing this the -above script can be run unmodified. After the above command has been -run on one terminal, enter `chmod +x remote-notmuch.sh` in another -terminal and then test the script with `./remote-notmuch.sh help` +above wrapper script can be run unmodified. After the above command has +been run on **one terminal**, enter `chmod +x remote-notmuch.sh` in +**another terminal** and then test the script with `./remote-notmuch.sh help` Note that the '~' is inside single quotes for a reason. In this case shell never expand it to `$HOME` -- ssh does it by not reading @@ -99,3 +105,31 @@ to the `./remote-notmuch.sh` wrapper script testing with See the section *Configure Emacs on the client computer* in [[remoteusage|remoteusage]] how to do this. The instructions are the same. + + +## Creating master connection + +As mentioned so many times, using this solution requires one pre-made +ssh connection in "master" mode. The simplest way is to dedicate one +terminal for the connection with shell access to the remote machine: + + ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost + +One possibility is to have this dedicated terminal in a way that the +connection has (for example 1 hour) timeout: + + ssh -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600 + +The above holds the terminal. The next alternative puts the command in +background: + + ssh -f -M -S '~'/.ssh/master-user@host:22 [user@]remotehost sleep 3600 + +If you don't want this to timeout so soon, use a longer sleep, like 99999999 +(8 9:s, 1157 days, a bit more than 3 years). + +A more "exotic" solution would be to make a shell script running on remote +machine, checking/inotifying when new mail arrives. When mail arrives it +could send message back to local host, where a graphical client (to be written) +pops up on display providing info about received mail (and exiting this +graphical client connection to remote host is terminated).