Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # This is a wrapper for dmidecode that will return the configured UUID
- # when 'dmidecode -s system-uuid' is called. Otherwise, it will call dmidecode
- # and return as appropriate.
- #
- ## slightly edited to leave @ARGV intact, do open "-|" and exec {} $0, @ARGV,
- ## by Lars Ellenberg, untested, all typos mine :)
- use strict;
- use warnings;
- use IO::Handle;
- # Desired System UUID
- my $uuid;
- my $exit=0;
- my $sub=0;
- $sub = (@ARGV == 3 and
- $ARGV[0] eq "-q" and
- $ARGV[1] eq "-t" and
- $ARGV[2] eq "0,1,4,17");
- # Read the UUID from /etc/libvirt/libvirtd.conf.
- my $sc="</etc/libvirt/libvirtd.conf";
- my $fh=IO::Handle->new();
- open ($fh, $sc) or die "$!";
- while (<$fh>)
- {
- chomp;
- my $line=$_;
- next if $line =~ /^#/;
- if ($line =~ /host_uuid/)
- {
- ($uuid)=($line =~ /"(.*?)"/);
- }
- }
- $fh->close();
- # Call the real dmidecode
- undef $fh;
- my $pid = open($fh, "-|");
- die unless defined $pid;
- if ($pid == 0) {
- # child
- exec { "/usr/sbin/dmidecode.orig" } $0, @ARGV;
- die; # not reached
- }
- # parent
- while (<$fh>)
- {
- chomp;
- my $line=$_;
- # If I found a UUID, this line is the UUID and I am doing a
- # substitution, well, do it already.
- if (($uuid) && ($line=~/(\s+)UUID: /) && ($sub))
- {
- my $space=$1;
- print "${space}UUID: $uuid\n";
- }
- else
- {
- print $line, "\n";
- }
- }
- $fh->close();
- $exit=$?;
- exit($exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement