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
This commit is contained in:
Monty Taylor 2019-01-21 19:11:14 +00:00
parent 5bae85e626
commit d940043197
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
1 changed files with 17 additions and 12 deletions

View File

@ -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