Commit cceefef5 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Create a wrapper shell script for very long shebang scripts.

parent 2304e1f2
......@@ -8,6 +8,7 @@ import pkg_resources
from platform import machine as platform_machine
import re
import shutil
import stat
import subprocess
import sys
import zc.buildout
......@@ -395,4 +396,29 @@ class Recipe(object):
if self.options['share'] == '':
parts.append(self.options['default-location'])
self.fix_shebang(self.options['default-location'])
return parts
def fix_shebang(self, location):
# Workaround for shebang line limit by renaming the script and
# putting a wrapper shell script.
for dir in ('bin', 'sbin'):
dir_abspath = os.path.join(location, dir)
if not os.path.isdir(dir_abspath):
continue
for f in os.listdir(dir_abspath):
f_abspath = os.path.join(dir_abspath, f)
if not os.path.isfile(f_abspath):
continue
header = file(f_abspath).readline(128)
m = re.match('^#! ?(/.*)', header)
if not m or len(header) < 128:
continue
shebang_abspath = f_abspath + '.shebang'
os.rename(f_abspath, shebang_abspath)
file(f_abspath, 'w').write('''#!/bin/sh
shebang=$(head -1 "$0.shebang")
exec ${shebang#\#!} "$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