Update node system install script to share code

main
Buddy Sandidge 4 years ago
parent b85d8e9c68
commit 8ed2056c5a

@ -1,2 +1,4 @@
# shellcheck shell=bash
#ft=sh
# shellcheck disable=SC2034
NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc"

@ -3,41 +3,14 @@
set -e
# shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
source "${XDG_DATA_HOME}/buddy-up/includes/node.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
}
VERSION=${VERSION:-v14.17.3}
DEST="${XDG_DATA_HOME}/apps/releases/node"
CURRENT="${DEST}/current"
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}"
set_symlink () {
local src="$1"
local dest="$2"
dest_dir=$(dirname "${dest}")
mkdir_if_missing "${dest_dir}"
pushd "${dest_dir}" > /dev/null || exit 1
unlink_if_set "${dest}"
ln -s "$(relative_path "${dest_dir}" "${src}")" "$(basename "${dest}")"
popd > /dev/null || exit 1
}
for app in "${CURRENT}"/bin/*; do
set_symlink "${CURRENT}/bin/${app}" "${XDG_BIN_HOME}/${app}"
done

@ -1,54 +1,20 @@
#!/usr/bin/env bash
NODE_VERSION=${NODE_VERSION:-v14.15.3}
PREFIX_DIR=${PREFIX_DIR:-/usr/local}
# shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/node.sh"
BIN_DIR=${PREFIX_DIR}/bin
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
PREFIX=${PREFIX:-/usr/local}
DEST="${PREFIX}/apps/releases/node"
CURRENT="${DEST}/current"
OS=
ARCH=
case $(uname -s) in
Linux*) OS=linux;;
Darwin*) OS=darwin;;
*) >&2 echo "unsupported os"; return;
esac
extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1" "sudo"
set_current_link "${DEST}" "${VERSION}" "sudo"
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
echo downloading node "$NODE_VERSION" to temp directory "${TMP_DIR}"
curl --silent --output "${DEST_FILE}" "${URL}"
sudo tar xf "${DEST_FILE}" --directory "${NODE_DEST_DIR}" --strip-components 1
sudo chown --recursive root:root "${NODE_DEST_DIR}"
else
echo node "$NODE_VERSION" already installed
fi
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}" || exit 1
for bin in "${NODE_CURRENT}/bin/"*; do
[[ -s $bin ]] || sudo ln --symbolic "${NODE_CURRENT}/bin/$bin"
for app in "${CURRENT}"/bin/*; do
set_symlink "${CURRENT}/bin/${app}" "${XDG_BIN_HOME}/${app}" sudo
done
if [[ $TMP_DIR != "" ]]; then
rm -rf "${TMP_DIR}"
echo removed up temp directory "${TMP_DIR}"
fi
set_symlink "${CURRENT}/include/node" "${PREFIX}/include/node" sudo
set_symlink "${CURRENT}/share/doc/node" "${CURRENT}/share/doc/node" sudo
set_symlink "${CURRENT}/share/man/man1/node.1" "${CURRENT}/share/man/man1/node.1" sudo
set_symlink "${CURRENT}/share/systemtap/tapset/node.stp" "${CURRENT}/share/systemtap/tapset/node.stp" sudo

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# 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
}
set_symlink () {
src="$1"
dest="$2"
sudo="$3"
dest_dir=$(dirname "${dest}")
mkdir_if_missing "${dest_dir}"
pushd "${dest_dir}" > /dev/null || exit 1
unlink_if_set "${dest}" "${sudo}"
$sudo ln -s "$(relative_path "${dest_dir}" "${src}")" "$(basename "${dest}")"
popd > /dev/null || exit 1
}
VERSION=${VERSION:-v14.17.3}
# shellcheck disable=SC2034
URL=https://nodejs.org/dist/${VERSION}/node-${VERSION}-$(get_os)-$(get_arch).tar.xz
Loading…
Cancel
Save