~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/reporting/src/test/pl/inject.pl

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
#
 
4
# inject.pl injects an executable or perl script into an image, then modifies the startup
 
5
#  of that image such that the executable or perl script will start automatically when
 
6
#  the image starts.
 
7
#
 
8
# (c)2011, Eucalyptus Systems, Inc. All Rights Reserved.
 
9
# author: tom.werges
 
10
#
 
11
 
 
12
use strict;
 
13
use warnings;
 
14
 
 
15
if ($#ARGV < 1) {
 
16
        die "Usage: inject.pl image_file executable_file";
 
17
}
 
18
 
 
19
my $image_file = shift;
 
20
my $executable_file = shift;
 
21
 
 
22
sub cmd($);
 
23
 
 
24
mkdir("/mnt/image");
 
25
cmd("losetup /dev/loop6 $image_file");
 
26
cmd("mount /dev/loop6 /mnt/image");
 
27
cmd("cp $executable_file /mnt/image/etc/init.d");
 
28
chmod(755, "/mnt/image/etc/init.d/$executable_file");
 
29
cmd("chroot /mnt/image ln -s /usr/bin/$executable_file /etc/rc3.d/S99$executable_file");
 
30
cmd("umount /dev/loop6");
 
31
cmd("losetup -d /dev/loop6");
 
32
 
 
33
exit(0);
 
34
 
 
35
sub cmd($) {
 
36
        print "Running command:$_[0]:";
 
37
        my $return_code = (system($_[0])/256);
 
38
        if ($return_code==0) {
 
39
                print "passed\n";
 
40
                return;
 
41
        } else {
 
42
                print "FAILED\n";
 
43
                exit(127);
 
44
        }
 
45
}
 
46