This file is indexed.

/usr/bin/xt-customize-image is in xen-tools 4.2.1-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/perl -w

=head1 NAME

xt-customize-image - Customize a freshly installed copy of GNU/Linux

=cut

=head1 SYNOPSIS

  xt-customize-image [options]

  Help Options:
   --help     Show this scripts help information.
   --manual   Read this scripts manual.
   --version  Show the version number and exit.

  Debugging Options:
   --verbose  Be verbose in our execution.

  Mandatory Options:
   --location The location of the new installation
   --dist     The name of the distribution which has been installed.

  All other options from xen-create-image, such as the new IP address(es)
 to give to the new instance, will be passed as environmental variables.

=cut

=head1 NOTES

  This script is invoked by xen-create-image after it has created a
 fresh installation of Linux withing a temporary location.

  This script will be invoked with a full copy of the arguments from
 xen-create-image in its environment, along with several command line
 arguments.

  The command line arguments which are mandatory are:

   --location  - The temporary installation root of the new install
   --dist      - The distribution which has been installed.

=cut


=head1 HOOK SCRIPTS

  The distribution name is used to locate an appropriate collection
 of scripts, or hooks, to execute to do the actual customisation.

  The hooks will each be executed with a single parameter which is
 the directory path to the new instance.  This argument is taken from
 the --location option.

  For the distribution named 'foo' the scripts will be loaded and
 executed from '/usr/lib/xen-tools/foo.d'.  Each executable will
 be loaded and executed in sorted order.

=cut


=head1 AUTHORS

 Steve Kemp, http://www.steve.org.uk/
 Axel Beckert, http://noone.org/abe/
 Stéphane Jourdois

=cut


=head1 LICENSE

Copyright (c) 2005-2009 by Steve Kemp, (c) 2010 by The Xen-Tools
Development Team. All rights reserved.

This module is free software;
you can redistribute it and/or modify it under
the same terms as Perl itself.
The LICENSE file contains the full text of the license.

=cut


use strict;
use Env;
use Getopt::Long;
use Pod::Usage;


#
#  Configuration values read from the command line.
#
#  We do not need to read any configuration file.
#
my %CONFIG;

#
# Release number.
#
my $RELEASE = '4.2.1';



#
#  Parse the command line arguments.
#
parseCommandLineArguments();


#
#  Check our arguments.
#
checkArguments();


#
#  Run each relevant hook scripts.
#
runDistributionHooks();


#
#  Exit cleanly - any errors which have already occurred will result
# in "exit 1".
#
exit 0;



=begin doc

  Parse the command line arguments this script was given.

=end doc

=cut

sub parseCommandLineArguments
{
    my $HELP    = 0;
    my $MANUAL  = 0;
    my $VERSION = 0;

    #
    #  Parse options.
    #
    GetOptions( "location=s", \$CONFIG{ 'location' },
                "dist=s",     \$CONFIG{ 'dist' },
                "verbose",    \$CONFIG{ 'verbose' },
                "help",       \$HELP,
                "manual",     \$MANUAL,
                "version",    \$VERSION
              );

    pod2usage(1) if $HELP;
    pod2usage( -verbose => 2 ) if $MANUAL;


    if ($VERSION)
    {
        my $REVISION = '$Revision: 1.33 $';
        if ( $REVISION =~ /1.([0-9.]+) / )
        {
            $REVISION = $1;
        }

        print "xt-customize-image release $RELEASE - CVS: $REVISION\n";
        exit;
    }
}



=begin doc

  Test that the command line arguments we were given make sense.

=end doc

=cut

sub checkArguments
{

    #
    #  We require a location.
    #
    if ( !defined( $CONFIG{ 'location' } ) )
    {
        print "The '--location' argument is mandatory\n";
        exit 1;
    }


    #
    #  Test that the location we've been given exists
    #
    if ( !-d $CONFIG{ 'location' } )
    {
        print "The installation directory we've been given doesn't exist\n";
        print "We tried to use : $CONFIG{'location'}\n";
        exit 1;
    }


    #
    #  We require a distribution name.
    #
    if ( !defined( $CONFIG{ 'dist' } ) )
    {
        print "The '--dist' argument is mandatory\n";
        exit 1;
    }


    #
    #  Test that the distribution name we've been given
    # to configure has a collection of hook scripts.
    #
    #  If there are no scripts then we clearly cannot
    # customise it!
    #
    my $dir = "/usr/lib/xen-tools/" . $CONFIG{ 'dist' } . ".d";

    if ( !-d $dir )
    {
        print <<E_OR;

  We\'re trying to configure an installation of $CONFIG{'dist'} in
 $CONFIG{'location'} - but there is no hook directory for us to use.

  This means we don\'t know how to configure this installation.

  We\'d expect the hook directory to be : $dir

  Aborting.
E_OR
        exit 1;
    }

}



=begin doc

  This function does the real work of running each of our hook scripts.

  Each hook script is executed in turn, ignoring emacs save files and
 dpkg files.

  We will give each script the name of the directory containing the
 installation as a single argument.

=end doc

=cut

sub runDistributionHooks
{

    #
    #  Hook directory.
    #
    my $hooks = "/usr/lib/xen-tools/" . $CONFIG{ 'dist' } . ".d/";

    #
    #  Installation prefix
    #
    my $prefix = $CONFIG{ 'location' };

    #
    #  If we're running verbosely then setup the client environment
    # appropriately.
    #
    #  This is useful in case this script is called outwith the usual
    # xen-create-image framework.
    #
    if ( $CONFIG{ 'verbose' } )
    {
        $ENV{ 'verbose' } = 1;
    }

    #
    # Make sure that our scripts run in sorted order, as
    # the user would expect.
    #
    foreach my $file ( sort( glob( $hooks . "*" ) ) )
    {

        # skip files that end with .dpkg-new, .dpkg-old or '~'
        next if ( $file =~ /\.dpkg-(new|old)/ );
        next if ( $file =~ /~$/ );

        #
        # Only run executable files.
        #
        if ( ( -x $file ) && ( -f $file ) )
        {

            #
            # Just display the name - no need to see the full path.
            #
            my $name = $file;
            if ( $file =~ /(.*)\/(.*)/ )
            {
                $name = $2;
            }

            #
            # Complete command we're going to execute.
            #
            my $cmd = $hooks . $name . " $CONFIG{'location'}";

            #
            #  Run the command.  This has different prolog and epilog
            # depending on whether we're running verbosely or not.
            #
            if ( $CONFIG{ 'verbose' } )
            {
                print "Running hook $name ['$cmd']\n";
                print "--\n";
                my $rc = system($cmd);
                if ($rc != 0) {
                print "hook $name failed: $?\n";
                exit 1;
            }
                print "--\n";
                print "Done\n\n";
            }
            else
            {
                print "Running hook $name\n";
                my $rc = system($cmd);
                if ($rc != 0) {
                    print "hook $name failed: $?\n";
                    exit 1;
                }
                print "hook $name: done.\n";
            }
        }
    }
}