1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!/usr/bin/env bash
# This script prints the standard header that should be at the start
# of every Perl tool.
# ############################################################################
# Standard startup, find the branch's root directory
# ############################################################################
exit_status=0
die() {
echo $1 >&2
exit 1
}
warn() {
echo $1 >&2
exit_status=$((exit_status | 1))
}
cwd="$PWD"
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
BRANCH=$PERCONA_TOOLKIT_BRANCH
else
while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do
cd ..
done
if [ ! -f Makefile.PL ]; then
die "Cannot find the root directory of the Percona Toolkit branch"
fi
BRANCH=`pwd`
fi
cd "$cwd"
# ############################################################################
# Global variables
# ############################################################################
EXIT_STATUS=0
# ############################################################################
# Subroutines
# ############################################################################
# None
# ############################################################################
# Script starts here
# ############################################################################
tool_file=$1
if [ -z "$tool_file" ]; then
die "Usage: $0 TOOL"
fi
if [ ! -f $tool_file ]; then
die "$tool_file does not exist"
fi
if ! grep -m 1 -q '^use ' $tool_file; then
die "This only works for Perl tools"
fi
echo "#!/usr/bin/env perl
# This program is part of Percona Toolkit: http://www.percona.com/software/
# See \"COPYRIGHT, LICENSE, AND WARRANTY\" at the end of this file for legal
# notices and disclaimers.
use strict;
use warnings FATAL => 'all';
# This tool is \"fat-packed\": most of its dependent modules are embedded
# in this file. Setting %INC to this file for each module makes Perl aware
# of this so it will not try to load the module from @INC. See the tool's
# documentation for a full list of dependencies.
BEGIN {
\$INC{\$_} = __FILE__ for map { (my \$pkg = \"\$_.pm\") =~ s!::!/!g; \$pkg } (qw("
for pkg in $(grep '^package [A-Za-z:]*;' $tool_file | cut -d' ' -f2 | cut -d';' -f1); do
echo " $pkg"
done
echo " ));
}";
exit $EXIT_STATUS
|