2012-03-27 17:37:21 +00:00
|
|
|
#!/usr/bin/perl
|
2011-03-29 17:41:03 +00:00
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
use strict;
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
use Getopt::Long;
|
|
|
|
require "$Bin/misc/devlib.pl";
|
2011-03-29 17:41:03 +00:00
|
|
|
|
2012-04-29 04:29:51 +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;
|
2012-03-27 17:37:21 +00:00
|
|
|
}
|
2012-04-29 04:29:51 +00:00
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
my $cammount = build_bin("./cmd/cammount");
|
2013-07-10 09:34:58 +00:00
|
|
|
unless (-x $cammount) { die "Failed to find $cammount" }
|
2011-03-29 17:41:03 +00:00
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
my $dir = "/tmp/cammount-dir";
|
2011-03-29 17:41:03 +00:00
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
try_unmount();
|
2013-07-10 11:27:54 +00:00
|
|
|
|
|
|
|
mkdir $dir, 0700 unless -d $dir;
|
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
print "Mounting on $dir ...\n";
|
2013-07-10 09:34:58 +00:00
|
|
|
|
|
|
|
# Respected by camli/osutil:
|
|
|
|
$ENV{"CAMLI_CONFIG_DIR"} = "$Bin/config/dev-client-dir";
|
|
|
|
|
|
|
|
# Respected by env expansions in config/dev-client-dir/config
|
|
|
|
$ENV{"CAMLI_SECRET_RING"} = "$Bin/pkg/jsonsign/testdata/test-secring.gpg";
|
|
|
|
$ENV{"CAMLI_KEYID"} = "26F5ABDA";
|
|
|
|
$ENV{"CAMLI_DEV_KEYBLOBS"} = "$Bin/config/dev-client-dir/keyblobs";
|
2013-02-07 05:56:44 +00:00
|
|
|
$ENV{"CAMLI_AUTH"} = "userpass:camlistore:pass3179";
|
2013-07-10 09:34:58 +00:00
|
|
|
|
2013-07-10 11:27:54 +00:00
|
|
|
my $in_child = "false";
|
|
|
|
if ($^O eq "darwin") {
|
|
|
|
$in_child = "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
exec("$cammount", "--mount_in_child=$in_child", "--server=http://localhost:3179/bs", $dir, @blobref_arg)
|
2012-03-27 17:37:21 +00:00
|
|
|
and warn "cammount failure: $!\n";
|
|
|
|
warn "Failed to unmount\n" unless try_unmount();
|
2012-03-19 06:58:36 +00:00
|
|
|
|
2012-03-27 17:37:21 +00:00
|
|
|
sub try_unmount {
|
2013-07-10 11:27:54 +00:00
|
|
|
if ($^O eq "darwin") {
|
|
|
|
print "Try unmount darwin...\n";
|
|
|
|
unless (`df -n` =~ /\Q$dir\E/) {
|
|
|
|
print "Not mounted.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
print "Running: diskutil unmount force $dir ...\n";
|
|
|
|
return system("diskutil", "umount", "force", $dir) == 0;
|
|
|
|
}
|
2012-03-27 17:37:21 +00:00
|
|
|
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;
|
|
|
|
}
|