blob: fe448b96650e96226f467360d1315e1370960d08 [file] [log] [blame]
Christopher Piro094823a2007-07-18 00:26:12 +00001#!/bin/sh
2
3# erlwareSys: otp/build/beamver,v 1.1 2002/02/14 11:45:20 hal Exp $
4
5# usage: beamver <beam_file>
6#
7# if there's a usable -vsn() attribute, print it and exit with status 0
8# otherwise, print nothing and exit with status 1
9
10# From the Erlang shell:
11#
12# 5> code:which(acca_inets).
13# "/home/martin/work/otp/releases/<app>/../../acca/ebin/<app>.beam"
14#
15# 8> beam_lib:version(code:which(<app>)).
16# {ok,{<app>,['$Id: beamver,v 1.1.1.1 2003/06/13 21:43:21 mlogan Exp $ ']}}
17
18# TMPFILE looks like this:
19#
20# io:format("hello ~p~n",
21# beam_lib:version("/home/hal/work/otp/acca/ebin/acca_inets.beam")]).
22
23TMPFILE=/tmp/beamver.$$
24
25# exit with failure if we can't read the file
26test -f "$1" || exit 1
27BEAMFILE=\"$1\"
28
29cat > $TMPFILE <<_EOF
30io:format("~p~n",
31 [beam_lib:version($BEAMFILE)]).
32_EOF
33
34# beam_result is {ok,{Module_name, Beam_version} or {error,beam_lib,{Reason}}
35beam_result=`erl -noshell \
36 -s file eval $TMPFILE \
37 -s erlang halt`
38
39rm -f $TMPFILE
40
41# sed regexes:
42# remove brackets and anything outside them
43# remove quotes and anything outside them
44# remove apostrophes and anything outside them
45# remove leading and trailing spaces
46
47case $beam_result in
48\{ok*)
49 echo $beam_result | sed -e 's/.*\[\(.*\)].*/\1/' \
50 -e 's/.*\"\(.*\)\".*/\1/' \
51 -e "s/.*\'\(.*\)\'.*/\1/" \
52 -e 's/ *$//' -e 's/^ *//'
53 exit 0
54 ;;
55*)
56 exit 1
57 ;;
58esac
59