Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 175 lines (154 sloc) 6.573 kb
a4511e3 @squiffy Fixed scripts to have more universal compatibility
squiffy authored
1 #!/usr/bin/env bash
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
2 #
ccdea50 Easier way to build
Caleb James DeLisle authored
3 # You may redistribute this program and/or modify it under the terms of
4 # the GNU General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
14 #
15
16 [[ -n "$PLATFORM" ]] \
17 || PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
18
19 [[ -n "$MARCH" ]] \
20 || MARCH=$(uname -m | sed 's/i./x/g')
ccdea50 Easier way to build
Caleb James DeLisle authored
21
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
22 build_dir="build_$PLATFORM"
23 node_min_ver='v0.8.15'
24 node_dl_ver='v0.10.24'
ccdea50 Easier way to build
Caleb James DeLisle authored
25
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
26 read -d '' version_test <<"EOF"
7599f59 Merge versionTest.js into ./do
Caleb James DeLisle authored
27 var currentVersion = process.version;
28 var verArray = currentVersion.substring(1).split(".");
29 var minVerArray = process.argv[process.argv.length-1].substring(1).split(".");
30 for (var i = 0; i < minVerArray.length; i++) {
31 if (Number(verArray[i]) < Number(minVerArray[i])) {
32 process.exit(1);
33 } else if (Number(verArray[i]) > Number(minVerArray[i])) {
34 process.exit(0);
35 }
36 }
37 EOF
38
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
39 # return true if the input command exists in $PATH
40 function cmd_exists() {
41 type -P "$1" >/dev/null
42 }
43
44 # output an error and exit with a failed status
45 function die() {
46 printf '%s\n' "ERROR: $1" >&2
47 exit 1
48 }
49
50 # detect and configure a copy of node.js to use with at least the minimum version
51 function check_node_tool() {
52 for node_tool in "$build_dir/nodejs/node/bin/node" 'nodejs' 'node'; do
53 cmd_exists "$node_tool"
54 if [ $? = 0 -o -f "$node_tool" ]; then
55 "$node_tool" '' "$node_min_ver" <<< "$version_test" && {
56 node_cmd="$node_tool"
57 return 0
58 }
59 printf '%s\n' "You have a version of node [$node_tool] but it is too old [$($node_tool -v)]"
5cfa192 @Shnatsel Made node.js detection in ./do more robust and readable
Shnatsel authored
60 fi
61 done
4292557 Upgraded ./do to download node.js if necessary
Caleb James DeLisle authored
62 return 1
63 }
64
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
65 # detect and configure a sha256sum implementation to use that produces the expected sum for an empty string
66 function get_shasum_tool() {
67 expected_sum='01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
68 for shasum_tool in 'sha256sum' 'gsha256sum' 'sha256' 'shasum -a 256' 'openssl sha256'; do
69 if cmd_exists "${shasum_tool/ *}"; then
70 [[ $($shasum_tool <<< '') =~ "$expected_sum" ]] && {
71 shasum_cmd="$shasum_tool"
72 return 0
73 }
74 fi
75 done
76 return 1
77 }
4292557 Upgraded ./do to download node.js if necessary
Caleb James DeLisle authored
78
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
79 # download and configure a copy of node.js to use based on the current system
80 function get_node_tool() {
81 printf '%s %s\n\n' '###' "Installing node.js (you can bypass this step by manually installing node.js $node_min_ver or newer)"
82 case "$PLATFORM-$MARCH" in
83 linux-x86_64)
84 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-linux-x64.tar.gz"
85 node_sha='6ef93f4a5b53cdd4471786dfc488ba9977cb3944285ed233f70c508b50f0cb5f'
86 ;;
87 linux-x86)
88 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-linux-x86.tar.gz"
89 node_sha='fb6487e72d953451d55e28319c446151c1812ed21919168b82ab1664088ecf46'
90 ;;
91 linux-armv6l|linux-armv7l)
92 # Raspberry Pi or Cubieboard
93 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-linux-arm-pi.tar.gz"
94 node_sha='bdd5e253132c363492fa24ed9985873733a10558240fd45b0a4a15989ab8da90'
95 ;;
96 darwin-x86_64)
97 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-darwin-x64.tar.gz"
98 node_sha='c1c523014124a0327d71ba5d6f737a4c866a170f1749f8895482c5fa8be877b0'
99 ;;
100 darwin-x86)
101 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-darwin-x86.tar.gz"
102 node_sha='8b8d2bf9828804c3f8027d7d442713318814a36df12dea97dceda8f4aff42b3c'
103 ;;
104 sunos-x86_64)
105 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-sunos-x64.tar.gz"
106 node_sha='7cb714df92055b93a908b3b6587ca388a2884b1a9b5247c708a867516994a373'
107 ;;
108 sunos-x86)
109 node_download="http://nodejs.org/dist/$node_dl_ver/node-$node_dl_ver-sunos-x86.tar.gz"
110 node_sha='af69ab26aae42b05841c098f5d11d17e21d22d980cd32666e2db45a53ddffe34'
111 ;;
112 *)
113 printf '%s\n%s\n' \
114 "No nodejs executable available for $PLATFORM-$MARCH" \
115 "Please install nodejs (>= $node_min_ver) from your distribution package repository or from source"
116 return 1
117 ;;
118 esac
4292557 Upgraded ./do to download node.js if necessary
Caleb James DeLisle authored
119
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
120 [[ -d "$build_dir/nodejs" ]] \
121 && rm -r "$build_dir/nodejs"
122 install -d "$build_dir/nodejs"
123
124 pushd "$build_dir/nodejs" >/dev/null
125 node_dl="node-${node_dl_ver}.tar.gz"
126 if cmd_exists wget; then
127 printf '\n%s %s ' '==>' "Downloading $node_download with wget..."
128 wget -q "$node_download" -O "$node_dl"
129 elif cmd_exists curl; then
130 printf '%s %s ' '==>' "Downloading $node_download with curl..."
131 curl -s "$node_download" > "$node_dl"
b24eb33 @cjdelisle merged new ./do and copied old ./do to ./old_do which will be removed…
authored
132 elif cmd_exists fetch; then
133 printf '%s %s ' '==>' "Downloading $node_download with fetch..."
134 fetch "$node_download" -o "$node_dl"
b0d6ce0 @Shnatsel Simplify ./do by replacing some fragile dark magic with more portable…
Shnatsel authored
135 else
b24eb33 @cjdelisle merged new ./do and copied old ./do to ./old_do which will be removed…
authored
136 die 'wget, curl or fetch is required download node.js but you have none!'
b0d6ce0 @Shnatsel Simplify ./do by replacing some fragile dark magic with more portable…
Shnatsel authored
137 fi
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
138 [[ -f "$node_dl" ]] \
139 || die 'Failed to download node.js'
140 printf '%s\n' 'DONE!'
4292557 Upgraded ./do to download node.js if necessary
Caleb James DeLisle authored
141
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
142 printf '%s %s ' '==>' "Verifying the checksum of the downloaded archive..."
143 [[ $($shasum_cmd "$node_dl") =~ $node_sha ]] \
144 || die 'The downloaded file is damaged! Aborting'
145 printf '%s\n' 'DONE!'
4292557 Upgraded ./do to download node.js if necessary
Caleb James DeLisle authored
146
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
147 printf '%s %s ' '==>' "Extracting the downloaded archive..."
148 install -d node
149 tar xzf "$node_dl" -C node --strip-components=1
150 [[ -d 'node' ]] \
151 || die 'An error prevented the archive from being extracted'
152 printf '%s\n\n' 'DONE!'
153 popd >/dev/null
bab2f96 Reverted d8c0ec4c559acf7dd4a703ce60bd1aad0daeca97 because it broke Ap…
Caleb James DeLisle authored
154
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
155 # Return with the success status of the check_node_tool function
156 check_node_tool
eaa4c72 beating the toolchain with a stick
Caleb James DeLisle authored
157 }
158
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
159 cd "$(dirname $0)" \
160 || die 'failed to set directory'
d8c0ec4 @grawity Clean up the bash scripts
grawity authored
161
0951ce0 @prurigro Refactor 'do' with more compliant bash that relies less on external c…
prurigro authored
162 [[ -d "$build_dir" ]] \
163 || install -d "$build_dir" \
164 || die "failed to create build dir $build_dir"
165
166 get_shasum_tool \
167 || die "couldn't find working sha256 shasum_tool";
168
169 check_node_tool \
170 || get_node_tool \
171 || die "couldn't get working node.js implementation";
172
173 "$node_cmd" ./node_build/make.js "$@"
ccdea50 Easier way to build
Caleb James DeLisle authored
174
Something went wrong with that request. Please try again.