Browse Source

Utils for installing nodejs

Bob Mottram 8 years ago
parent
commit
7120990b26
1 changed files with 107 additions and 0 deletions
  1. 107
    0
      src/freedombone-utils-nodejs

+ 107
- 0
src/freedombone-utils-nodejs View File

@@ -0,0 +1,107 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# nodejs functions
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+# For reasons unknown we initially have to upgrade to an intermediate version
32
+# before getting to the version we want
33
+
34
+VARIANTS='mesh'
35
+
36
+NODEJS_VERSION='6.2.2'
37
+NODEJS_N_VERSION='2.1.4'
38
+
39
+function mesh_install_nodejs {
40
+    chroot "${rootdir}" apt-get -y install nodejs
41
+    chroot "${rootdir}" apt-get -y install npm curl
42
+
43
+    if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
44
+        echo $'nodejs was not installed'
45
+        exit 63962
46
+    fi
47
+
48
+    cat <<EOF > ${rootdir}/root/install-nodejs.sh
49
+#!/bin/bash
50
+PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
51
+NODE_PATH="/usr/lib/node_modules"
52
+cp /usr/bin/nodejs /usr/local/bin/node
53
+cp /usr/bin/nodejs /usr/bin/node
54
+/usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
55
+npm install -g n@${NODEJS_N_VERSION} --save
56
+n ${NODEJS_VERSION}
57
+exit 0
58
+EOF
59
+    chroot "${rootdir}" chmod +x /root/install-nodejs.sh
60
+    chroot "${rootdir}" /root/install-nodejs.sh
61
+    if [ ! "$?" = "0" ]; then
62
+        chroot "${rootdir}" rm -f /root/install-nodejs.sh
63
+        exit 7632572
64
+    fi
65
+    chroot "${rootdir}" rm -f /root/install-nodejs.sh
66
+}
67
+
68
+function install_nodejs {
69
+    if [ $INSTALLING_MESH ]; then
70
+        mesh_install_nodejs
71
+        return
72
+    fi
73
+    if grep -Fxq "install_nodejs" $COMPLETION_FILE; then
74
+        return
75
+    fi
76
+
77
+    apt-get -y install nodejs
78
+    apt-get -y install npm curl
79
+
80
+    if [ ! -f /usr/bin/nodejs ]; then
81
+        echo $'nodejs was not installed'
82
+        exit 63962
83
+    fi
84
+
85
+    cat <<EOF > /root/install-nodejs.sh
86
+#!/bin/bash
87
+PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
88
+NODE_PATH="/usr/lib/node_modules"
89
+cp /usr/bin/nodejs /usr/local/bin/node
90
+cp /usr/bin/nodejs /usr/bin/node
91
+/usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
92
+npm install -g n@${NODEJS_N_VERSION} --save
93
+n ${NODEJS_VERSION}
94
+exit 0
95
+EOF
96
+    chmod +x /root/install-nodejs.sh
97
+    /root/install-nodejs.sh
98
+    if [ ! "$?" = "0" ]; then
99
+        rm -f /root/install-nodejs.sh
100
+        exit 7632572
101
+    fi
102
+    rm -f /root/install-nodejs.sh
103
+
104
+    echo 'install_nodejs' >> $COMPLETION_FILE
105
+}
106
+
107
+# NOTE: deliberately there is no "exit 0"