diff --git a/bolt/bolt.rkt b/bolt/bolt.rkt index 89a362d..1eb69b1 100755 --- a/bolt/bolt.rkt +++ b/bolt/bolt.rkt @@ -1,5 +1,6 @@ #lang racket +(require "execute.rkt") (require remote-shell/ssh) (require "directory.rkt") (require "shell_env.rkt") @@ -65,15 +66,13 @@ (displayln (format "Executed on ~a:" (remote-host (host)))) (match - (ssh (host) + ((make-exec (hostname)) (as-user (format "cd ~a && ~a ~a" (cwd) (format-vars (shell-env)) cmd) - ) - #:failure-log "/tmp/test.log" - #:mode 'output) + )) [(cons code output) (cons code (strip-first-line diff --git a/bolt/execute.rkt b/bolt/execute.rkt new file mode 100644 index 0000000..ebf9acd --- /dev/null +++ b/bolt/execute.rkt @@ -0,0 +1,54 @@ +#! /usr/bin/env racket +#lang racket + +(define (read-avail from-port callback) + (define ready + (sync + (read-bytes-evt 1 from-port))) + + (if (not (eof-object? ready)) + (begin + (callback ready) + (read-avail from-port callback)) + (callback #f))) + + +(define (execute-async to-port) + (define command (thread-receive)) + + (displayln command to-port) + + (flush-output to-port) + (execute-async to-port)) + +;; you tell it the remote, and pass it a callback +;; the callback gets hooked into another thread that waits for output +;; the callback executes on any output +;; the output might be parsed into a standard format + +(define (make-executor host callback) + + (match-define (list from-remote + to-remote + pid + error-from-remote + control-remote) + (process (format "ssh -tt ~a" host))) + + (thread + (lambda () (read-avail from-remote callback))) + + (define + executor + (thread (lambda () (execute-async to-remote)))) + + (lambda (command) + (thread-send executor command))) + +(define (make-exec hostname) + (make-executor + hostname + (lambda (result) + (display result)))) + +(provide make-exec)