26 lines
1.1 KiB
Bash
Executable File
26 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# 35-nvm — Node Version Manager + Node LTS.
|
|
|
|
step_name="nvm"
|
|
step_desc="nvm into ~$TARGET_USER/.nvm, install Node LTS"
|
|
step_run="run_nvm"
|
|
|
|
run_nvm() {
|
|
log "installing nvm for $TARGET_USER"
|
|
local nvm_home="$TARGET_HOME/.nvm"
|
|
export NVM_DIR="$nvm_home"
|
|
|
|
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
|
|
ok "nvm already present at $NVM_DIR"
|
|
else
|
|
# fetch the install script at a pinned NVM version (update here to upgrade)
|
|
as_user env NVM_DIR="$nvm_home" bash -c 'curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash' \
|
|
|| { warn "nvm install failed"; return; }
|
|
ok "nvm installed to $NVM_DIR"
|
|
fi
|
|
|
|
# run node/lts install as the target user so binary ownership + default are theirs
|
|
as_user bash -lc 'export NVM_DIR='"$NVM_DIR"'; source "$NVM_DIR/nvm.sh"; nvm install --lts && nvm use --lts && nvm alias default lts/*' \
|
|
|| warn "node lts install had issues (continue; run 'nvm install --lts' as $TARGET_USER)"
|
|
as_user bash -lc 'export NVM_DIR='"$NVM_DIR"'; source "$NVM_DIR/nvm.sh"; command -v node >/dev/null && echo " node \$(node -v) active for $TARGET_USER"' 2>/dev/null || true
|
|
} |