Changeset 3488


Ignore:
Timestamp:
Dec 3, 2015, 3:07:55 AM (22 months ago)
Author:
bruno
Message:
  • mr-label now works for setupping UUIDs and is called in mondorestore postprocessing accordingly. Fix #778.
Location:
branches/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/bin/mr-label

    r3486 r3488  
    2727=head1 SYNOPSIS
    2828
    29 mr-label [-v][-h][-l label] device|file
     29mr-label [-v][-h][-L LABEL|-U UUID] device|file
    3030
    3131=head1 ARGUMENTS
     
    5555Prints the manual page and exits.
    5656
    57 =item B<-l label>
     57=item B<-L LABEL>
    5858
    59 This is the new label to put on the VFAT filesystem
     59This is the new LABEL to put on the VFAT filesystem
     60
     61=item B<-U UUID>
     62
     63This is the new UUID to put on the VFAT filesystem
    6064
    6165=back
     
    9296        "man" => \$opts{'man'},
    9397        "verbose|v+" => \$opts{'v'},
    94         "label|l=s" => \$opts{'l'},
     98        "label|L=s" => \$opts{'L'},
     99        "uuid|U=s" => \$opts{'U'},
    95100) || pb_syntax(-1,0);
    96101
     
    107112pb_temp_init($pbdebug);
    108113
    109 my $label=$opts{'l'};
    110 die "Unable no label defined, use -l label" if (not defined $label);
     114my $label=$opts{'L'};
     115my $uuid=$opts{'U'};
     116die "Unable no label/uuid defined" if ((not defined $label) && (not defined $uuid));
    111117
    112118my $inputf  = $ARGV[0];
    113119die "$0: no input file defined" if (not defined $inputf);
    114120
    115 my($inputfh, $buffer);
     121my($inputfh, $buffer, $offset, $length, $hexlabel, $newbuf);
    116122open($inputfh,  "+< $inputf") || die "$0: cannot open $inputf for reading/writing: $!";
    117123binmode($inputfh) || die "binmode failed: $!";
    118124
    119 # 42 first bytes are untouched
    120 if (! seek($inputfh, 43,0)) {
     125if (defined $label) {
     126    # 42 first bytes are untouched
     127    $offset = 43;
     128    $length = 11;
     129} elsif (defined $uuid) {
     130    # 38 first bytes are untouched
     131    $offset = 39;
     132    $length = 4;
     133    $newbuf = "";
     134} else {
     135    die "Nothing to do no label/uuid defined";
     136}
     137
     138if (! seek($inputfh, $offset,0)) {
    121139    die "Unable to seek $inputf: $!";
    122140}
     141# then read the following bytes
     142my $size = read($inputfh, $buffer, $length);
     143if ($size != $length) {
     144    die "Unable to read existing label/uuid: $!";
     145}
    123146
    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: $!";
     147if (defined $label) {
     148    pb_log(1,"Previous label was ***$buffer***\n");
     149} elsif (defined $uuid) {
     150    my ($hex) = unpack( 'H*', $buffer );
     151    #for my $d (split('',$buffer)) {
     152    #pb_log(1,"Char analyzed: ".hex($d)."\n");
     153    #$newbuf = $d.$newbuf;
     154    #}
     155    pb_log(1,"Previous hex was ***$hex***\n");
     156    my @loc = ($hex =~ m/../g);
     157    print Dumper(@loc);
     158    $hex = join('',reverse(@loc));
     159    pb_log(1,"Previous uuid was ***$hex***\n");
     160} else {
     161    die "Nothing to do no label/uuid defined";
    128162}
    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");
     163   
     164if (defined $label) {
     165    $hexlabel=sprintf("%-11s", uc($label));
     166    pb_log(1,"New label is ***$hexlabel***\n");
     167} elsif (defined $uuid) {
     168    pb_log(1,"New uuid is ***$uuid***\n");
     169    my @loc = ($uuid =~ m/../g);
     170    my $hex = join('',reverse(@loc));
     171    ($hexlabel) = pack( 'H*', $hex );
     172} else {
     173    die "Nothing to do no label/uuid defined";
     174}
    132175# Go back
    133 seek($inputfh, 43,0);
     176seek($inputfh, $offset,0);
    134177print $inputfh $hexlabel;
    135178close($inputfh) || die "couldn't close $inputf: $!";
  • branches/3.2/mondo/src/restore-scripts/mondo/label-partitions-as-necessary

    r3472 r3488  
    5757            $command
    5858        elif [ "$format" = "fat" ] || [ "$format" = "vfat" ]; then
    59             if [ -x "/sbin/fatlabel" ]; then
    60                 command="/sbin/fatlabel $mountpt $label"
    61                 LogIt "Running $command"
    62                 $command
     59            if [ "$opttun" = "-U" ]; then
     60                if [ -x "/usr/bin/mr-label" ]; then
     61                    command="/usr/bin/mr-label -U $label $mountpt"
     62                    LogIt "Running $command"
     63                    $command
     64                else
     65                    LogIt "No command available to update a UUID of a FAT/VFAT FS"
     66                fi
    6367            else
    64                 LogIt "No fatlabel command available to label a FAT/VFAT FS"
     68                if [ -x "/sbin/fatlabel" ]; then
     69                    command="/sbin/fatlabel $mountpt $label"
     70                    LogIt "Running $command"
     71                    $command
     72                else
     73                    LogIt "No fatlabel command available to label a FAT/VFAT FS"
     74                fi
    6575            fi
    6676        elif [ "$format" = "swap" ] ; then
Note: See TracChangeset for help on using the changeset viewer.