From f714f688abce6050fecdc754ec7c731d5e0a1c94 Mon Sep 17 00:00:00 2001 From: glenux Date: Tue, 15 Mar 2011 16:55:16 +0000 Subject: [PATCH] sshfs-mapper map: Replace environment variables in map descriptions. git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1664 eaee96b3-f302-0410-b096-c6cfd47f7835 --- sshfs-mapper/map.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sshfs-mapper/map.rb b/sshfs-mapper/map.rb index 724ce12..ed3fb53 100644 --- a/sshfs-mapper/map.rb +++ b/sshfs-mapper/map.rb @@ -28,7 +28,7 @@ module SshfsMapper @user = nil @cypher = :arcfour @maps = {} - @debug = false + @debug = true self.load @path end @@ -38,10 +38,18 @@ module SshfsMapper rdebug "Parsing map #{@path}" f = File.open @path linect = 0 + local_env = ENV.clone f.each do |line| line = line.strip linect += 1 + while line =~ /\$(.*)/ do + pattern = $1 + puts "FOUND PATTERN %s => %s" % [$1, local_env[$1]] + line.gsub!(/\$#{pattern}/,local_env[$1]) + line.gsub!(/\$\{#{pattern}\}/,local_env[$1]) + end + case line when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then @user = $1 @@ -71,7 +79,7 @@ module SshfsMapper def write path=nil @path=path unless path.nil? - File.open @path, "w" do |f| + File.open(@path, "w") do |f| f.puts "REMOTE_USER=%s" % @user f.puts "REMOTE_PORT=%s" % @port f.puts "REMOTE_HOST=%s" % @host @@ -79,7 +87,8 @@ module SshfsMapper end end - def alive? + def online? + rdebug "testing online? %s " % self.inspect #FIXME: test liveness end