Éric Lemoine | c892804 | 2016-11-08 12:53:02 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ## Functions |
| 4 | |
| 5 | log_info() { |
| 6 | echo "[INFO] $*" |
| 7 | } |
| 8 | |
| 9 | log_err() { |
| 10 | echo "[ERROR] $*" >&2 |
| 11 | } |
| 12 | |
| 13 | _atexit() { |
| 14 | RETVAL=$? |
| 15 | trap true INT TERM EXIT |
| 16 | |
| 17 | if [ $RETVAL -ne 0 ]; then |
| 18 | log_err "Execution failed" |
| 19 | else |
| 20 | log_info "Execution successful" |
| 21 | fi |
| 22 | return $RETVAL |
| 23 | } |
| 24 | |
| 25 | ## Main |
| 26 | |
| 27 | [ -n "$DEBUG" ] && set -x |
| 28 | |
| 29 | LUA_VERSION=$(lua -v 2>&1) |
| 30 | if [[ $? -ne 0 ]]; then |
| 31 | log_err "No lua interpreter present" |
| 32 | exit $? |
| 33 | fi |
| 34 | if [[ ! $LUA_VERSION =~ [Lua\ 5\.1] ]]; then |
| 35 | log_err "Lua version 5.1 is required" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | lua5.1 -e "require('lpeg')" > /dev/null 2>&1 |
| 40 | if [[ $? -ne 0 ]]; then |
| 41 | log_err "lua-lpeg is required (run apt-get install lua-lpeg)" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | lua5.1 -e "require('cjson')" > /dev/null 2>&1 |
| 46 | if [[ $? -ne 0 ]]; then |
| 47 | log_err "lua-cjson is required (run apt-get install lua-cjson)" |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | for pgm in "cmake wget curl"; do |
| 52 | which $pgm > /dev/null 2>&1 |
| 53 | if [[ $? -ne 0 ]]; then |
| 54 | log_err "$pgm is required (run apt-get install $pgm)" |
| 55 | exit 1 |
| 56 | fi |
| 57 | done |
| 58 | |
| 59 | if [[ ! -f /usr/lib/x86_64-linux-gnu/liblua5.1.so ]]; then |
| 60 | log_err "package liblua5.1-0-dev is not installed (run apt-get install liblua5.1-0-dev)" |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | set -e |
| 65 | |
| 66 | curl -s -o lua/mocks/annotation.lua "https://raw.githubusercontent.com/mozilla-services/heka/versions/0.10/sandbox/lua/modules/annotation.lua" |
| 67 | curl -s -o lua/mocks/anomaly.lua "https://raw.githubusercontent.com/mozilla-services/heka/versions/0.10/sandbox/lua/modules/anomaly.lua" |
| 68 | curl -s -o lua/mocks/date_time.lua "https://raw.githubusercontent.com/mozilla-services/lua_sandbox/97331863d3e05d25131b786e3e9199e805b9b4ba/modules/date_time.lua" |
| 69 | curl -s -o lua/mocks/inspect.lua "https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua" |
| 70 | |
| 71 | CBUF_COMMIT="bb6dd9f88f148813315b5a660b7e2ba47f958b31" |
| 72 | CBUF_TARBALL_URL="https://github.com/mozilla-services/lua_circular_buffer/archive/${CBUF_COMMIT}.tar.gz" |
| 73 | CBUF_DIR="/tmp/lua_circular_buffer-${CBUF_COMMIT}" |
| 74 | CBUF_SO="${CBUF_DIR}/release/circular_buffer.so" |
| 75 | if [[ ! -f "${CBUF_SO}" ]]; then |
| 76 | rm -rf ${CBUF_DIR} |
| 77 | wget -qO - ${CBUF_TARBALL_URL} | tar -zxvf - -C /tmp |
| 78 | (cd ${CBUF_DIR} && mkdir release && cd release && cmake -DCMAKE_BUILD_TYPE=release .. && make) |
| 79 | cp ${CBUF_SO} ./ |
| 80 | fi |
| 81 | |
| 82 | for t in $(ls lua/test_*.lua); do |
| 83 | lua5.1 $t |
| 84 | done |
| 85 | |
| 86 | trap _atexit INT TERM EXIT |