3 # Copyright (C) 2009 Red Hat Inc.
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.
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.
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.
21 use Sys::Guestfs::Lib qw(open_guest get_partitions);
24 use Locale::TextDomain 'virt-tools';
30 virt-tools-get-key - virt-tools helper to get the guest's key
34 virt-tools-get-key [--options] domname
38 This helper program is used by L<virt-tools(8)> to get the guest's
39 secret key. If you don't know anything about this, you probably want
40 to start by reading L<virt-tools(8)>. Otherwise read on.
42 The single command line argument should be a libvirt domain name (see
47 The cache is described in detail in L<virt-tools(8)>. In brief, if
48 C<@LOCALSTATEDIR@/lib/virt-tools/keys/E<lt>UUIDE<gt>> exists (where
49 E<lt>UUIDE<gt> is the guest's UUID), then the contents of that file
50 are returned directly. Otherwise we will try to create this file
51 after reading the key so that we don't have to read the key out of the
52 guest's filesystem each time.
72 Display version number and exit.
78 =item B<--connect URI> | B<-c URI>
80 If using libvirt, connect to the given I<URI>. If omitted, then we
81 connect to the default libvirt hypervisor.
87 =item B<--verbose> | B<-v>
89 Enable verbose messages, useful for debugging.
95 GetOptions ("help|?" => \$help,
96 "version" => \$version,
97 "connect|c=s" => \$uri,
98 "verbose|v" => \$verbose,
100 pod2usage (1) if $help;
102 print "@PACKAGE_STRING@\n";
106 die __"no domain name or UUID listed on the command line\n" unless @ARGV == 1;
111 $g = open_guest (\@ARGV, address => $uri);
113 $g = open_guest (\@ARGV);
118 # Don't care about mountpoints. Instead, just look for a
119 # directory with one of a selection of names on one of the
120 # partitions that we found.
121 my @partitions = get_partitions ($g);
126 foreach my $partition (@partitions) {
128 $g->mount_ro ($partition, "/");
130 my @dirs = ("/var/lib/virt-tools", "/lib/virt-tools");
131 foreach $dir (@dirs) {
132 if ($g->is_dir ($dir) && $g->is_file ("$dir/key")) {
133 $key = $g->cat ("$dir/key");
143 die __x("{n}: no key found in guest.\nDoes it have the virt-tool-guest package installed?\n",
157 L<Sys::Guestfs::Lib(3)>,
159 L<http://libguestfs.org/>.
167 Richard W.M. Jones (C<rjones at redhat dot com>)
171 Matthew Booth (C<mbooth at redhat dot com>)
177 Copyright (C) 2009 Red Hat Inc.
179 This program is free software; you can redistribute it and/or modify
180 it under the terms of the GNU General Public License as published by
181 the Free Software Foundation; either version 2 of the License, or
182 (at your option) any later version.
184 This program is distributed in the hope that it will be useful,
185 but WITHOUT ANY WARRANTY; without even the implied warranty of
186 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187 GNU General Public License for more details.
189 You should have received a copy of the GNU General Public License
190 along with this program; if not, write to the Free Software
191 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.