|
| 1 | +# |
| 2 | +# Copyright (c) 2012-2017 Red Hat, Inc. |
| 3 | +# All rights reserved. This program and the accompanying materials |
| 4 | +# are made available under the terms of the Eclipse Public License v1.0 |
| 5 | +# which accompanies this distribution, and is available at |
| 6 | +# http://www.eclipse.org/legal/epl-v10.html |
| 7 | +# |
| 8 | +# Contributors: |
| 9 | +# Red Hat, Inc. - initial API and implementation |
| 10 | +# |
| 11 | + |
| 12 | +is_current_user_root() { |
| 13 | + test "$(id -u)" = 0 |
| 14 | +} |
| 15 | + |
| 16 | +is_current_user_sudoer() { |
| 17 | + sudo -n true > /dev/null 2>&1 |
| 18 | +} |
| 19 | + |
| 20 | +set_sudo_command() { |
| 21 | + if is_current_user_sudoer && ! is_current_user_root; then SUDO="sudo -E"; else unset SUDO; fi |
| 22 | +} |
| 23 | + |
| 24 | +set_sudo_command |
| 25 | +unset PACKAGES |
| 26 | +command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; } |
| 27 | +command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; } |
| 28 | + |
| 29 | +AGENT_BINARIES_URI=http://download.jboss.org/jbosstools/oxygen/stable/builds/yaml-language-server/yaml-language-server-latest.tar.gz |
| 30 | +CHE_DIR=$HOME/che |
| 31 | +LS_DIR=${CHE_DIR}/ls-yaml |
| 32 | +LS_LAUNCHER=${LS_DIR}/launch.sh |
| 33 | + |
| 34 | +if [ -f /etc/centos-release ]; then |
| 35 | + FILE="/etc/centos-release" |
| 36 | + LINUX_TYPE=$(cat $FILE | awk '{print $1}') |
| 37 | + elif [ -f /etc/redhat-release ]; then |
| 38 | + FILE="/etc/redhat-release" |
| 39 | + LINUX_TYPE=$(cat $FILE | cut -c 1-8) |
| 40 | + else |
| 41 | + FILE="/etc/os-release" |
| 42 | + LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]') |
| 43 | + LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=) |
| 44 | +fi |
| 45 | + |
| 46 | +MACHINE_TYPE=$(uname -m) |
| 47 | + |
| 48 | +mkdir -p ${CHE_DIR} |
| 49 | +mkdir -p ${LS_DIR} |
| 50 | + |
| 51 | +######################## |
| 52 | +### Install packages ### |
| 53 | +######################## |
| 54 | + |
| 55 | +# Red Hat Enterprise Linux 7 |
| 56 | +############################ |
| 57 | +if echo ${LINUX_TYPE} | grep -qi "rhel"; then |
| 58 | + test "${PACKAGES}" = "" || { |
| 59 | + ${SUDO} yum install ${PACKAGES}; |
| 60 | + } |
| 61 | + |
| 62 | + command -v nodejs >/dev/null 2>&1 || { |
| 63 | + curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 64 | + ${SUDO} yum -y install nodejs; |
| 65 | + } |
| 66 | + |
| 67 | +# Red Hat Enterprise Linux 6 |
| 68 | +############################ |
| 69 | +elif echo ${LINUX_TYPE} | grep -qi "Red Hat"; then |
| 70 | + test "${PACKAGES}" = "" || { |
| 71 | + ${SUDO} yum install ${PACKAGES}; |
| 72 | + } |
| 73 | + |
| 74 | + command -v nodejs >/dev/null 2>&1 || { |
| 75 | + curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 76 | + ${SUDO} yum -y install nodejs; |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | +# Ubuntu 14.04 16.04 / Linux Mint 17 |
| 81 | +#################################### |
| 82 | +elif echo ${LINUX_TYPE} | grep -qi "ubuntu"; then |
| 83 | + test "${PACKAGES}" = "" || { |
| 84 | + ${SUDO} apt-get update; |
| 85 | + ${SUDO} apt-get -y install ${PACKAGES}; |
| 86 | + } |
| 87 | + |
| 88 | + command -v nodejs >/dev/null 2>&1 || { |
| 89 | + { |
| 90 | + curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 91 | + }; |
| 92 | + |
| 93 | + ${SUDO} apt-get update; |
| 94 | + ${SUDO} apt-get install -y nodejs; |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +# Debian 8 |
| 99 | +########## |
| 100 | +elif echo ${LINUX_TYPE} | grep -qi "debian"; then |
| 101 | + test "${PACKAGES}" = "" || { |
| 102 | + ${SUDO} apt-get update; |
| 103 | + ${SUDO} apt-get -y install ${PACKAGES}; |
| 104 | + } |
| 105 | + |
| 106 | + command -v nodejs >/dev/null 2>&1 || { |
| 107 | + { |
| 108 | + curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 109 | + }; |
| 110 | + |
| 111 | + ${SUDO} apt-get update; |
| 112 | + ${SUDO} apt-get install -y nodejs; |
| 113 | + } |
| 114 | + |
| 115 | +# Fedora 23 |
| 116 | +########### |
| 117 | +elif echo ${LINUX_TYPE} | grep -qi "fedora"; then |
| 118 | + command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" procps-ng"; } |
| 119 | + test "${PACKAGES}" = "" || { |
| 120 | + ${SUDO} dnf -y install ${PACKAGES}; |
| 121 | + } |
| 122 | + |
| 123 | + command -v nodejs >/dev/null 2>&1 || { |
| 124 | + curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 125 | + ${SUDO} dnf -y install nodejs; |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | +# CentOS 7.1 & Oracle Linux 7.1 |
| 130 | +############################### |
| 131 | +elif echo ${LINUX_TYPE} | grep -qi "centos"; then |
| 132 | + test "${PACKAGES}" = "" || { |
| 133 | + ${SUDO} yum -y install ${PACKAGES}; |
| 134 | + } |
| 135 | + |
| 136 | + command -v nodejs >/dev/null 2>&1 || { |
| 137 | + curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -; |
| 138 | + ${SUDO} yum -y install nodejs; |
| 139 | + } |
| 140 | + |
| 141 | +# openSUSE 13.2 |
| 142 | +############### |
| 143 | +elif echo ${LINUX_TYPE} | grep -qi "opensuse"; then |
| 144 | + test "${PACKAGES}" = "" || { |
| 145 | + ${SUDO} zypper install -y ${PACKAGES}; |
| 146 | + } |
| 147 | + |
| 148 | + command -v nodejs >/dev/null 2>&1 || { |
| 149 | + ${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js |
| 150 | + ${SUDO} zypper in nodejs |
| 151 | + } |
| 152 | + |
| 153 | +else |
| 154 | + >&2 echo "Unrecognized Linux Type" |
| 155 | + >&2 cat $FILE |
| 156 | + exit 1 |
| 157 | +fi |
| 158 | + |
| 159 | + |
| 160 | +######################## |
| 161 | +### Install Yaml LS ### |
| 162 | +######################## |
| 163 | + |
| 164 | +curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR} |
| 165 | + |
| 166 | +touch ${LS_LAUNCHER} |
| 167 | +chmod +x ${LS_LAUNCHER} |
| 168 | +echo "nodejs ${LS_DIR}/out/server/src/server.js --stdio" > ${LS_LAUNCHER} |
0 commit comments