diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-25 15:12:14 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-27 13:26:21 -0700 |
commit | afe955cbd1dab48cf15a5a9b3f033d47d87720f4 (patch) | |
tree | d2ff5bbddf94471e8f29015d90fbf71d22e84702 /src | |
parent | 911bb7fc7597a83d1453ae083e33d7eaa8640f6b (diff) | |
download | consfigurator-afe955cbd1dab48cf15a5a9b3f033d47d87720f4.tar.gz |
convert some internal shell snippets to single lines
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r-- | src/connection.lisp | 5 | ||||
-rw-r--r-- | src/connection/shell-wrap.lisp | 22 | ||||
-rw-r--r-- | src/package.lisp | 1 | ||||
-rw-r--r-- | src/util.lisp | 15 |
4 files changed, 29 insertions, 14 deletions
diff --git a/src/connection.lisp b/src/connection.lisp index 7db2413..b03e33e 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -318,7 +318,8 @@ which will be cleaned up when BODY is finished." ;; ;; While GNU M4 mkstemp makes the temporary file at most readable and ;; writeable by its owner, POSIX doesn't require this, so set a umask. - #?"umask 077 + (sh-script-to-single-line + #?"umask 077 exec 3>&1 if err=\$(if command -v m4 >/dev/null; then echo 'mkstemp(${template})' | m4 2>&1 1>&3 @@ -334,7 +335,7 @@ else ?*) printf >&2 \"%s\\n\" \"$err\" ;; esac exit 1 -fi") +fi")) (defun mktemp (&key (connection *connection*) directory) "Make a temporary file on the remote side, in DIRECTORY, defaulting to /tmp." diff --git a/src/connection/shell-wrap.lisp b/src/connection/shell-wrap.lisp index 51591b8..1200391 100644 --- a/src/connection/shell-wrap.lisp +++ b/src/connection/shell-wrap.lisp @@ -46,18 +46,16 @@ path content mode) - (let ((cmd - (format - nil "set -e -tmpf=$(~A) -trap \"rm -f '$tmpf'\" EXIT HUP KILL TERM INT -chmod ~O \"$tmpf\" -cat >\"$tmpf\" -mv \"$tmpf\" ~A" - (mkstemp-cmd - (merge-pathnames "tmp.XXXXXX" (pathname-directory-pathname path))) - mode - (sh-escape path)))) + (let* ((mkstemp (mkstemp-cmd + (merge-pathnames "tmp.XXXXXX" + (pathname-directory-pathname path)))) + (cmd (sh-script-to-single-line + (format nil "set -e + tmpf=$(~A) + trap \"rm -f '$tmpf'\" EXIT HUP KILL TERM INT + chmod ~O \"$tmpf\" + cat >\"$tmpf\" + mv \"$tmpf\" ~A" mkstemp mode (sh-escape path))))) (multiple-value-bind (out exit) (connection-run conn cmd content) (unless (zerop exit) (error "Failed to write ~A: ~A" path out))))) diff --git a/src/package.lisp b/src/package.lisp index 9f1637f..69b50fb 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -131,6 +131,7 @@ #:prog-changes #:add-change #:return-changes + #:sh-script-to-single-line #:*consfigurator-debug-level* #:with-indented-inform diff --git a/src/util.lisp b/src/util.lisp index c78005f..cd986d9 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -432,6 +432,21 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." ,@body ,result))))) +(defun sh-script-to-single-line (script) + "Attempt to convert a multiline POSIX sh script to a single line. + +The current implementation is naïve, and certainly unsuitable for converting +arbitrary scripts. Thus, this function is presently intended to be used only +on simple scripts embedded in source code, written with newlines for the sake +of maintainability. Converting those scripts to single lines before they are +executed improves Consfigurator's debug output, and also makes process names +visible to remote commands like ps(1) more readable." + (re:regex-replace-all + #?/\s+/ (re:regex-replace-all "(then|else|elif|fi|case|in|;;|do|done);" + (format nil "~{~A~^; ~}" (lines script)) + "\\1") + " ")) + ;;;; Progress & debug printing |