(use-modules (ice-9 filesystem) (srfi srfi-71) (ordo playbook) (ordo play) (ordo interceptor) (ordo connection) (ordo interceptor create-tmp-dir) (ordo interceptor require-commands) (ordo interceptor user-info) (ordo util flatten)) ;; TODO: this should be in (ordo interceptor download) and it needs arg validation (define* (download name #:key url target-dir register) (interceptor name #:enter (lambda (ctx) (let* ((url target-dir (expand-vars ctx url target-dir)) (file-name (file-name-join* target-dir (file-basename url)))) (run (context-connection ctx) "wget" "-O" file-name url #:check? #t) (when register (var-set! ctx register file-name)))) #:leave (lambda (ctx) (when register (var-delete! ctx register))) #:error (lambda (ctx) (when register (var-delete! ctx register))))) ;; TODO: this should be in (ordo interceptor unzip) and it needs arg validation (define* (unzip name #:key file-name target-dir) (interceptor name #:enter (lambda (ctx) (let ((file-name target-dir (expand-vars ctx file-name target-dir))) (run (context-connection ctx) "unzip" file-name "-d" target-dir #:check? #t))))) ;; TODO: this should be in (ordo interceptor command) ;; Maybe it could expose more of the run functionality? (define (command name prog . args) (interceptor name #:enter (lambda (ctx) (run (context-connection ctx) (expand-vars ctx prog) (map (lambda (a) (expand-vars ctx a)) (flatten args)) #:check? #t)))) (define* (install-aws-cli #:key (url "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip") update? install-dir bin-dir) (list (require-commands "wget" "unzip") (create-tmp-dir #:register 'aws-cli-tmp) (download "download-aws-cli" #:url url #:target-dir (let-vars (aws-cli-tmp) aws-cli-tmp) #:register 'aws-cli-zipfile) (unzip "extract-aws-cli" #:file-name (let-vars (aws-cli-zipfile) aws-cli-zipfile) #:target-dir (let-vars (aws-cli-tmp) aws-cli-tmp)) (command "run-aws-cli-installer" (let-vars (aws-cli-tmp) (file-name-join* aws-cli-tmp "aws" "install")) (when install-dir `("-i" ,install-dir)) (when bin-dir `("-b" ,bin-dir)) (when update? "-u")))) (playbook #:name "Test Playbook" #:plays (list (play #:name "Install AWS CLI" #:host "localhost" #:interceptors (list (user-info) (install-aws-cli #:update? #t #:install-dir (let-vars (user-info) (file-name-join* (assoc-ref user-info #:home-dir) ".local" "aws-cli")) #:bin-dir (let-vars (user-info) (file-name-join* (assoc-ref user-info #:home-dir) ".local" "bin")))))))