add502255560d7ec12a4334a99127157be05f64f
[webi-installers/.git] / node / install.sh
1 #!/bin/bash
2
3 # "This is too simple" you say! "Where is the magic!?" you ask.
4 # There is no magic!
5 # The custom functions for node are here.
6 # The generic functions - version checks, download, extract, etc - are here:
7 #   - https://github.com/webinstall/packages/branches/master/_webi/template.sh
8
9 set -e
10 set -u
11
12 pkg_cmd_name="node"
13 #WEBI_SINGLE=""
14
15 pkg_get_current_version() {
16     # 'node --version' has output in this format:
17     #       v12.8.0
18     # This trims it down to just the version number:
19     #       12.8.0
20     echo "$(node --version 2>/dev/null | head -n 1 | cut -d' ' -f1 | sed 's:^v::')"
21 }
22
23 pkg_install() {
24     # mkdir -p $HOME/.local/opt
25     mkdir -p "$(dirname $pkg_src)"
26
27     # mv ./node* "$HOME/.local/opt/node-v14.4.0"
28     mv ./"$pkg_cmd_name"* "$pkg_src"
29 }
30
31 pkg_link() {
32     # rm -f "$HOME/.local/opt/node"
33     rm -f "$pkg_dst"
34
35     # ln -s "$HOME/.local/opt/node-v14.4.0" "$HOME/.local/opt/node"
36     ln -s "$pkg_src" "$pkg_dst"
37
38     # Node bugfix: use the correct version of node, even if PATH has a conflict
39     "$pkg_src"/bin/node "$pkg_src"/bin/npm config set scripts-prepend-node-path=true
40 }
41
42 pkg_done_message() {
43     echo "Installed 'node' and 'npm' at $pkg_dst"
44 }