Browse Source

Merge "Use sudo -E in install-js-tools only if not root"

tags/3.5.0
Zuul 4 months ago
parent
commit
8bdd1208e3
1 changed files with 17 additions and 12 deletions
  1. 17
    12
      tools/install-js-tools.sh

+ 17
- 12
tools/install-js-tools.sh View File

@@ -13,25 +13,30 @@
13 13
 # implied.
14 14
 # See the License for the specific language governing permissions and
15 15
 # limitations under the License.
16
+if [ $EUID -ne 0 ] ; then
17
+    SUDO='sudo -E'
18
+fi
16 19
 
17 20
 if type apt-get; then
18 21
     # Install https transport - otherwise apt-get HANGS on https urls
19
-    sudo apt-get update
20
-    sudo apt-get install apt-transport-https
22
+    # Install curl so the curl commands work
23
+    # Install gnupg2 so that the apt-key add works
24
+    $SUDO apt-get update
25
+    $SUDO apt-get install -y apt-transport-https curl gnupg2
21 26
     # Install recent NodeJS repo
22
-    curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
23
-    echo "deb https://deb.nodesource.com/node_8.x xenial main" | sudo tee /etc/apt/sources.list.d/nodesource.list
27
+    curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | $SUDO apt-key add -
28
+    echo "deb https://deb.nodesource.com/node_8.x xenial main" | $SUDO tee /etc/apt/sources.list.d/nodesource.list
24 29
     # Install yarn repo
25
-    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
26
-    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
27
-    sudo apt-get update
28
-    sudo DEBIAN_FRONTEND=noninteractive \
29
-        apt-get -q --option "Dpkg::Options::=--force-confold" --assume-yes \
30
+    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | $SUDO apt-key add -
31
+    echo "deb https://dl.yarnpkg.com/debian/ stable main" | $SUDO tee /etc/apt/sources.list.d/yarn.list
32
+    $SUDO apt-get update
33
+    DEBIAN_FRONTEND=noninteractive \
34
+        $SUDO apt-get -q --option "Dpkg::Options::=--force-confold" --assume-yes \
30 35
         install nodejs yarn
31 36
 elif type yum; then
32
-    sudo curl https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo
33
-    sudo $(dirname $0)/install-js-repos-rpm.sh
34
-    sudo yum -y install nodejs yarn
37
+    $SUDO curl https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo
38
+    $SUDO $(dirname $0)/install-js-repos-rpm.sh
39
+    $SUDO yum -y install nodejs yarn
35 40
 elif type brew; then
36 41
     brew install nodejs yarn
37 42
 else

Loading…
Cancel
Save