diff --git a/.local/share/common-lisp/source/ambrevar/storage.lisp b/.local/share/common-lisp/source/ambrevar/storage.lisp index d3f27f87..7eb4f66d 100644 --- a/.local/share/common-lisp/source/ambrevar/storage.lisp +++ b/.local/share/common-lisp/source/ambrevar/storage.lisp @@ -220,10 +220,15 @@ If DESTINATION ends with '.gpg', it gets GPG-encrypted." (export-always 'sync-gpg-key) (defun sync-gpg-key (device &key (mount-point "/mnt")) "Device (e.g. /dev/sda1) where to sync ~/.gnupg." - (let ((mapper-name "gpg_backup")) - (cmd:cmd "sudo cryptsetup open" device mapper-name) + (format t "Enter passphrase for ~a:~&" device) + (let ((mapper-name "gpg_backup") + (passphrase (uiop:run-program `(,(uiop:getenv "SUDO_ASKPASS")) :output '(:string :stripped t)))) + (with-input-from-string (input passphrase) + (uiop:run-program + `("sudo" "cryptsetup" "open" ,device ,mapper-name) + :input input)) (cmd:cmd "sudo mount -o compress=zstd" - (str:concat "/dev/mapper" mapper-name) + (str:concat "/dev/mapper/" mapper-name) mount-point) (cmd:cmd "gpg --import" (str:concat mount-point "/public/.gnupg/pubring.gpg")) @@ -232,17 +237,16 @@ If DESTINATION ends with '.gpg', it gets GPG-encrypted." (str:concat mount-point "/.snapshots/public." (local-time:format-timestring t (local-time:now) :format +fs-time-format+))) - ;; TODO: Uncomment this once tested. - ;; (uiop:delete-directory-tree - ;; (str:concat mount-point "/public/.gnupg") - ;; :validate t) + (uiop:delete-directory-tree + (str:concat mount-point "/public/.gnupg/") + :validate t) ;; TODO: How to copy directory trees in pure CL? (cmd:cmd "cp -av" (home ".gnupg") (str:concat mount-point "/public")) (cmd:cmd "sudo umount" mount-point) (cmd:cmd "sudo cryptsetup close" mapper-name))) (export-always 'sync-all) -(defun sync-all () +(defun sync-all () ; REVIEW: Optionally call `sync-gpg-key'? (dolist (op '(write-roots-index notmuch-tags stowed-saves