Skip to content

Commit 4c0abf9

Browse files
committedApr 1, 2011
Initial commit
0 parents  commit 4c0abf9

File tree

3 files changed

+326
-0
lines changed

3 files changed

+326
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

‎README.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
kerl
2+
====
3+
4+
Easy building and installing of Erlang/OTP instances
5+
6+
Kerl aims to be shell agnostic and its only dependency, excluding what's required to actually build Erlang/OTP, is curl.
7+
8+
Downloading
9+
===========
10+
11+
You can download the script directly from github:
12+
13+
$ curl -O https://github.com/evax/kerl/raw/master/kerl
14+
$ chmod a+x kerl
15+
16+
How it works
17+
============
18+
19+
Kerl keeps tracks of the releases it downloaded, built and installed,
20+
allowing easy installations to new destinations (without complete rebuilding) and easy switches between Erlang/OTP installations.
21+
22+
Usage
23+
=====
24+
25+
List the available releases (kerl ignores releases < 10):
26+
27+
$ ./kerl list releases
28+
Getting the available releases from erlang.org...
29+
R10B-0 R10B-2 R10B-3 R10B-4 R10B-5 R10B-6 R10B-7 R10B-8 R10B-9 R11B-0 R11B-1 R11B-2 R11B-3 R11B-4 R11B-5 R12B-0 R12B-1 R12B-2 R12B-3 R12B-4 R12B-5 R13A R13B R13B01 R13B02 R13B03 R13B04 R14A R14B R14B01 R14B02 R14B01
30+
Run "./kerl update" to update this list from erlang.org
31+
32+
Pick your choice and build it:
33+
34+
$ ./kerl build R14B02
35+
Downloading otp_src_R14B02.tar.gz to /home/evax/.kerl/archives
36+
(curl progresses...)
37+
Verifying archive checksum...
38+
(curl progresses...)
39+
Checksum verified (229fb8f193b09ac04a57a9d7794349b7)
40+
Extracting source code
41+
Building Erlang/OTP R14B02, please wait...
42+
Erlang/OTP R14B02 has been successfully built
43+
44+
You can verify it's been registered:
45+
46+
$ ./kerl list builds
47+
R14B02
48+
49+
Now install it to some location:
50+
51+
$ kerl install R14B02 /path/to/install/dir/
52+
Installing Erlang/OTP R14B02 in /path/to/install/dir/
53+
You can activate this installation running the following command:
54+
. /path/to/install/dir/activate
55+
56+
Here again you can check the installation's been registered:
57+
58+
$ kerl list installations
59+
R14B02 /path/to/install/dir
60+
61+
And at last activate it:
62+
63+
$ . /path/to/install/dir/activate
64+
65+
You're now ready to work with R14B02
66+
67+
$ erl -version
68+
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 5.8.3
69+
70+
71+
Tuning
72+
======
73+
74+
You can tune kerl using the .kerlrc file in your $HOME directory.
75+
76+
You can set the following variables:
77+
KERL_DOWNLOAD_DIR: where to put downloaded files
78+
KERL_BUILD_DIR: where to hold the builds
79+
KERL_CONFIGURE_OPTIONS: options to pass to Erlang's ./configure script
80+
KERL_MAKE_OPTIONS: options to pass to make (e.g. -j2)
81+

‎kerl

