From 69a4bcb292b9b340309020d6d8ee8e9b4905c919 Mon Sep 17 00:00:00 2001 From: glenux Date: Fri, 12 Jun 2009 15:49:30 +0000 Subject: [PATCH] sshfs-mapper: improved ruby version a bit. git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1389 eaee96b3-f302-0410-b096-c6cfd47f7835 --- map.rb | 8 +++++--- sshfs-mapper | 12 ++++++++++-- sshfs-mapper.rb | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/map.rb b/map.rb index 1d510b3..fb6a64a 100644 --- a/map.rb +++ b/map.rb @@ -1,12 +1,14 @@ module SshfsMapper class Map - def initialize + def initialize( map_path ) + @path = map_path @host = nil @port = 22 @user = nil - - end + def parse() + puts "Parsing #{@path}" + end end end diff --git a/sshfs-mapper b/sshfs-mapper index 702d4d0..ab0ee5b 100644 --- a/sshfs-mapper +++ b/sshfs-mapper @@ -59,6 +59,8 @@ do_usage() { Usage: `basename $0` [options] -h Show this help and exit. -i Initialize user configuration. +-l List available maps. +-s Only use specified map. -u Umount user maps. EOF exit 1 @@ -115,7 +117,6 @@ do SSHFS_MOUNT=0 ;; s) # only selected hosts - #SSHFS_HOST_SELECTION=1 SSHFS_HOST_PATTERN+="$OPTARG " SSHFS_HOST_LIMIT=1 ;; @@ -153,6 +154,13 @@ mountpoint=$( read_conf "$SSHFS_CONFIG" MOUNTPOINT ) exit 1; } +is_mounted() { + local map_name=$1 + + mount | grep -q " $mountpoint/$map_name " + return $? +} + for map_file in `find "$SSHFS_DIR" -type f -name '*.map' `; do if [ $SSHFS_HOST_LIST -eq 1 ]; then basename ${map_file/.map/} @@ -184,7 +192,7 @@ for map_file in `find "$SSHFS_DIR" -type f -name '*.map' `; do map_count=$(( ( $map_count + 1 ) % 2 )) [ $map_count = 0 ] && { echo " $map_name => $remote_dir" - if ! mount | grep -q " $mountpoint/$map_name " ; then + if ! is_mounted $map_name ; then [ $SSHFS_MOUNT = 1 ] && { mkdir -p $mountpoint/$map_name do_mount $remote_user@$remote_host:$remote_dir $mountpoint/$map_name $remote_port diff --git a/sshfs-mapper.rb b/sshfs-mapper.rb index 222b783..5a52a54 100755 --- a/sshfs-mapper.rb +++ b/sshfs-mapper.rb @@ -21,6 +21,7 @@ module SshfsMapper end @maps.each do |map_path| map = Map.new( map_path ) + map.parse() end puts "--run" end