diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-26 13:42:03 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-27 08:33:17 -0700 |
commit | b1688ced028a63e6817e97f490ecf081d45c14c9 (patch) | |
tree | 5280fb4cc0ed1dfc4e47a127c9e547c4b9793602 /src/connection/ssh.lisp | |
parent | 03e93e96fdc7b4dd17e24a101202a25fb6d20c1e (diff) | |
download | consfigurator-b1688ced028a63e6817e97f490ecf081d45c14c9.tar.gz |
factor out SHELL-WRAP-CONNECTION superclass
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/ssh.lisp')
-rw-r--r-- | src/connection/ssh.lisp | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/src/connection/ssh.lisp b/src/connection/ssh.lisp index d9b5f42..da32070 100644 --- a/src/connection/ssh.lisp +++ b/src/connection/ssh.lisp @@ -28,7 +28,7 @@ (mrun "ssh" "-fN" hop) (make-instance 'ssh-connection :hostname hop :user user)) -(defclass ssh-connection (posix-connection) +(defclass ssh-connection (shell-wrap-connection) ((hostname :initarg :hostname :documentation "Hostname to SSH to.") @@ -42,31 +42,11 @@ (format nil "~A@~A" user (slot-value connection 'hostname)) (slot-value connection 'hostname))) -(defun sshcmd (connection &rest args) +(defmethod connection-shell-wrap ((connection ssh-connection) cmd) ;; wrap in 'sh -c' in case the login shell is not POSIX (format nil "ssh ~A ~A" (ssh-host connection) - (escape-sh-token - (format nil "sh -c ~A" - (escape-sh-token - (if (cdr args) (escape-sh-command args) (car args))))))) - -(defmethod connection-run ((c ssh-connection) cmd &optional input) - (mrun :may-fail :input input (sshcmd c cmd))) - -(defmethod connection-readfile ((c ssh-connection) path) - (multiple-value-bind (out exit-code) - (mrun :may-fail - (sshcmd c (format nil "test -r ~A && cat ~:*~A" - (escape-sh-token path)))) - (if (= 0 exit-code) - out - (error "File ~S not readable" path)))) - -(defmethod connection-writefile ((c ssh-connection) path contents) - (with-remote-temporary-file (temp) - (mrun :input contents (sshcmd c "cat" #?">${temp}")) - (mrun "mv" temp path))) + (escape-sh-token (format nil "sh -c ~A" (escape-sh-token cmd))))) ;; rsync it straight to to its destination so rsync can do incremental updates (defmethod connection-upload ((c ssh-connection) from to) |