Make a start on connection
This commit is contained in:
parent
6f217e006e
commit
cac302e739
5 changed files with 110 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
scratch/
|
||||
/.dir-locals.el
|
||||
/gnu
|
||||
*-tarball-pack.tar.gz
|
||||
/mybin
|
||||
|
|
27
README.md
Normal file
27
README.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Ordo
|
||||
|
||||
Ordo ab chao: from chaos, comes order.
|
||||
|
||||
## Installing Dependencies
|
||||
|
||||
On a Guix system, you can simply run:
|
||||
|
||||
``` bash
|
||||
guix package -m manifest.scm
|
||||
```
|
||||
|
||||
If Guix is not available where you plan to run ordo, but you have access to a
|
||||
system running Guix, you can create a tarball containing all the dependencies:
|
||||
|
||||
``` bash
|
||||
guix pack -RR -m manifest.scm
|
||||
```
|
||||
|
||||
Copy the tarball to your system and unpack it (somewhere).
|
||||
|
||||
Find the name of the profile in the tarball and use that to configure paths etc.
|
||||
|
||||
``` bash
|
||||
export GUIX_PROFILE=$(realpath gnu/store/*-profile)
|
||||
source "${GUIX_PROFILE}/etc/profile"
|
||||
```
|
26
manifest.scm
Normal file
26
manifest.scm
Normal file
|
@ -0,0 +1,26 @@
|
|||
(specifications->manifest '("git"
|
||||
"git-crypt"
|
||||
"git-lfs"
|
||||
"gnupg"
|
||||
"guile"
|
||||
"guile-config"
|
||||
"guile-dsv"
|
||||
"guile-file-names"
|
||||
"guile-filesystem"
|
||||
"guile-gcrypt"
|
||||
"guile-gnutls"
|
||||
"guile-ini"
|
||||
"guile-irregex"
|
||||
"guile-json"
|
||||
"guile-lib"
|
||||
"guile-libyaml"
|
||||
"guile-quickcheck"
|
||||
"guile-readline"
|
||||
"guile-semver"
|
||||
"guile-sqlite3"
|
||||
"guile-srfi-145"
|
||||
"guile-srfi-158"
|
||||
"guile-srfi-197"
|
||||
"guile-srfi-235"
|
||||
"guile-ssh"
|
||||
"password-store"))
|
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