Last active
September 12, 2017 09:22
-
-
Save pooza/a1606b5fd6a6432290a40330ff541302 to your computer and use it in GitHub Desktop.
引数に指定した仮想マシンのホームディレクトリをsshfsでマウント。元記事→https://blog.b-shock.org/2017/09/07/sshfs/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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