added pod
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Mon, 25 Jul 2011 17:16:07 +0200
changeset 12 46a3e65e850f
parent 11 675ef249d116
child 13 b767ab4b0888
added pod
fuse
--- a/fuse	Mon Jul 25 16:36:53 2011 +0200
+++ b/fuse	Mon Jul 25 17:16:07 2011 +0200
@@ -6,28 +6,56 @@
 use autodie qw(:all);
 use Getopt::Long;
 use Fuse;
+use POSIX qw(setpgid);
+use Pod::Usage;
+use Hash::Util qw(lock_keys);
+use File::Basename;
 
-my $opt_debug = 0;
+my %o = (
+    debug => undef,
+    detach => 1,
+); lock_keys %o;
+
+use constant ME => basename $0;
 
-GetOptions("debug!" => \$opt_debug)
-	and @ARGV == 2
-	or die "Bad Usage\n";
+MAIN: {
 
-my $src = shift;
-my $mp = shift;
+    GetOptions(
+	"d|debug!" => \$o{debug},
+	"detach!" => \$o{detach},
+	"h|help" => sub { pod2usage(-verbose => 1, -exit => 0) },
+	"m|man" =>  sub { pod2usage(-verbose => 2, -exit => 0,
+		-noperlpod => system("perldoc -V 1>/dev/null 2>&1")) },
+	) and @ARGV == 2 or pod2usage;
+
+    my ($src, $mp) = @ARGV;
 
-$fs::DATA = "$src/data";
-$fs::IDX = "$src/idx";
+    $fs::DATA = "$src/data";
+    $fs::IDX = "$src/idx";
+
+    die ME.": $fs::DATA: $!" if not -d $fs::DATA;
+    die ME.": $fs::IDX: $!" if not -d $fs::IDX;
+
+    if (!$o{debug} and $o{detach}) {
+	fork() and exit;
+	$0 = "FUSE $src $mp";
+	open(STDOUT => ">/dev/null");
+	open(STDIN => "/dev/null");
 
-Fuse::main(mountpoint => $mp,
-    debug => $opt_debug,
-    getattr => "fs::getattr",
-    getdir => "fs::getdir",
-    open => "fs::openfile",
-    read => "fs::readbuffer",
-    write => "fs::writebuffer",
-    );
+	setpgid($$ => $$);
+    }
+
 
+    Fuse::main(mountpoint => $mp,
+	debug => $o{debug} // 0,
+	getattr => "fs::getattr",
+	getdir => "fs::getdir",
+	open => "fs::openfile",
+	read => "fs::readbuffer",
+	write => "fs::writebuffer",
+	);
+
+}
 
 { package fs;
   use strict;
@@ -179,3 +207,41 @@
     }
 
 }
+
+__END__
+
+=head1 NAME
+
+    fuse - the fuse mount helper for imagers backups
+
+=head1 SYNOPSIS
+
+    fuse [options] {src} {mount point}
+
+=head1 DESCRIPTION
+
+B<fuse> mounts the src directory (containing F<data/> and F<idx/>
+directories) the the specified mount point.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-d>|B<--debug>
+
+Enables debugging output from B<Fuse>. When using this option,
+B<Fuse> does not detach from the terminal. (default: off)
+
+=item B<-->I<[no]>B<detach> 
+
+Detach or don't detach from the terminal. (default: detach)
+
+=item B<-h>|B<--help>
+
+=item B<-m>|B<--man>
+
+The common help and man options.
+
+=back
+
+=cut