Skip to content

Commit

Permalink
texlive.combine: fix perl scripts without a shebang
Browse files Browse the repository at this point in the history
Fixes NixOS#24343.  These parts of upstream texlive are really ugly.
Also improve variable quoting in the code around.
  • Loading branch information
vcunat committed Jul 1, 2017
1 parent 1551975 commit 8dddd2b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkgs/tools/typesetting/tex/texlive/combine.nix
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,24 @@ in buildEnv {
--prefix PERL5LIB : "$out/share/texmf/scripts/texlive"
# avoid using non-nix shebang in $target by calling interpreter
if [[ "$(head -c 2 $target)" = "#!" ]]; then
local cmdline="$(head -n 1 $target | sed 's/^\#\! *//;s/ *$//')"
if [[ "$(head -c 2 "$target")" = "#!" ]]; then
local cmdline="$(head -n 1 "$target" | sed 's/^\#\! *//;s/ *$//')"
local relative=`basename "$cmdline" | sed 's/^env //' `
local newInterp=`echo "$relative" | cut -d\ -f1`
local params=`echo "$relative" | cut -d\ -f2- -s`
local newPath="$(type -P $newInterp)"
local newPath="$(type -P "$newInterp")"
if [[ -z "$newPath" ]]; then
echo " Warning: unknown shebang '$cmdline' in '$target'"
continue
fi
echo " and patching shebang '$cmdline'"
sed "s|^exec |exec $newPath $params |" -i "$link"
elif head -n 1 "$target" | grep -q 'exec perl'; then
# see #24343 for details of the problem
echo " and patching weird perl shebang"
sed "s|^exec |exec '${perl}/bin/perl' -w |" -i "$link"
else
sed 's|^exec |exec -a "$0" |' -i "$link"
echo
Expand Down

0 comments on commit 8dddd2b

Please sign in to comment.