diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 6cdde8d..2e2d2cd 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -46,20 +46,19 @@ sudo_run() { } # run_remote_sudo -# Runs `cmd` on the remote host, with the wrapped command preceded -# by sudo_run. Used so the rest of the script can stay readable. +# Runs `cmd` on the remote host under sudo, piping the password +# through `sudo -S -p ''`. We also force PAGER/SYSTEMD_PAGER=cat +# inside the sh -c so any systemctl / journalctl call (even if +# piped further) doesn't open a pager over the ssh -tt TTY. run_remote_sudo() { local ssh_prefix="$1" local pw="$2" shift 2 - # Build the inner shell command: pipe pw to sudo -S -p '' "cmd". - # We pre-marshal the command into a single string the SSH side can - # `eval` safely (single-quote the arguments). local inner="" for a in "$@"; do inner+=" '"$(printf %s "$a" | sed "s/'/'\\\\''/g")"'" done - $ssh_prefix "printf '%s\n' '$pw' | sudo -S -p '' sh -c '$inner'" + $ssh_prefix "printf '%s\n' '$pw' | sudo -S -p '' sh -c 'export PAGER=cat SYSTEMD_PAGER=cat; $inner'" } # ponytail: Wipe-and-replace. The deploys are stateful on the VM only via @@ -82,12 +81,14 @@ install_unit() { # Prints a short status + last 10 journal lines. Uses sudo -S for # journalctl (always root-only) but `systemctl status` works for # the administrator's own services without sudo on most distros. +# PAGER/SYSTEMD_PAGER=cat and --output=cat on journalctl defeat +# the pager that would otherwise kick in over the ssh -tt TTY. status_block() { local ssh_prefix="$1" local unit="$2" local pw="$3" - $ssh_prefix "echo ' status:'; systemctl --no-pager --full status $unit 2>/dev/null | head -3" - $ssh_prefix "echo ' journal (last 10):'; printf '%s\n' '$pw' | sudo -S -p '' journalctl -u $unit -n 10 --no-pager" + $ssh_prefix "echo ' status:'; PAGER=cat SYSTEMD_PAGER=cat systemctl --no-pager --full status $unit 2>/dev/null | head -3" + $ssh_prefix "echo ' journal (last 10):'; export PAGER=cat SYSTEMD_PAGER=cat; printf '%s\n' '$pw' | sudo -S -p '' journalctl -u $unit -n 10 --no-pager --output=cat 2>/dev/null | head -20" } # restart_unit