-# Test for existing version
-set +e
-cur_node="$(command -v node)"
-set -e
-cur_node_version=""
-if [ -n "$cur_node" ]; then
- cur_node_version="$("$cur_node" -v 2>/dev/null)"
- if [ "$cur_node_version" == "v${WEBI_VERSION}" ]; then
- echo "node v${WEBI_VERSION} already installed at $cur_node"
- exit 0
- else
- if [ "$cur_node" != "$common_node_home/bin/node" ]; then
- echo "WARN: possible conflict between node v${WEBI_VERSION} and ${cur_node_version} at ${cur_node}"
- fi
- if [ -x "$new_node" ]; then
- update_node_home
- echo "switched to node v${WEBI_VERSION} at $new_node_home"
- exit 0
- fi
- fi
-fi
-
-
-# Note: this file is `source`d by the true installer and hence will have the webi functions
-
-# because we created releases.js we can use webi_download()
-# downloads node to ~/Downloads
-webi_download
-
-# because this is tar or zip, we can webi_extract()
-# extracts to the WEBI_TMP directory, raw (no --strip-prefix)
-webi_extract
-
-pushd "$WEBI_TMP" 2>&1 >/dev/null
- echo Installing node v${WEBI_VERSION} as "$new_node"
-
- # simpler for single-binary commands
- #mv ./example*/bin/example "$HOME/.local/bin"
-
- # best for packages and toolchains
- rm -rf "$new_node_home"
- if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
- rsync -Krl ./node*/ "$new_node_home/" 2>/dev/null
- else
- cp -Hr ./node*/* "$new_node_home/" 2>/dev/null
- cp -Hr ./node*/.* "$new_node_home/" 2>/dev/null
- fi
- rm -rf ./node*
-popd 2>&1 >/dev/null
-
-###################
-# Update PATH #
-###################
-
-update_node_home
-
-echo "Installed 'node' and 'npm'"
-echo ""
+pkg_install() {
+ pushd "$WEBI_TMP" 2>&1 >/dev/null
+
+ # remove the versioned folder, just in case it's there with junk
+ rm -rf "$pkg_new_opt"
+
+ # rename the entire extracted folder to the new location
+ # (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
+ mv ./"$pkg_cmd_name"* "$pkg_new_opt"
+
+ popd 2>&1 >/dev/null
+}
+
+pkg_post_install() {
+ pkg_link_new_version
+
+ # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
+ # Adds "$HOME/.local/opt/node" to PATH
+ webi_path_add "$pkg_common_bin"
+}
+
+pkg_post_install_message() {
+ echo "Installed 'node' and 'npm'"
+}