| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# This scripts enables shebang lines like |
| 4 |
# |
| 5 |
# #!/usr/bin/env lua-any |
| 6 |
# -- Lua-Versions: 5.1 5.4 |
| 7 |
# -- Lua-Root: /usr/bin/lua |
| 8 |
# -- Lua-Args: -l foo |
| 9 |
# |
| 10 |
# That will pick the first installed interpreter among /usr/bin/lua5.1 and |
| 11 |
# /usr/bin/lua5.4 and pass to if '-l foo' as well ass the name of the script |
| 12 |
# containing the shebang and the extra arguments |
| 13 |
# |
| 14 |
# License: MIT/X |
| 15 |
# Copyright: 2015 Enrico Tassi <[email protected]> |
| 16 |
|
| 17 |
#set -x |
| 18 |
set -e |
| 19 |
|
| 20 |
FILE="$1" |
| 21 |
|
| 22 |
if [ -z "$FILE" ]; then |
| 23 |
echo "Error: lua-any needs at least one argument" |
| 24 |
exit 1 |
| 25 |
fi |
| 26 |
|
| 27 |
VERSIONS="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Versions[[:space:]]*:' \ |
| 28 |
| cut -d : -f 2- \ |
| 29 |
| sed 's/^[[:space:]]*//' \ |
| 30 |
| sed 's/[[:space:]]*$//' `" |
| 31 |
ROOT="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Root[[:space:]]*:' \ |
| 32 |
| cut -d : -f 2- \ |
| 33 |
| sed 's/^[[:space:]]*//' \ |
| 34 |
| sed 's/[[:space:]]*$//' `" |
| 35 |
ARGS="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Args[[:space:]]*:' \ |
| 36 |
| cut -d : -f 2- \ |
| 37 |
| sed 's/^[[:space:]]*//' \ |
| 38 |
| sed 's/[[:space:]]*$//' `" |
| 39 |
|
| 40 |
if [ -z "$ROOT" ]; then ROOT=/usr/bin/lua; fi |
| 41 |
|
| 42 |
for v in $VERSIONS; do |
| 43 |
if [ -x "$ROOT$v" ]; then |
| 44 |
exec $ROOT$v $ARGS "$@" |
| 45 |
fi |
| 46 |
done |
| 47 |
|
| 48 |
echo "Error: no suitable Lua interpreter found" |
| 49 |
echo "Error: supported versions are: $VERSIONS" |
| 50 |
exit 1 |