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 | #
|
---|
9 | use strict 'vars';
|
---|
10 | use ProjectBuilder::Base;
|
---|
11 | use ProjectBuilder::Version;
|
---|
12 | use Data::Dumper;
|
---|
13 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
14 | use English;
|
---|
15 |
|
---|
16 |
|
---|
17 | =pod
|
---|
18 |
|
---|
19 | =head1 NAME
|
---|
20 |
|
---|
21 | mr-label labelling tool
|
---|
22 |
|
---|
23 | =head1 DESCRIPTION
|
---|
24 |
|
---|
25 | mr-label labels VFAT devices or files representing VFAT devices
|
---|
26 |
|
---|
27 | =head1 SYNOPSIS
|
---|
28 |
|
---|
29 | mr-label [-v][-h][-l label] device|file
|
---|
30 |
|
---|
31 | =head1 ARGUMENTS
|
---|
32 |
|
---|
33 | =over 4
|
---|
34 |
|
---|
35 | =item B<device|file>
|
---|
36 |
|
---|
37 | This 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 |
|
---|
47 | Increase verbosity
|
---|
48 |
|
---|
49 | =item B<-h|--help>
|
---|
50 |
|
---|
51 | Print a brief help message and exits.
|
---|
52 |
|
---|
53 | =item B<--man>
|
---|
54 |
|
---|
55 | Prints the manual page and exits.
|
---|
56 |
|
---|
57 | =item B<-l label>
|
---|
58 |
|
---|
59 | This is the new label to put on the VFAT filesystem
|
---|
60 |
|
---|
61 | =back
|
---|
62 |
|
---|
63 | =head1 WEB SITES
|
---|
64 |
|
---|
65 | The 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/>.
|
---|
66 |
|
---|
67 | =head1 USER MAILING LIST
|
---|
68 |
|
---|
69 | For community exchanges around MondoRescue please use the list L<http://sourceforge.net/mailarchive/forum.php?forum_name=mondo-devel>
|
---|
70 |
|
---|
71 | =head1 AUTHORS
|
---|
72 |
|
---|
73 | The MondoRescue team lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
74 |
|
---|
75 | =head1 COPYRIGHT
|
---|
76 |
|
---|
77 | MondoRescue is distributed under the GPL v2.0 license or later,
|
---|
78 | described in the file C<COPYING> included with the distribution.
|
---|
79 |
|
---|
80 | =cut
|
---|
81 |
|
---|
82 | # Global variables
|
---|
83 | my ($mrver,$mrrev) = pb_version_init();
|
---|
84 | my $appname = "mr-label";
|
---|
85 | my %opts; # CLI Options
|
---|
86 |
|
---|
87 | # Initialize the syntax string
|
---|
88 |
|
---|
89 | pb_syntax_init("$appname Version $mrver-$mrrev\n");
|
---|
90 |
|
---|
91 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
92 | "man" => \$opts{'man'},
|
---|
93 | "verbose|v+" => \$opts{'v'},
|
---|
94 | "label|l=s" => \$opts{'l'},
|
---|
95 | ) || pb_syntax(-1,0);
|
---|
96 |
|
---|
97 | if (defined $opts{'h'}) {
|
---|
98 | pb_syntax(0,1);
|
---|
99 | }
|
---|
100 | if (defined $opts{'man'}) {
|
---|
101 | pb_syntax(0,2);
|
---|
102 | }
|
---|
103 | if (defined $opts{'v'}) {
|
---|
104 | $pbdebug++;
|
---|
105 | }
|
---|
106 | pb_log_init($pbdebug, $pbLOG);
|
---|
107 | pb_temp_init($pbdebug);
|
---|
108 |
|
---|
109 | my $label=$opts{'l'};
|
---|
110 | die "Unable no label defined, use -l label" if (not defined $label);
|
---|
111 |
|
---|
112 | my $inputf = $ARGV[0];
|
---|
113 | die "$0: no input file defined" if (not defined $inputf);
|
---|
114 |
|
---|
115 | my($inputfh, $buffer);
|
---|
116 | open($inputfh, "+< $inputf") || die "$0: cannot open $inputf for reading/writing: $!";
|
---|
117 | binmode($inputfh) || die "binmode failed: $!";
|
---|
118 |
|
---|
119 | # 42 first bytes are untouched
|
---|
120 | if (! seek($inputfh, 43,0)) {
|
---|
121 | die "Unable to seek $inputf: $!";
|
---|
122 | }
|
---|
123 |
|
---|
124 | # Label is then the 11 following bytes
|
---|
125 | my $size = read($inputfh, $buffer, 11);
|
---|
126 | if ($size != 11) {
|
---|
127 | die "Unable to read existing label: $!";
|
---|
128 | }
|
---|
129 | pb_log(1,"Previous label was ***$buffer***\n");
|
---|
130 | my $hexlabel=sprintf("%-11s", uc($label));
|
---|
131 | pb_log(1,"New label is ***$hexlabel***\n");
|
---|
132 | # Go back
|
---|
133 | seek($inputfh, 43,0);
|
---|
134 | print $inputfh $hexlabel;
|
---|
135 | close($inputfh) || die "couldn't close $inputf: $!";
|
---|