source: MondoRescue/branches/3.2/MondoRescue/bin/mr-label@ 3496

Last change on this file since 3496 was 3496, checked in by Bruno Cornec, 8 years ago
  • Avoid a perl warning on mr-label
  • Property svn:executable set to *
File size: 3.9 KB
RevLine 
[3486]1#!/usr/bin/perl -w
2#
3# $Id$
4# Copyright B. Cornec 2005-2014
5# Provided under the GPL v2
6#
7# Get the complete network configuration of the system
8#
9use strict 'vars';
10use ProjectBuilder::Base;
11use ProjectBuilder::Version;
12use Data::Dumper;
13use Getopt::Long qw(:config auto_abbrev no_ignore_case);
14use English;
15
16
17=pod
18
19=head1 NAME
20
21mr-label labelling tool
22
23=head1 DESCRIPTION
24
25mr-label labels VFAT devices or files representing VFAT devices
26
27=head1 SYNOPSIS
28
[3488]29mr-label [-v][-h][-L LABEL|-U UUID] device|file
[3486]30
31=head1 ARGUMENTS
32
33=over 4
34
35=item B<device|file>
36
37This is the VFAT device or file representing a VFAT device to modify with regards to its label
38
39=back
40
41=head1 OPTIONS
42
43=over 4
44
45=item B<-v|--verbose>
46
47Increase verbosity
48
49=item B<-h|--help>
50
51Print a brief help message and exits.
52
53=item B<--man>
54
55Prints the manual page and exits.
56
[3488]57=item B<-L LABEL>
[3486]58
[3488]59This is the new LABEL to put on the VFAT filesystem
[3486]60
[3488]61=item B<-U UUID>
62
63This is the new UUID to put on the VFAT filesystem
64
[3486]65=back
66
67=head1 WEB SITES
68
69The main Web site of the project is available at L<http://www.mondorescue.org>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.
70
71=head1 USER MAILING LIST
72
73For community exchanges around MondoRescue please use the list L<http://sourceforge.net/mailarchive/forum.php?forum_name=mondo-devel>
74
75=head1 AUTHORS
76
77The MondoRescue team lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
78
79=head1 COPYRIGHT
80
81MondoRescue is distributed under the GPL v2.0 license or later,
82described in the file C<COPYING> included with the distribution.
83
84=cut
85
86# Global variables
87my ($mrver,$mrrev) = pb_version_init();
88my $appname = "mr-label";
89my %opts; # CLI Options
90
91# Initialize the syntax string
92
93pb_syntax_init("$appname Version $mrver-$mrrev\n");
94
95GetOptions("help|?|h" => \$opts{'h'},
96 "man" => \$opts{'man'},
97 "verbose|v+" => \$opts{'v'},
[3488]98 "label|L=s" => \$opts{'L'},
99 "uuid|U=s" => \$opts{'U'},
[3486]100) || pb_syntax(-1,0);
101
102if (defined $opts{'h'}) {
103 pb_syntax(0,1);
104}
105if (defined $opts{'man'}) {
106 pb_syntax(0,2);
107}
108if (defined $opts{'v'}) {
109 $pbdebug++;
110}
111pb_log_init($pbdebug, $pbLOG);
112pb_temp_init($pbdebug);
113
[3488]114my $label=$opts{'L'};
115my $uuid=$opts{'U'};
116die "Unable no label/uuid defined" if ((not defined $label) && (not defined $uuid));
[3486]117
[3496]118my($inputfh, $buffer, $offset, $length, $hexlabel, $newbuf);
119
120$inputf = $ARGV[0];
[3486]121die "$0: no input file defined" if (not defined $inputf);
122
123open($inputfh, "+< $inputf") || die "$0: cannot open $inputf for reading/writing: $!";
124binmode($inputfh) || die "binmode failed: $!";
125
[3488]126if (defined $label) {
127 # 42 first bytes are untouched
128 $offset = 43;
129 $length = 11;
130} elsif (defined $uuid) {
131 # 38 first bytes are untouched
132 $offset = 39;
133 $length = 4;
134 $newbuf = "";
135} else {
136 die "Nothing to do no label/uuid defined";
137}
138
139if (! seek($inputfh, $offset,0)) {
[3486]140 die "Unable to seek $inputf: $!";
141}
[3488]142# then read the following bytes
143my $size = read($inputfh, $buffer, $length);
144if ($size != $length) {
145 die "Unable to read existing label/uuid: $!";
146}
[3486]147
[3488]148if (defined $label) {
149 pb_log(1,"Previous label was ***$buffer***\n");
150} elsif (defined $uuid) {
151 my ($hex) = unpack( 'H*', $buffer );
152 #for my $d (split('',$buffer)) {
153 #pb_log(1,"Char analyzed: ".hex($d)."\n");
154 #$newbuf = $d.$newbuf;
155 #}
156 pb_log(1,"Previous hex was ***$hex***\n");
157 my @loc = ($hex =~ m/../g);
158 print Dumper(@loc);
159 $hex = join('',reverse(@loc));
160 pb_log(1,"Previous uuid was ***$hex***\n");
161} else {
162 die "Nothing to do no label/uuid defined";
[3486]163}
[3488]164
165if (defined $label) {
166 $hexlabel=sprintf("%-11s", uc($label));
167 pb_log(1,"New label is ***$hexlabel***\n");
168} elsif (defined $uuid) {
169 pb_log(1,"New uuid is ***$uuid***\n");
170 my @loc = ($uuid =~ m/../g);
171 my $hex = join('',reverse(@loc));
172 ($hexlabel) = pack( 'H*', $hex );
173} else {
174 die "Nothing to do no label/uuid defined";
175}
[3486]176# Go back
[3488]177seek($inputfh, $offset,0);
[3486]178print $inputfh $hexlabel;
179close($inputfh) || die "couldn't close $inputf: $!";
Note: See TracBrowser for help on using the repository browser.