~percona-toolkit-dev/percona-toolkit/changehandler-dont-hexify-text-cols

« back to all changes in this revision

Viewing changes to util/tool-header

  • Committer: Daniel Nichter
  • Date: 2012-08-23 01:59:55 UTC
  • mfrom: (350.1.29 pingback-feature)
  • Revision ID: daniel@percona.com-20120823015955-5amltej7vn72sz9w
MergeĀ lp:~percona-toolkit-dev/percona-toolkit/pingback-feature

Show diffs side-by-side

added added

removed removed

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