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 # shellcheck disable=SC2034
NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc" NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc"

@ -3,41 +3,14 @@
set -e set -e
# shellcheck disable=SC1090 # 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" DEST="${XDG_DATA_HOME}/apps/releases/node"
CURRENT="${DEST}/current" 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" extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1"
set_current_link "${DEST}" "${VERSION}" 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 for app in "${CURRENT}"/bin/*; do
set_symlink "${CURRENT}/bin/${app}" "${XDG_BIN_HOME}/${app}" set_symlink "${CURRENT}/bin/${app}" "${XDG_BIN_HOME}/${app}"
done done

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