chore(style): add shebang, set bash strict mode, create function
[webi-installers/.git] / node / install.sh
index f2c259c801152e02d988e79cfea9f26ae6cbed8a..f321ab568d78e2f0cfba65ef20a18a1194b85ef7 100644 (file)
@@ -1,19 +1,29 @@
 #!/bin/bash
 
+# "This is too simple" you say! "Where is the magic!?" you ask.
+# There is no magic!
+# The custom functions for node are here.
+# The generic functions - version checks, download, extract, etc - are here:
+#   - https://github.com/webinstall/packages/branches/master/_webi/template.sh
+
 set -e
 set -u
 
 pkg_cmd_name="node"
+#WEBI_SINGLE=""
 
-pkg_get_current_version() {
+function pkg_get_current_version() {
     # 'node --version' has output in this format:
     #       v12.8.0
     # This trims it down to just the version number:
     #       12.8.0
-    echo "$(node --version 2>/dev/null | head -n 1 | cut -d' ' -f1 | sed 's:^v::')"
+    node --version 2> /dev/null |
+        head -n 1 |
+        cut -d' ' -f1 |
+        sed 's:^v::'
 }
 
-pkg_install() {
+function pkg_install() {
     # mkdir -p $HOME/.local/opt
     mkdir -p "$(dirname $pkg_src)"
 
@@ -21,14 +31,17 @@ pkg_install() {
     mv ./"$pkg_cmd_name"* "$pkg_src"
 }
 
-pkg_link() {
+function pkg_link() {
     # rm -f "$HOME/.local/opt/node"
     rm -f "$pkg_dst"
 
     # ln -s "$HOME/.local/opt/node-v14.4.0" "$HOME/.local/opt/node"
     ln -s "$pkg_src" "$pkg_dst"
+
+    # Node bugfix: use the correct version of node, even if PATH has a conflict
+    "$pkg_src"/bin/node "$pkg_src"/bin/npm config set scripts-prepend-node-path=true
 }
 
-pkg_done_message() {
+function pkg_done_message() {
     echo "Installed 'node' and 'npm' at $pkg_dst"
 }