Commit 7d73caa0 authored by Julien Muchembled's avatar Julien Muchembled

Optimize wrapper to scripts with long shebangs

parent 339b320e
...@@ -409,16 +409,18 @@ class Recipe(object): ...@@ -409,16 +409,18 @@ class Recipe(object):
continue continue
for f in os.listdir(dir_abspath): for f in os.listdir(dir_abspath):
f_abspath = os.path.join(dir_abspath, f) f_abspath = os.path.join(dir_abspath, f)
if not os.path.isfile(f_abspath): st_mode = os.stat(f_abspath).st_mode
if not stat.S_ISREG(st_mode):
continue continue
header = file(f_abspath).readline(128) with open(f_abspath) as f:
m = re.match('^#! ?(/.*)', header) header = f.readline(128)
if not m or len(header) < 128: if header.startswith('#!') and header[-1] != '\n':
continue os.rename(f_abspath, f_abspath + '.shebang')
shebang_abspath = f_abspath + '.shebang' with open(f_abspath, 'w') as f:
os.rename(f_abspath, shebang_abspath) os.fchmod(f.fileno(), stat.S_IMODE(st_mode))
file(f_abspath, 'w').write('''#!/bin/sh f.write('''#!/bin/sh -e
shebang=$(head -1 "$0.shebang") read -r EXE ARG < "$0.shebang"
exec ${shebang#\#!} "$0.shebang" "$@" EXE=${EXE#\\#!}
[ "$EXE" ] || read -r _ EXE ARG < "$0.shebang"
exec $EXE ${ARG:+"$ARG"} "$0.shebang" "$@"
''') ''')
os.chmod(f_abspath, stat.S_IMODE(os.stat(shebang_abspath).st_mode))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment