blob: 5a27c71b577fbb0787c140e3defb5e8803e3bcb7 [file] [log] [blame] [raw]
#!/bin/bash
#!/bin/sh
# Use /bin/bash for exec -a
# perl(1) wrapper
# Copyright 2015-2018 Rivoreo
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
REAL_PERL=/usr/lib/perl5/5.8.0/perl
argv0="`basename \"$0\"`"
set +H
set -e
printf '[%s] UID=%s PWD="%s" %s %s (#=%s)\n' "`date +%F.%T.%Z`" "$UID" "$PWD" "$0" "$*" "$#" >> /var/log/perl.log
[ ${argv0:0:4} != perl ] && exec -a $argv0 $REAL_PERL "$@"
case "$1" in
--)
shift
;;
-*)
exec -a $argv0 $REAL_PERL "$@"
;;
esac
[ $# -lt 1 -o "$1" = - ] && exec -a $argv0 $REAL_PERL
if [ ! -e "$1" ]; then
echo "Can't open perl script \"$1\": No such file or directory" 1>&2
exit 2
fi
if [ "`dd bs=1 count=3 if=\"$1\" 2> /dev/null`" = "`printf '\\xef\\xbb\\xbf'`" ]; then
script="$1"
shift
printf \\0 | cat - "$script" | $REAL_PERL -- - "$@"
exit
fi
if sed 1!d "$1" | grep -Eq '^#!.+'; then
script="$1"
shift
sed 1c\# "$script" | $REAL_PERL -- - "$@"
exit
fi
exec -a $argv0 $REAL_PERL -- "$@"