Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 1 | #!/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 | |
| 23 | TMPFILE=/tmp/beamver.$$ |
| 24 | |
| 25 | # exit with failure if we can't read the file |
| 26 | test -f "$1" || exit 1 |
| 27 | BEAMFILE=\"$1\" |
| 28 | |
| 29 | cat > $TMPFILE <<_EOF |
| 30 | io: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}} |
| 35 | beam_result=`erl -noshell \ |
| 36 | -s file eval $TMPFILE \ |
| 37 | -s erlang halt` |
| 38 | |
| 39 | rm -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 | |
| 47 | case $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 | ;; |
| 58 | esac |
| 59 | |