Make a start on connection
This commit is contained in:
parent
6f217e006e
commit
cac302e739
5 changed files with 110 additions and 0 deletions
41
modules/ordo/connection.scm
Normal file
41
modules/ordo/connection.scm
Normal file
|
@ -0,0 +1,41 @@
|
|||
(define-module (ordo connection)
|
||||
#:use-module (oop goops)
|
||||
#:use-module (ice-9 popen)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:use-module (ssh session)
|
||||
#:use-module (ssh auth)
|
||||
#:use-module (ssh popen)
|
||||
#:use-module (srfi srfi-197))
|
||||
|
||||
(define-class <connection> ()
|
||||
(sudo? #:init-value #f #:getter sudo? #:init-keyword #:sudo?))
|
||||
|
||||
(define-class <local-connection> (<connection>))
|
||||
|
||||
(define-class <ssh-connection> (<connection>)
|
||||
(user #:getter get-user #:init-keyword #:user)
|
||||
(host #:getter get-host #:init-keyword #:host)
|
||||
(session #:getter get-session #:setter set-session!))
|
||||
|
||||
(define-method (init! (c <local-connection>))
|
||||
c)
|
||||
|
||||
(define-method (init! (c <ssh-connection>))
|
||||
(unless (slot-bound? c 'session)
|
||||
(let ((session (make-session #:user (get-user c) #:host (get-host c))))
|
||||
(connect! session)
|
||||
(userauth-public-key/auto! s)
|
||||
(set-session! c session)))
|
||||
c)
|
||||
|
||||
(define (build-command pwd env prog args sudo?)
|
||||
(let ((cmd (list (if sudo? "sudo" "env"))))
|
||||
(chain-when cmd
|
||||
(pwd (append _ (list "--chdir" pwd)))
|
||||
(env (append _ (map (lambda (x) (format #f "~a=~a" (car x) (cdr x))) env)))
|
||||
(#t (append _ (list prog)))
|
||||
(args (append _ args)))))
|
||||
|
||||
(define-method (run (c <local-connection>) pwd env prog args))
|
||||
|
||||
(define-method (run (c <ssh-connection>) pwd env prog args))
|
|
@ -47,3 +47,16 @@
|
|||
(let ((output (get-string-all (car output-pipe))))
|
||||
(close-port (car output-pipe))
|
||||
(values (cdr (waitpid pid)) output)))))
|
||||
|
||||
;; Possibly nicer way to do this, suggested by dsmith on IRC: https://bpa.st/3JYTA
|
||||
;; (use-modules (ice-9 popen)
|
||||
;; (ice-9 rdelim)
|
||||
;; (ice-9 receive))
|
||||
|
||||
;; (define (filter text)
|
||||
;; (receive (from to pids) (pipeline '(("the-command")))
|
||||
;; (write text to)
|
||||
;; (close to)
|
||||
;; (read-line from)))
|
||||
|
||||
;; See also https://github.com/ray1729/ordo/blob/main/modules/ordo/util/process.scm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue