Skip to content

Instantly share code, notes, and snippets.

@pooza
Last active September 12, 2017 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pooza/a1606b5fd6a6432290a40330ff541302 to your computer and use it in GitHub Desktop.
Save pooza/a1606b5fd6a6432290a40330ff541302 to your computer and use it in GitHub Desktop.
引数に指定した仮想マシンのホームディレクトリをsshfsでマウント。元記事→https://blog.b-shock.org/2017/09/07/sshfs/
#!/usr/bin/env ruby
require 'socket'
require 'fileutils'
def get_fqdn (name)
parts = Socket.gethostname.split('.')
parts.unshift(name)
parts.push('local') unless parts.last == 'local'
return parts.join('.')
end
unless ARGV.first
puts '引数がないよ'
exit 1
end
name = ARGV.first
mountpoint = File.join(File.expand_path('~/mount'), name)
FileUtils.mkdir_p(mountpoint) unless Dir.exist?(mountpoint)
source = "#{get_fqdn(name)}:/home/#{ENV['USER']}"
command = ['sshfs', source, mountpoint]
puts command.join(' ')
system(*command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment