Add node settings for xdg

main
Buddy Sandidge 4 years ago
parent 212ba2f984
commit b79b34ee29

@ -0,0 +1,4 @@
prefix=${XDG_DATA_HOME}/npm
cache=${XDG_CACHE_HOME}/npm
tmp=${XDG_RUNTIME_DIR}/npm
init-module=${XDG_CONFIG_HOME}/npm/config/npm-init.js

@ -0,0 +1,2 @@
# shellcheck disable=SC2034
NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc"

@ -1,42 +1,35 @@
#!/usr/bin/env bash
set -e
NODE_VERSION=${NODE_VERSION:-v14.15.3}
PREFIX_DIR=${PREFIX_DIR:-/usr/local}
NODE_VERSION=${NODE_VERSION:-v12.16.2}
PREFIX_DIR=/usr/local
BIN_DIR=${PREFIX_DIR}/bin
NODE_PREFIX_DIR=${PREFIX_DIR}/node
NODE_PREFIX_DIR=${PREFIX_DIR}/apps/node
NODE_DEST_DIR=${NODE_PREFIX_DIR}/${NODE_VERSION}
NODE_DEST_BIN_DIR=${NODE_DEST_DIR}/bin
NODE_CURRENT=${NODE_PREFIX_DIR}/current
OS=
if [[ $OSTYPE =~ linux ]]; then
OS=linux
elif [[ $OSTYPE =~ darwin ]]; then
OS=darwin
else
echo unknown os: "$OSTYPE"
exit 1
fi
ARCH=
if [[ $(uname -m) == x86_64 ]]; then
ARCH=x64
else
echo arch not yet supported: "$(uname -m)"
exit 1
fi
case $(uname -s) in
Linux*) OS=linux;;
Darwin*) OS=darwin;;
*) >&2 echo "unsupported os"; return;
esac
case $(uname -m) in
x86_64*) ARCH=x64;;
*) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;;
esac
[[ -d "${NODE_DEST_DIR}" ]] || sudo mkdir -p "${NODE_DEST_DIR}"
URL=https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${OS}-${ARCH}.tar.xz
TMP_DIR=
if [[ ! -d ${NODE_DEST_BIN_DIR} ]]; then
TMP_DIR=$(mktemp --directory)
DEST_FILE=$TMP_DIR/node.tar.xz
URL=https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${OS}-${ARCH}.tar.xz
echo downloading node "$NODE_VERSION" to temp directory "${TMP_DIR}"
curl --silent --output "${DEST_FILE}" "${URL}"
@ -46,11 +39,11 @@ else
echo node "$NODE_VERSION" already installed
fi
cd ${NODE_PREFIX_DIR}
cd "${NODE_PREFIX_DIR}" || exit 1
[[ -s current ]] && sudo unlink current
sudo ln --symbolic "${NODE_VERSION}" current
echo current version set to "${NODE_VERSION}"
cd ${BIN_DIR}
cd "${BIN_DIR}" || exit 1
for bin in "${NODE_CURRENT}/bin/"*; do
[[ -s $bin ]] || sudo ln --symbolic "${NODE_CURRENT}/bin/$bin"
done
Loading…
Cancel
Save