Skip to content
Browse files

added group capability

  • Loading branch information...
1 parent 02e5905 commit 62d179d273e7e5e0d07843c80b170d73591daf3a @jacoby committed Feb 27, 2012
Showing with 56 additions and 15 deletions.
  1. +20 −5 README
  2. +36 −10 mount.pl
View
25 README
@@ -18,17 +18,32 @@ Configuration is held in ~/.mount.conf, which looks like this :
### .mount.conf
# like many config files, hashes comment out
-Machine1 |M|sshfs|machine1.long.url: | /home/me/Machine1
-Machine2 | |sshfs|machine2.long.url: | /home/me/Machine2
+Machine1 |G|M|sshfs|machine1.long.url: | /home/me/Machine1
+Machine2 |G| |sshfs|machine2.long.url: | /home/me/Machine2
# ^ M indicates mounting via mount-all setting
-Machine2Log |M|sshfs|machine2.long.url:/var/log | /home/me/Machine2log
-
-
+Machine2Log |G|M|sshfs|machine2.long.url:/var/log | /home/me/Machine2log
The fields are:
Name - the name of this mountpoint, for individual mounting and unmounting
+ Group - the name of the group this mountpoint is in, to allow the mounting
+ and unmounting of specific groups of file systems
M - indicates whether this gets mounted on mount-all
Protocol - right now, only sshfs is supported
Remote - follows the SSHFS syntax for remote mounts:
network_address:/remote/file/system/if/any
Local - where the mount point is on the local file system
+
+
+Usage:
+ mount.pl
+ Mounts all
+ mount.pl -Q
+ Unmounts all
+ mount.pl -g Foo -g Bar
+ Mounts members of groups Foo and Bar
+ mount.pl -d Foo -d Bar
+ Unmounts members of groups Foo and Bar
+ mount.pl -m Blee -m Quuz
+ Mounts systems named Blee and Quuz
+ mount.pl -u Blee -u Quuz
+ Unounts systems named Blee and Quuz
View
46 mount.pl
@@ -12,11 +12,13 @@
# 2011/11 - DAJ - Added -o workaround=rename to allow GIT over
# sshfs
+# 2012/02 - DAJ - Added groups for mounting and dismounting
use 5.010 ;
use strict ;
use warnings ;
use Carp ;
+use Data::Dumper ;
use Getopt::Long ;
use IO::Interactive qw{ interactive } ;
use subs qw( mount unmount ) ;
@@ -33,19 +35,24 @@
my @mount ;
my %mountprog ;
my %protocol ;
+my $groups ;
my %remote ;
my @unmount ;
my $unmount ;
my $verbose ;
+my @group_mount ;
+my @group_unmount ;
$mountprog{ sshfs } = '/usr/bin/sshfs' ;
my $unmountprog = '/bin/fusermount' ;
GetOptions(
- 'mount=s' => \@mount,
- 'unmount=s' => \@unmount,
- 'quit' => \$unmount,
- 'verbose' => \$verbose,
+ 'mount=s' => \@mount,
+ 'unmount=s' => \@unmount,
+ 'group=s' => \@group_mount ,
+ 'dismount=s' => \@group_unmount ,
+ 'quit' => \$unmount,
+ 'verbose' => \$verbose,
) ;
# don't like the full hardcode
@@ -57,9 +64,10 @@
my $result = ( split m{\#}mx, $line )[ 0 ] ;
$line = $result ;
next if $line !~ m{\w}mx ;
- my ( $name, $flag, $protocol, $remote, $local ) = split m{\s*\|\s*}mx,
+ my ( $name, $group , $flag, $protocol, $remote, $local ) = split m{\s*\|\s*}mx,
$line ;
$name =~ s{\s}{}g ;
+ push @{ $groups->{ $group } } , $name ;
$local{ $name } = $local ;
$remote{ $name } = $remote ;
$protocol{ $name } = $protocol ;
@@ -75,7 +83,11 @@
}
# MOUNT EVERYTHING
-elsif ( ( $#mount == -1 ) && ( $#unmount == -1 ) ) {
+elsif ( ( $#mount == -1 ) &&
+ ( $#unmount == -1 ) &&
+ ( $#group_mount == -1 ) &&
+ ( $#group_unmount == -1 )
+ ) {
for my $mount ( sort { lc $a cmp lc $b } keys %local ) {
next unless $flag{ $mount } ;
mount $mount , $remote{ $mount }, $local{ $mount } ;
@@ -85,15 +97,29 @@
# MIXED MOUNTS AND UNMOUNTS
else {
- # mounts first
- for my $mount ( @mount ) {
- mount $mount , $remote{ $mount }, $local{ $mount } ;
+ # groups then individuals
+ # unmounts first
+ for my $group ( @group_unmount ) {
+ for my $mount ( @{ $groups->{ $group } } ) {
+ unmount $mount , $local{ $mount } ;
+ }
}
- # then unmounts
for my $mount ( @unmount ) {
unmount $mount , $local{ $mount } ;
}
+
+ # then mounts
+ for my $group ( @group_unmount ) {
+ for my $mount ( @{ $groups->{ $group } } ) {
+ next unless $flag{ $mount } ;
+ mount $mount , $remote{ $mount }, $local{ $mount } ;
+ }
+ }
+
+ for my $mount ( @mount ) {
+ mount $mount , $remote{ $mount }, $local{ $mount } ;
+ }
}
exit 0 ;

0 comments on commit 62d179d

Please sign in to comment.
Something went wrong with that request. Please try again.