perkeep/dev-cammount

37 lines
857 B
Plaintext
Raw Normal View History

#!/usr/bin/perl
2011-03-29 17:41:03 +00:00
use strict;
use FindBin qw($Bin);
use Getopt::Long;
require "$Bin/misc/devlib.pl";
2011-03-29 17:41:03 +00:00
my @blobref_arg;
if (@ARGV) {
my $blobref = shift;
unless ($blobref && $blobref =~ /^\w+-[0-9a-f]{10,}$/) {
die "Usage: dev-cammount [<blobref>]\n";
}
push @blobref_arg, $blobref;
}
my $cammount = build_bin("./cmd/cammount");
2011-03-29 17:41:03 +00:00
my $dir = "/tmp/cammount-dir";
mkdir $dir, 0700 unless -d $dir;
2011-03-29 17:41:03 +00:00
try_unmount();
print "Mounting on $dir ...\n";
system("$cammount", "--blobserver=http://localhost:3179/bs", $dir, @blobref_arg)
and warn "cammount failure: $!\n";
warn "Failed to unmount\n" unless try_unmount();
sub try_unmount {
if ($^O eq "linux" && system("fusermount", "-u", $dir) == 0) {
return 1;
}
return 1 if system("umount", $dir) == 0;
return 1 if system("umount", "-f", $dir) == 0;
return 0;
}