Skip to content

Commit

Permalink
Merge pull request #2 from mariux64/add_software_raid_mounts
Browse files Browse the repository at this point in the history
mxmount: Add software raid mounts
  • Loading branch information
donald authored Feb 16, 2017
2 parents 6c9441e + 3eabfd1 commit b7a6ffe
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions mxmount
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ my $exports = "/etc/exports";

########################################

my $tag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #";
my $exportstag = "# DO NOT EDIT BELOW THIS LINE # created by /usr/bin/mxmount #";

my $fullhostname;
my $hostname;
Expand All @@ -31,7 +31,7 @@ $fullhostname = hostname();
DEFAULT_MOUNT_OPTIONS => '',
DEFAULT_EXPORT_OPTIONS => '',
DEFAULT_MOUNT_PREFIX => '/',

SHORTHOST => $hostname,
FULLHOST => $fullhostname,

Expand Down Expand Up @@ -89,21 +89,21 @@ sub create_exports {
foreach my $exp (@exports) {
chomp($exp);
next if($exp =~ /^\s*$/);
last if($exp eq $tag);
last if($exp eq $exportstag);
print EXPORTS "$exp\n";
}

print EXPORTS "\n$tag\n\n# auch du nicht, donald 8)\n\n";
print EXPORTS "\n$exportstag\n\n";

foreach my $mp (@$allmp) {
next if($mp->{noexport});
@CMD = ($mp->{mountpoint}, $mp->{exportopts});

print join " ", "$exports: ", @CMD, "\n";
print EXPORTS join " ", @CMD, "\n";

}

close EXPORTS;
}

Expand All @@ -112,11 +112,11 @@ sub mount_all {
my $allmp = $D{$hostname};
my @CMD;
foreach my $mp (sort { $a->{mountpoint} cmp $b->{mountpoint} } @$allmp) {

@CMD = ();

push @CMD, 'mount', "LABEL=$mp->{label}", $mp->{mountpoint};

if($mp->{fs}) {
push @CMD, '-t', $mp->{fs};
}
Expand All @@ -133,7 +133,7 @@ sub parse_data {
my @lines = @_;
my @invalid = ();
my @data;

my $rest;

foreach(@lines) {
Expand All @@ -145,7 +145,7 @@ sub parse_data {
}

my $D = {};

$D->{line} = $_;

$D->{host} = $data[0];
Expand All @@ -156,20 +156,23 @@ sub parse_data {
$D->{noexport} = 1;
$D->{label} = $1;
}

if($D->{label} =~ /(.*):(.*)/) {
$D->{label} = $1;
$D->{mountpoint} = $2;
} else {
if($D->{label} =~ /^X/) {
if($D->{label} =~ /^X/) { # X: decent controller based raid
$D->{mountpoint} = 'X/' . $D->{label};
$D->{label} = lc($D->{label});
} elsif($D->{label} =~ /^C/) {
} elsif($D->{label} =~ /^C/) { # C: controller based raid, confidential
$D->{mountpoint} = 'C/' . $D->{label};
$D->{label} = lc($D->{label});
if (!$data[3]) {
$D->{noexport} = 1;
}
} elsif($D->{label} =~ /^M/) { # M: decent software raid (mdadm)
$D->{mountpoint} = 'M/' . $D->{label};
$D->{label} = lc($D->{label});
} elsif($D->{label} =~ /^data(.*)/) {
$D->{mountpoint} = $1;
} else {
Expand All @@ -189,11 +192,11 @@ sub parse_data {
}

$D->{exportopts} = $data[3] ? $data[3] : $V{DEFAULT_EXPORT_OPTIONS};

foreach(qw(host label mountpoint fs mountopts exportopts )) {
$D->{$_} = expand_variables($D->{$_});
}


push @{$D{$D->{host}}}, $D;
}
Expand All @@ -202,11 +205,11 @@ sub parse_data {

sub expand_variables {
my $s = shift;

foreach my $k (keys %V) {
$s =~ s/$k/$V{$k}/g;
}

return $s;
}

Expand Down Expand Up @@ -238,13 +241,13 @@ sub read_file {
while(<F>) {
chomp;
next if(/^\s*#/ or /^\s*$/);
$cont=0;
s/#.*$//; # remove comments..
$_ = $line . $_;

if(s/\\\s*$//) {
# line continous in next line..
$cont=1;
Expand All @@ -260,7 +263,7 @@ sub read_file {
$line="";
}
}

close F;
return @lines;
}
Expand Down

0 comments on commit b7a6ffe

Please sign in to comment.