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;
|
2013-07-15 11:29:00 +00:00
|
|
|
my $opt_xterm;
|
2013-07-20 17:18:18 +00:00
|
|
|
my $opt_verbose;
|
2013-07-15 11:29:00 +00:00
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
"xterm" => \$opt_xterm,
|
2013-07-20 17:18:18 +00:00
|
|
|
"verbose" => \$opt_verbose,
|
2013-07-15 11:29:00 +00:00
|
|
|
) or usage();
|
2012-04-29 04:29:51 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
|
2013-07-21 05:37:21 +00:00
|
|
|
# Respected by env expansions in config/dev-client-dir/client-config.json
|
2013-07-10 09:34:58 +00:00
|
|
|
$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-15 11:29:00 +00:00
|
|
|
print "############################################################################\n## Press 'q' <enter> to shut down.\n##\n";
|
2013-07-10 11:27:54 +00:00
|
|
|
|
2013-07-15 11:29:00 +00:00
|
|
|
exec("$cammount",
|
|
|
|
"--xterm=" . ($opt_xterm ? "true" : "false"),
|
2013-07-20 17:18:18 +00:00
|
|
|
"--debug=" . ($opt_verbose ? "true" : "false"),
|
2013-07-15 11:29:00 +00:00
|
|
|
"--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") {
|
|
|
|
unless (`df -n` =~ /\Q$dir\E/) {
|
|
|
|
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;
|
|
|
|
}
|