From cb5098dd8e3f55ad7c4395d494ca395a319640af Mon Sep 17 00:00:00 2001 From: David Sulpy Date: Thu, 6 Dec 2018 10:17:29 -0600 Subject: [PATCH] adjusted install script to function correctly if not run as sudo making sudo optional for pyenv or other python environment managers --- install_scripts/python | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/install_scripts/python b/install_scripts/python index a20c08c..3d217b4 100755 --- a/install_scripts/python +++ b/install_scripts/python @@ -22,6 +22,15 @@ echo "This may take a couple minutes to install, grab some coffee :)" echo "But don't forget to come back, I'll have questions later!" echo "" INITIALSTATE_AUTH_SVC=${INITIALSTATE_AUTH_SVC:="auth"} +SUDO='' + +# if this script is being run by root user +# then we need to modify file saving commands +# to make sure ownership is correct +if [ "$EUID" -eq 0 ]; then + SUDO="sudo -u $SUDO_USER" +fi + function check_for_easy_install { if hash easy_install 2>/dev/null; then @@ -129,7 +138,7 @@ function download_script { echo "invalid credentials, let's try that again!" download_script else - echo "$python_example" | sudo -u $SUDO_USER tee "$example_location" > /dev/null + echo "$python_example" | $SUDO tee "$example_location" > /dev/null fi else echo -n "Enter iot.app.initialstate.com user email: " @@ -158,7 +167,7 @@ function download_script { echo "there's currently an issue with this endpoint, try again later or email support@initialstate.com. Thanks!" exit 1 else - echo "$python_example" | sudo -u $SUDO_USER tee "$example_location" > /dev/null + echo "$python_example" | $SUDO tee "$example_location" > /dev/null fi fi @@ -181,7 +190,7 @@ function download_script_old { echo "invalid credentials, let's try that again!" download_script else - echo "$python_example" | sudo -u $SUDO_USER tee "$example_location" > /dev/null + echo "$python_example" | $SUDO tee "$example_location" > /dev/null fi }