+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
#! /bin/sh
2+
3+
# Copyright (c) 2011 Evax Software <contact(at)evax(dot)org>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
ERLANG_DOWNLOAD_URL=http://www.erlang.org/download
24+
25+
KERL_BASE_DIR=$HOME/.kerl
26+
KERL_CONFIG=$HOME/.kerlrc
27+
KERL_DOWNLOAD_DIR=$KERL_BASE_DIR/archives
28+
KERL_BUILD_DIR=$KERL_BASE_DIR/builds
29+
KERL_CONFIGURE_OPTIONS=
30+
KERL_MAKE_OPTIONS=
31+
32+
# source the config file if available
33+
if [ -f "$KERL_CONFIG" ]; then . "$KERL_CONFIG"; fi
34+
35+
usage() {
36+
echo "kerl: build and install Erlang/OTP"
37+
echo "usage: $0 <command> [options ...]"
38+
echo "\n <command> Command to be executed\n"
39+
echo "Valid commands are:"
40+
echo " build Build specified release"
41+
echo " install Install the specified release at the given location"
42+
echo " update Update the list of available releases from erlang.org"
43+
echo " list List releases, builds and installations"
44+
exit 1
45+
}
46+
47+
if [ $# -eq 0 ]; then usage; fi
48+
49+
get_releases() {
50+
curl -s $ERLANG_DOWNLOAD_URL/ | \
51+
sed -e 's/^.*>otp_src_\(R1[-1234567890ABCD]\+\)\.tar\.gz<.*$/\1/' \
52+
-e '/^R/!d'
53+
}
54+
55+
update_checksum_file() {
56+
echo "Getting the checksum file from erlang.org..."
57+
curl $ERLANG_DOWNLOAD_URL/MD5 > "$KERL_DOWNLOAD_DIR/MD5" || exit 1
58+
}
59+
60+
ensure_checksum_file() {
61+
if [ ! -f "$KERL_DOWNLOAD_DIR/MD5" ]; then
62+
update_checksum_file
63+
fi
64+
}
65+
66+
check_releases() {
67+
if [ ! -f "$KERL_BASE_DIR/otp_releases" ]; then
68+
echo "Getting the available releases from erlang.org..."
69+
get_releases > "$KERL_BASE_DIR/otp_releases"
70+
fi
71+
}
72+
73+
assert_valid_release() {
74+
check_releases
75+
for rel in `cat $KERL_BASE_DIR/otp_releases`; do
76+
if [ "$1" = "$rel" ]; then
77+
return 0
78+
fi
79+
done
80+
echo "$1 is not a valid Erlang/OTP release"
81+
exit 1
82+
}
83+
84+
do_build() {
85+
assert_valid_release $1
86+
FILENAME=otp_src_$1.tar.gz
87+
if [ ! -f "$KERL_DOWNLOAD_DIR/$FILENAME" ]; then
88+
echo "Downloading $FILENAME to $KERL_DOWNLOAD_DIR"
89+
mkdir -p "$KERL_DOWNLOAD_DIR"
90+
curl $ERLANG_DOWNLOAD_URL/$FILENAME > "$KERL_DOWNLOAD_DIR/$FILENAME"
91+
update_checksum_file
92+
fi
93+
ensure_checksum_file
94+
echo "Verifying archive checksum..."
95+
SUM=`md5sum $KERL_DOWNLOAD_DIR/$FILENAME | cut -d " " -f 1`
96+
ORIG_SUM=`grep $FILENAME $KERL_DOWNLOAD_DIR/MD5 | cut -d " " -f 2`
97+
if [ "$SUM" != "$ORIG_SUM" ]; then
98+
echo "Checksum error, check the files in $KERL_DOWNLOAD_DIR"
99+
exit 1
100+
fi
101+
echo "Checksum verified ($SUM)"
102+
mkdir -p $KERL_BUILD_DIR
103+
mkdir -p $KERL_BASE_DIR/logs
104+
if [ ! -d $KERL_BUILD_DIR/otp_src_$1 ]; then
105+
echo "Extracting source code"
106+
cd $KERL_BUILD_DIR && tar xfz $KERL_DOWNLOAD_DIR/$FILENAME
107+
fi
108+
echo "Building Erlang/OTP $1, please wait..."
109+
cd $KERL_BUILD_DIR/otp_src_$1
110+
./configure $KERL_CONFIGURE_OPTIONS > \
111+
$KERL_BASE_DIR/logs/configure_$1.log 2>&1
112+
if [ "$?" -eq 1 ]; then
113+
echo "./configure failed";
114+
exit 1
115+
fi
116+
rm -f "$KERL_BASE_DIR/logs/configure_$1.log"
117+
make $KERL_MAKE_OPTIONS > $KERL_BASE_DIR/logs/build_$1.log 2>&1
118+
if [ "$?" -eq 1 ]; then
119+
echo "Build failed, see $KERL_BASE_DIR/logs/build_$1.log";
120+
list_remove builds $2
121+
fi
122+
rm -f "$KERL_BASE_DIR/logs/build_$1.log"
123+
echo "Erlang/OTP $1 has been successfully built";
124+
list_add builds $1
125+
}
126+
127+
do_install() {
128+
assert_valid_release $1
129+
if ! list_has builds $1; then
130+
echo "You must build the $1 realease before installing it"
131+
exit 1
132+
fi
133+
mkdir -p "$2"
134+
if [ ! -d "$2" ]; then
135+
echo "Destination is not a directory"
136+
exit 1
137+
fi
138+
absdir=`cd "$2" && pwd`
139+
echo "Installing Erlang/OTP $1 in $absdir"
140+
cd $KERL_BUILD_DIR/otp_src_$1
141+
./configure --prefix="$absdir" > /dev/null 2>&1
142+
make install > /dev/null 2>&1
143+
if [ $? -eq 1 ]; then
144+
echo "Couldn't install Erlang/OTP $1 in $absdir"
145+
exit 1
146+
fi
147+
list_add installations "$1 $absdir";
148+
echo "export PATH=$absdir/bin:\$PATH" > $absdir/activate
149+
echo "You can activate this installation running the following command:"
150+
echo ". $absdir/activate"
151+
}
152+
153+
list_print() {
154+
if [ -f $KERL_BASE_DIR/otp_$1 ]; then
155+
if [ -z "$2" ]; then
156+
cat $KERL_BASE_DIR/otp_$1
157+
else
158+
echo `cat $KERL_BASE_DIR/otp_$1`
159+
fi
160+
else
161+
echo "There are no $1 available"
162+
fi
163+
}
164+
165+
list_add() {
166+
if [ -f $KERL_BASE_DIR/otp_$1 ]; then
167+
grep $2 $KERL_BASE_DIR/otp_$1 > /dev/null 2>&1 || \
168+
echo $2 >> $KERL_BASE_DIR/otp_$1
169+
else
170+
echo $2 > $KERL_BASE_DIR/otp_$1
171+
fi
172+
}
173+
174+
list_remove() {
175+
if [ -f $KERL_BASE_DIR/otp_$1 ]; then
176+
sed -i -e '/$2/d' $KERL_BASE_DIR/otp_$1
177+
fi
178+
}
179+
180+
list_has() {
181+
if [ -f $KERL_BASE_DIR/otp_$1 ]; then
182+
grep $2 $KERL_BASE_DIR/otp_$1 > /dev/null 2>&1 && return 0
183+
fi
184+
return 1
185+
}
186+
187+
list_usage() {
188+
echo "usage: $0 list <releases|builds|installations>"
189+
}
190+
191+
case "$1" in
192+
build)
193+
if [ $# -ne 2 ]; then
194+
echo "specify a release to install (e.g. R14B02)"
195+
exit 1
196+
fi
197+
do_build $2
198+
;;
199+
install)
200+
if [ $# -lt 2 ]; then
201+
echo "usage: $0 $1 <release> [directory]"
202+
exit 1
203+
fi
204+
if [ $# -eq 3 ]; then
205+
do_install $2 $3
206+
else
207+
do_install $2 .
208+
fi
209+
;;
210+
update)
211+
rm -f $KERL_BASE_DIR/otp_releases
212+
check_releases
213+
echo "The available releases are:"
214+
list_print releases spaces
215+
;;
216+
list)
217+
if [ $# -ne 2 ]; then
218+
list_usage
219+
exit 1
220+
fi
221+
case "$2" in
222+
releases)
223+
check_releases
224+
list_print $2 space
225+
echo "Run \"$0 update\" to update this list from erlang.org"
226+
;;
227+
builds)
228+
list_print $2
229+
;;
230+
installations)
231+
list_print $2
232+
;;
233+
*)
234+
echo "Cannot list $2"
235+
list_usage
236+
exit 1
237+
;;
238+
esac
239+
;;
240+
*)
241+
echo "unkwnown command: $1"; usage; exit 1
242+
;;
243+
esac
244+

0 commit comments

Comments
 (0)
Please sign in to comment.