refactor: finish moving ssh-* scripts to own installers
[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 function 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     node --version 2> /dev/null |
21         head -n 1 |
22         cut -d' ' -f1 |
23         sed 's:^v::'
24 }
25
26 function pkg_install() {
27     # mkdir -p $HOME/.local/opt
28     mkdir -p "$(dirname $pkg_src)"
29
30     # mv ./node* "$HOME/.local/opt/node-v14.4.0"
31     mv ./"$pkg_cmd_name"* "$pkg_src"
32 }
33
34 function pkg_link() {
35     # rm -f "$HOME/.local/opt/node"
36     rm -f "$pkg_dst"
37
38     # ln -s "$HOME/.local/opt/node-v14.4.0" "$HOME/.local/opt/node"
39     ln -s "$pkg_src" "$pkg_dst"
40
41     # Node bugfix: use the correct version of node, even if PATH has a conflict
42     "$pkg_src"/bin/node "$pkg_src"/bin/npm config set scripts-prepend-node-path=true
43 }
44
45 function pkg_done_message() {
46     echo "Installed 'node' and 'npm' at $pkg_dst"
47 }