#!/usr/bin/env bash set -e # shellcheck disable=SC1090 source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" get_arch () { case $(uname -m) in x86_64*) echo x64;; amd64*) echo x64;; arm) echo armv7l;; armv7*) echo armv7l;; armv6*) echo armv7l;; armv8*) echo arm64;; aarch64*) echo arm64;; *) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;; esac } APPS="node npm npx" VERSION=${VERSION:-v14.17.3} DEST="${XDG_DATA_HOME}/apps/releases/node" URL=https://nodejs.org/dist/${VERSION}/node-${VERSION}-$(get_os)-$(get_arch).tar.xz extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1" set_current_link "${DEST}" "${VERSION}" pushd "${XDG_BIN_HOME}" >/dev/null for app in ${APPS}; do if [[ -L "${XDG_BIN_HOME}/${app}" ]]; then unlink "${XDG_BIN_HOME}/${app}" fi REL_LINK="$(relative_path "${XDG_BIN_HOME}" "${DEST}/current/bin/${app}")" ln --symbolic "${REL_LINK}" "${app}" done popd >/dev/null