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