check for AWS environment before running sudo

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2023-06-14 14:03:44 -04:00
parent 7f650acb3c
commit 89adbc6e5b
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59

View File

@ -207,6 +207,8 @@ else
# Refresh sudo credentials if needed
if ping -c 1 -q metadata.google.internal &> /dev/null; then
echo 'Running on GCE, not asking for sudo credentials'
elif ping -c 1 -q 169.254.169.254 &> /dev/null; then
echo 'Running on AWS, not asking for sudo credentials'
elif sudo --non-interactive "$(which bash)" -c true 2> /dev/null; then
# if we can run bash without a password, it's a pretty safe bet that either
# we can run any command without a password, or that sudo credentials