File: lua-any

package info (click to toggle)
dh-lua 35
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228 kB
  • sloc: ansic: 110; perl: 93; sh: 57; makefile: 56
file content (50 lines) | stat: -rwxr-xr-x 1,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
# This scripts enables shebang lines like
#
#   #!/usr/bin/env lua-any
#   -- Lua-Versions: 5.1 5.4
#   -- Lua-Root: /usr/bin/lua
#   -- Lua-Args: -l foo
#
# That will pick the first installed interpreter among /usr/bin/lua5.1 and
# /usr/bin/lua5.4 and pass to if '-l foo' as well ass the name of the script
# containing the shebang and the extra arguments
# 
# License: MIT/X
# Copyright: 2015 Enrico Tassi <gareuselesinge@debian.org>

#set -x
set -e

FILE="$1"

if [ -z "$FILE" ]; then
	echo "Error: lua-any needs at least one argument"
	exit 1
fi

VERSIONS="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Versions[[:space:]]*:' \
	| cut -d : -f 2- \
	| sed 's/^[[:space:]]*//' \
	| sed 's/[[:space:]]*$//' `"
ROOT="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Root[[:space:]]*:' \
	| cut -d : -f 2- \
	| sed 's/^[[:space:]]*//' \
	| sed 's/[[:space:]]*$//' `"
ARGS="`head "$FILE" | grep -i '^--[[:space:]]*Lua-Args[[:space:]]*:' \
	| cut -d : -f 2- \
	| sed 's/^[[:space:]]*//' \
	| sed 's/[[:space:]]*$//' `"

if [ -z "$ROOT" ]; then ROOT=/usr/bin/lua; fi

for v in $VERSIONS; do
	if [ -x "$ROOT$v" ]; then
		exec $ROOT$v $ARGS "$@"
	fi
done

echo "Error: no suitable Lua interpreter found"
echo "Error: supported versions are: $VERSIONS"
exit 1