Install python script, adjusting the shebang

This commit is contained in:
Peter J. Holzer 2021-04-01 15:05:27 +02:00 committed by Peter J. Holzer
commit 7de842141d
1 changed files with 24 additions and 0 deletions

24
install-python Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import argparse
import shutil
import sys
ap = argparse.ArgumentParser()
ap.add_argument("source")
ap.add_argument("destination")
args = ap.parse_args()
with open(args.source) as inf:
with open(args.destination, "w") as outf:
first_line = inf.readline()
if first_line.startswith("#!"):
print("#!", sys.executable, file=outf)
else:
print("#!", sys.executable, file=outf)
outf.write(first_line)
for line in inf:
outf.write(line)
shutil.copymode(args.source, args.destination)