forked from pib/lockerbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lockerbox.sh
executable file
·186 lines (163 loc) · 4.73 KB
/
lockerbox.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
#### Config
NODE_DOWNLOAD='http://nodejs.org/dist/node-v0.4.8.tar.gz'
NPM_DOWNLOAD='http://npmjs.org/install.sh'
VIRTUALENV_DOWNLOAD='http://github.com/pypa/virtualenv/raw/develop/virtualenv.py'
MONGODB_DOWNLOAD='http://fastdl.mongodb.org/OS/mongodb-OS-ARCH-1.8.1.tgz'
LOCKERBOX_DOWNLOAD='https://raw.github.com/pib/lockerbox/master/lockerbox.sh'
LOCKER_REPO='https://github.com/LockerProject/Locker.git'
LOCKER_BRANCH='master'
#### Helper functions
# check_for name exec_name version_command [minimum_version [optional]]
function check_for {
found=`which $2`
version=`$3 2>&1 | grep -o -E [-0-9.]\{1,\} | head -n 1`
if [ -z "$found" ]; then
echo "$1 not found!" >&2
else
echo "$1 version $version found." >&2
if [ -z "$4" ]; then
return
fi
fi
if [ -n "$4" ]; then
if [ "$version" \< "$4" ]; then
echo "$1 version $4 or greater required!" >&2
if [ -z "$5" ]; then
exit 1
else
false
fi
fi
else
exit 1
fi
}
function download {
base=`basename $1`
if [ -f $base ]; then
echo "$1 already downloaded." >&2
else
if wget "$1" 2>/dev/null || curl -L -o $base "$1"; then
echo "Downloaded $1." >&2
else
echo "Download of $1 failed!" >&2
exit 1
fi
fi
}
#### Main script
BASEDIR=`pwd`
THIS=`basename $0`
if [[ $BASEDIR != */lockerbox ]]; then
BASEDIR=$BASEDIR/lockerbox
mkdir -p "$BASEDIR/lockerbox"
cd $BASEDIR
fi
export PYEXE=`which python`
export PRE_LOCKERBOX_PATH=$PATH
export PATH="$BASEDIR/local/bin":$PATH
export PRE_LOCKERBOX_NODE_PATH=$NODE_PATH
export NODE_PATH="$BASEDIR/local/lib/node_modules":$NODE_PATH
check_for Git git 'git --version'
check_for Python python 'python -V' 2.6
mkdir -p local/build
cd local/build
check_for Node.js node 'node -v' 0.4.6 optional
if [ $? -ne 0 ]; then
echo "" >&2
echo "About to download, build, and install locally node.js." >&2
echo -n "This could take a while." >&2
sleep 1; echo -n .; sleep 1; echo -n .; sleep 1; echo -n .; sleep 1
download "$NODE_DOWNLOAD"
if tar zxf "`basename \"$NODE_DOWNLOAD\"`" &&
cd `basename "$NODE_DOWNLOAD" .tar.gz` &&
./configure --prefix="$BASEDIR/local" &&
make &&
make install
then
echo "Installed node.js into $BASEDIR" >&2
else
echo "Failed to install node.js into $BASEDIR" >&2
exit 1
fi
fi
cd "$BASEDIR/local/build"
check_for npm npm "npm -v" 1 optional
if [ $? -ne 0 ]; then
echo "" >&2
echo "About to download and install locally npm." >&2
download "$NPM_DOWNLOAD"
if cat `basename $NPM_DOWNLOAD` | clean=no sh; then
echo "Installed npm into $BASEDIR" >&2
else
echo "Failed to install npm into $BASEDIR" >&2
exit 1
fi
fi
if ! find "$BASEDIR/local/bin/activate" >/dev/null 2>&1; then
check_for virtualenv virtualenv "virtualenv --version" 1.4 optional
if [ $? -ne 0 ]; then
echo "" >&2
echo "About to download virtualenv.py." >&2
download "$VIRTUALENV_DOWNLOAD"
fi
if $PYEXE -m virtualenv --no-site-packages "$BASEDIR/local"; then
echo "Set up virtual Python environment." >&2
else
echo "Failed to set up virtual Python environment." >&2
fi
fi
if source "$BASEDIR/local/bin/activate"; then
echo "Activated virtual Python environment." >&2
else
echo "Failed to activate virtual Python environment." >&2
fi
check_for mongoDB mongod "mongod --version" 1.4.0 optional
if [ $? -ne 0 ]; then
OS=`uname -s`
case $OS in
Linux)
OS=linux
;;
Darwin)
OS=osx
;;
*)
echo "Don't recognize OS $OS" >&2
exit 1
esac
BITS=`getconf LONG_BIT`
ARCH='x86_64'
if [ $BITS -ne 64 ]; then
ARCH="i386"
if [ "$OS" != "osx" ]; then
ARCH="i686"
fi
fi
echo "" >&2
echo "Downloading and installing locally mongoDB" >&2
MONGODB_DOWNLOAD=`echo $MONGODB_DOWNLOAD | sed -e "s/OS/$OS/g" -e "s/ARCH/$ARCH/g"`
download $MONGODB_DOWNLOAD
if tar zxf `basename "$MONGODB_DOWNLOAD"` &&
cp `basename "$MONGODB_DOWNLOAD" .tgz`/bin/* "$BASEDIR/local/bin"
then
echo "Installed local mongoDB." >&2
else
echo "Failed to install local mongoDB." >&2
exit 1
fi
fi
cd "$BASEDIR"
if [ ! -d Locker/.git ]; then
echo "Checking out Locker repo." >&2
if git clone "$LOCKER_REPO" -b "$LOCKER_BRANCH"; then
echo "Checked out Locker repo." >&2
else
echo "Failed to check out Locker repo." >&2
exit 1
fi
fi
cd Locker
npm install
python setupEnv.py