-
Notifications
You must be signed in to change notification settings - Fork 2
/
npm_scripts.sh
executable file
·99 lines (97 loc) · 3.3 KB
/
npm_scripts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
postinstall() {(set -e
# this function will run npm postinstall
export PATH="$(pwd):$PATH"
# install elasticsearch
VERSION=1.7.6
FILE_BASE="elasticsearch-$VERSION.tar.gz"
FILE_URL="https://download.elastic.co/elasticsearch/elasticsearch/$FILE_BASE"
# init external/elasticsearch/bin/elasticsearch
mkdir -p external/elasticsearch/bin && rm -f external/elasticsearch/bin/elasticsearch
for DIR in /bin /usr/bin /usr/local/bin
do
if ("$DIR/elasticsearch" -v 2>/dev/null | grep -q "$VERSION")
then
ln -fs "$DIR/elasticsearch" external/elasticsearch/bin/elasticsearch
break
fi
done
if [ ! -f external/elasticsearch/bin/elasticsearch ]
then
# install file
if [ ! -f "/tmp/$FILE_BASE" ]
then
FILE_TMP="$(mktemp "/tmp/$FILE_BASE.XXXXXXXX")"
# copy cached file
if [ -f "/$FILE_BASE" ]
then
cp "/$FILE_BASE" "$FILE_TMP"
# download file
else
printf "downloading $FILE_URL to /tmp/$FILE_BASE ...\n"
curl -#Lo "$FILE_TMP" "$FILE_URL"
fi
chmod 644 "$FILE_TMP"
# mv file to prevent race-condition
mv "$FILE_TMP" "/tmp/$FILE_BASE" 2>/dev/null || true
fi
# untar file
tar --strip-components=1 -C external/elasticsearch -xzf /tmp/$FILE_BASE
fi
# install kibana
VERSION=3.1.3
FILE_BASE="kibana-$VERSION.tar.gz"
FILE_URL="https://download.elastic.co/kibana/kibana/$FILE_BASE"
# init external/kibana/index.html
mkdir -p external/kibana
if [ ! -f external/kibana/index.html ]
then
if [ ! -f "/tmp/$FILE_BASE" ]
then
FILE_TMP="$(mktemp "/tmp/$FILE_BASE.XXXXXXXX")"
# copy cached file
if [ -f "/$FILE_BASE" ]
then
cp "/$FILE_BASE" "$FILE_TMP"
# download file
else
printf "downloading $FILE_URL to /tmp/$FILE_BASE ...\n"
curl -#Lo "$FILE_TMP" "$FILE_URL"
fi
chmod 644 "$FILE_TMP"
# mv file to prevent race-condition
mv "$FILE_TMP" "/tmp/$FILE_BASE" 2>/dev/null || true
fi
# untar file
tar --strip-components=1 -C external/kibana -xzf /tmp/$FILE_BASE
fi
# install logstash
VERSION=2.4.1
FILE_BASE="logstash-$VERSION.tar.gz"
FILE_URL="https://download.elastic.co/logstash/logstash/$FILE_BASE"
# init external/logstash/index.html
mkdir -p external/logstash
if [ ! -f external/logstash/index.html ]
then
if [ ! -f "/tmp/$FILE_BASE" ]
then
FILE_TMP="$(mktemp "/tmp/$FILE_BASE.XXXXXXXX")"
# copy cached file
if [ -f "/$FILE_BASE" ]
then
cp "/$FILE_BASE" "$FILE_TMP"
# download file
else
printf "downloading $FILE_URL to /tmp/$FILE_BASE ...\n"
curl -#Lo "$FILE_TMP" "$FILE_URL"
fi
chmod 644 "$FILE_TMP"
# mv file to prevent race-condition
mv "$FILE_TMP" "/tmp/$FILE_BASE" 2>/dev/null || true
fi
# untar file
tar --strip-components=1 -C external/logstash -xzf /tmp/$FILE_BASE
fi
)}
# run command
"$@"