If there is no TTY, also skip verbose sudo messages

This commit is contained in:
Graham Christensen 2017-07-13 19:03:35 -04:00
parent ce2281e6d8
commit 12f6bb33d2
No known key found for this signature in database
GPG key ID: 06121D366FE9435C
2 changed files with 34 additions and 3 deletions

View file

@ -49,6 +49,14 @@ else
readonly IS_HEADLESS='yes' readonly IS_HEADLESS='yes'
fi fi
headless() {
if [ "$IS_HEADLESS" = "yes" ]; then
return 0
else
return 1
fi
}
contactme() { contactme() {
echo "We'd love to help if you need it." echo "We'd love to help if you need it."
echo "" echo ""
@ -179,7 +187,7 @@ failure() {
ui_confirm() { ui_confirm() {
_textout "$GREEN$GREEN_UL" "$1" _textout "$GREEN$GREEN_UL" "$1"
if [ "$IS_HEADLESS" = "yes" ]; then if headless; then
echo "No TTY, assuming you would say yes :)" echo "No TTY, assuming you would say yes :)"
return 0 return 0
fi fi
@ -221,9 +229,10 @@ __sudo() {
_sudo() { _sudo() {
local expl="$1" local expl="$1"
shift shift
if __sudo "$expl" "$*"; then if ! headless; then
sudo "$@" __sudo "$expl" "$*"
fi fi
sudo "$@"
} }
@ -620,6 +629,27 @@ EOF
chat_about_sudo() { chat_about_sudo() {
header "let's talk about sudo" header "let's talk about sudo"
if headless; then
cat <<EOF
This script is going to call sudo a lot. Normally, it would show you
exactly what commands it is running and why. However, the script is
run in a headless fashion, like this:
$ curl https://nixos.org/nix/install | sh
or maybe in a CI pipeline. Because of that, we're going to skip the
verbose output in the interest of brevity.
If you would like to
see the output, try like this:
$ curl -o install-nix https://nixos.org/nix/install
$ sh ./install-nix
EOF
return 0
fi
cat <<EOF cat <<EOF
This script is going to call sudo a lot. Every time we do, it'll This script is going to call sudo a lot. Every time we do, it'll
output exactly what it'll do, and why. output exactly what it'll do, and why.

View file

@ -91,5 +91,6 @@ verify
echo -n "" | PINCH_ME_IM_SILLY=true ./install echo -n "" | PINCH_ME_IM_SILLY=true ./install
verify verify
test -e /nix/store/.silly-hint test -e /nix/store/.silly-hint
cleanup cleanup
) )