From c2c00b69be8b69c523f2c951db58494561618274 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 20 Jan 2016 07:55:53 -0800 Subject: [PATCH] [ssh] Add ssh-add script --- scripts/ssh-add | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/ssh-add diff --git a/scripts/ssh-add b/scripts/ssh-add new file mode 100755 index 0000000..13d260d --- /dev/null +++ b/scripts/ssh-add @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby + +require 'optparse' + +# Default to a five minute timeout +timeout = 5 +unit = ?M + +OptionParser.new do |opts| + opts.banner = "Usage: #{__FILE__} [options]" + + opts.on("-tTIMEOUT", "--t=TIMEOUT", + "Default timeout: #{timeout}") { |t| timeout = t.to_i } + opts.on("-uUNIT", "--u=UNIT", + "Default unit: #{unit}") { |u| unit = u } +end.parse! + +def with_mount(image) + out = `hdiutil mount "#{image}"` + mountpoint = out.split(/\s+/).last + yield mountpoint +ensure + puts `hdiutil unmount "#{mountpoint}"` +end + +keyz = File.expand_path("../keyz.sparsebundle", __FILE__) +with_mount(keyz) do |mountpoint| + `ssh-add -t #{timeout}#{unit} "#{File.join(mountpoint, "id_rsa")}"` +end