From d940043197385a5b223a97ce804453adc1d08aff Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Mon, 21 Jan 2019 19:11:14 +0000 Subject: [PATCH] Use sudo -E in install-js-tools only if not root Add -E to sudo so that env vars pass through, ensuring proxies are used. Update the script to check uid to see if the user is already root. If the EUID is already 0, skip calling sudo. Change-Id: If9a729184c5fea1124faa36faec73b550f1ae0bb --- tools/install-js-tools.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/install-js-tools.sh b/tools/install-js-tools.sh index a2a77cafc4..d65668c853 100755 --- a/tools/install-js-tools.sh +++ b/tools/install-js-tools.sh @@ -13,25 +13,30 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. +if [ $EUID -ne 0 ] ; then + SUDO='sudo -E' +fi if type apt-get; then # Install https transport - otherwise apt-get HANGS on https urls - sudo apt-get update - sudo apt-get install apt-transport-https + # Install curl so the curl commands work + # Install gnupg2 so that the apt-key add works + $SUDO apt-get update + $SUDO apt-get install -y apt-transport-https curl gnupg2 # Install recent NodeJS repo - curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add - - echo "deb https://deb.nodesource.com/node_8.x xenial main" | sudo tee /etc/apt/sources.list.d/nodesource.list + curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | $SUDO apt-key add - + echo "deb https://deb.nodesource.com/node_8.x xenial main" | $SUDO tee /etc/apt/sources.list.d/nodesource.list # Install yarn repo - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - sudo apt-get update - sudo DEBIAN_FRONTEND=noninteractive \ - apt-get -q --option "Dpkg::Options::=--force-confold" --assume-yes \ + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | $SUDO apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | $SUDO tee /etc/apt/sources.list.d/yarn.list + $SUDO apt-get update + DEBIAN_FRONTEND=noninteractive \ + $SUDO apt-get -q --option "Dpkg::Options::=--force-confold" --assume-yes \ install nodejs yarn elif type yum; then - sudo curl https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo - sudo $(dirname $0)/install-js-repos-rpm.sh - sudo yum -y install nodejs yarn + $SUDO curl https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo + $SUDO $(dirname $0)/install-js-repos-rpm.sh + $SUDO yum -y install nodejs yarn elif type brew; then brew install nodejs yarn else