hivex: Reimplement hivexget as a simple shell script.
[libguestfs.git] / tools / run-locally
1 #!/usr/bin/perl
2 # Copyright (C) 2009 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # This script sets up the environment so you can run virt-* tools in
19 # place without needing to do 'make install' first. You can also run
20 # the tools by creating a symlink to this script and putting it in
21 # your path.
22 #
23 # Use it like this:
24 #   ./run-locally tool [usual virt-tool args ...]
25 # eg:
26 #   ./run-locally cat domname /etc/passwd
27
28 use strict;
29 use warnings;
30
31 use File::Basename qw(dirname);
32 use File::Spec;
33 use Cwd qw(abs_path);
34
35 my $path = $0;
36 my $tool = shift @ARGV;
37
38 # Follow symlinks until we get to the real file
39 while(-l $path) {
40     my $link = readlink($path) or die "readlink: $path: $!";
41     if(File::Spec->file_name_is_absolute($link)) {
42         $path = $link;
43     } else {
44         $path = File::Spec->catfile(dirname($path), $link);
45     }
46 }
47
48 # Get the absolute path of the parent directory
49 $path = abs_path(dirname($path).'/..');
50
51 $ENV{PATH}            = $path.'/hivex:'.$ENV{PATH};
52 $ENV{LD_LIBRARY_PATH} = $path.'/src/.libs';
53 $ENV{LIBGUESTFS_PATH} = $path.'/appliance';
54 $ENV{PERL5LIB}        = $path.'/perl/blib/lib:'.$path.'/perl/blib/arch';
55
56 #print (join " ", ("$path/tools/virt-$tool", @ARGV), "\n");
57 exec('perl', "$path/tools/virt-$tool", @ARGV);