#!/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. # use strict; use warnings; use IO::Handle; # Desired System UUID my $uuid; my $exit=0; my $sub=0; # Read command line. my $cla=""; foreach my $arg (@ARGV) { $cla.=$arg." "; } $cla=~s/\s+$//; if ($cla eq "-q -t 0,1,4,17") { $sub=1; } # Read the UUID from /etc/libvirt/libvirtd.conf. my $sc="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 $sc="/usr/sbin/dmidecode.orig $cla 2>&1 |"; $fh=IO::Handle->new(); open ($fh, $sc) or die $!; 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);