3 #This program is free software: you can redistribute it and/or modify
4 #it under the terms of the GNU General Public License as published by
5 #the Free Software Foundation, either version 3 of the License, or
6 #(at your option) any later version.
8 #This program is distributed in the hope that it will be useful,
9 #but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 #GNU General Public License for more details.
13 #You should have received a copy of the GNU General Public License
14 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Written by Richard Hartmann in 2009, feel free to email
17 # richih.mailinglist@gmail.com with questions.
24 use Getopt
::Long
qw(:config no_ignore_case bundling);
28 my $program = basename
($0);
30 my $file = '/etc/hostuuid';
37 'help|h|?' => \
$print_help,
38 'version|v' => \
$print_version,
39 'create|c' => \
$create_uuid,
44 $program: version $version
46 This program is released under GPLv3
47 Written by Richard Hartmann for Debian and Grml
56 -h, -?, --help : print this help
57 -v, --version : print version
58 -f, --file : file to read from/write to. Defaults to /etc/hostuuid
59 -c, --create : create & save UUID
65 my $uuid = find_hostuuid
();
67 print STDERR
"$program: Found UUID '$uuid' in '$file'. Aborting!\n";
70 open (F
, ">", "$file") or die "$program: Could not open file: '$file'\: $!\n";
71 $uuid = create_UUID_as_string
(UUID_V4
);
72 print "$program\: Stored UUID '$uuid' in file '$file'\n";
80 # if ($create_uuid) {return 0 unless -e $file;}
81 return 0 unless ((-e
$file && $create_uuid) || !$create_uuid);
82 open (F
, "<", "$file") or die "$program: Could not open file: '$file'\: $!\n";
84 if (/([0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12})/i) {
92 print "\n\nIf anyone knows how to die() when there is no value for -f, tell me!\n\n";
94 print_version
() if $print_version;
95 print_help
() if $print_help;
96 create_uuid
() if $create_uuid;
98 my $uuid = find_hostuuid
();
103 print STDERR
"$program: Could not find UUID in '$file'\n";