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
This commit is contained in:
Glenn Y. Rolland 2011-03-15 16:55:16 +00:00
parent 37cb6633f3
commit 9a480130ab

View file

@ -28,7 +28,7 @@ module SshfsMapper
@user = nil @user = nil
@cypher = :arcfour @cypher = :arcfour
@maps = {} @maps = {}
@debug = false @debug = true
self.load @path self.load @path
end end
@ -38,10 +38,18 @@ module SshfsMapper
rdebug "Parsing map #{@path}" rdebug "Parsing map #{@path}"
f = File.open @path f = File.open @path
linect = 0 linect = 0
local_env = ENV.clone
f.each do |line| f.each do |line|
line = line.strip line = line.strip
linect += 1 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 case line
when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then
@user = $1 @user = $1
@ -71,7 +79,7 @@ module SshfsMapper
def write path=nil def write path=nil
@path=path unless 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_USER=%s" % @user
f.puts "REMOTE_PORT=%s" % @port f.puts "REMOTE_PORT=%s" % @port
f.puts "REMOTE_HOST=%s" % @host f.puts "REMOTE_HOST=%s" % @host
@ -79,7 +87,8 @@ module SshfsMapper
end end
end end
def alive? def online?
rdebug "testing online? %s " % self.inspect
#FIXME: test liveness #FIXME: test liveness
end end