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