[scripts] Change default timeout of ssh-add

pull/28/head
Alpha Chen 9 years ago
parent 720f5e053d
commit 89a5c3268f

@ -2,17 +2,17 @@
require 'optparse' require 'optparse'
# Default to a one hour timeout timeout = [12*60+30, 18*60+00].map { |timeout|
timeout = 1 now = Time.now
unit = ?H timeout - (now.hour*60 + now.min)
}.find(60*60) {|timeout| timeout > 0 }
timeout = timeout.divmod(60).zip(%w[ h m ]).map(&:join).join
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options]" opts.banner = "Usage: #{__FILE__} [options]"
opts.on("-tTIMEOUT", "--t=TIMEOUT", opts.on("-tTIMEOUT", "--t=TIMEOUT",
"Default timeout: #{timeout}") { |t| timeout = t.to_i } "Default timeout: #{timeout}") { |t| timeout = t }
opts.on("-uUNIT", "--u=UNIT",
"Default unit: #{unit}") { |u| unit = u }
end.parse! end.parse!
def with_mount(image) def with_mount(image)
@ -25,6 +25,6 @@ end
keyz = File.expand_path("../keyz.sparsebundle", __FILE__) keyz = File.expand_path("../keyz.sparsebundle", __FILE__)
with_mount(keyz) do |mountpoint| with_mount(keyz) do |mountpoint|
`ssh-add -t #{timeout}#{unit} "#{File.join(mountpoint, "id_rsa")}"` `ssh-add -t #{timeout} "#{File.join(mountpoint, "id_rsa")}"`
end end
# `hdiutil eject "#{File.dirname(__FILE__)}"` # `hdiutil eject "#{File.dirname(__FILE__)}"`

Loading…
Cancel
Save