diff --git a/features/src/vip-cli/devcontainer-feature.json b/features/src/vip-cli/devcontainer-feature.json index e707abd9..fb786989 100644 --- a/features/src/vip-cli/devcontainer-feature.json +++ b/features/src/vip-cli/devcontainer-feature.json @@ -1,7 +1,7 @@ { "id": "vip-cli", "name": "VIP-CLI", - "version": "1.4.1", + "version": "1.4.2", "description": "Installs VIP-CLI into the Dev Environment", "options": { "enabled": { diff --git a/features/src/vip-cli/install.sh b/features/src/vip-cli/install.sh index b6ddb9eb..a858f8a2 100755 --- a/features/src/vip-cli/install.sh +++ b/features/src/vip-cli/install.sh @@ -15,8 +15,54 @@ fi if [ "${ENABLED}" = "true" ]; then echo '(*) Installing VIP CLI...' - apk add --no-cache nodejs npm - npm i -g "@automattic/vip@${VERSION}" + # /etc/os-release may overwrite VERSION + VIP_CLI_VERSION="${VERSION}" + + if ! hash node >/dev/null 2>&1 || ! hash npm >/dev/null 2>&1; then + # shellcheck source=/dev/null + . /etc/os-release + + : "${ID:=}" + : "${ID_LIKE:=${ID}}" + + case "${ID_LIKE}" in + "debian") + PACKAGES="" + + if ! hash curl >/dev/null 2>&1; then + PACKAGES="${PACKAGES} curl" + fi + + if ! hash update-ca-certificates >/dev/null 2>&1; then + PACKAGES="${PACKAGES} ca-certificates" + fi + + if [ -n "${PACKAGES}" ]; then + apt-get update + # shellcheck disable=SC2086 + apt-get install -y --no-install-recommends ${PACKAGES} + fi + + curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh && chmod +x nodesource_setup.sh + ./nodesource_setup.sh + apt-get install -y nodejs + + apt-get clean + rm -rf /var/lib/apt/lists/* + ;; + + "alpine") + apk add --no-cache nodejs npm + ;; + + *) + echo "(!) Unsupported distribution: ${ID}" + exit 1 + ;; + esac + fi + + npm i -g "@automattic/vip@${VIP_CLI_VERSION+}" install -D -m 0755 -o root -g root vip-sync-db.sh /usr/local/bin/vip-sync-db