vagrant-guest-cygwin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 037bef301ae967da1cf5d21154a3f0e03427fa0d57865d886fddef7b3bc76736
4
+ data.tar.gz: ad5e9dc42b31c93a72299934e0e0b60a5684b50a367a81d1f5a60f97d172bacb
5
+ SHA512:
6
+ metadata.gz: 73e1c0fd3a1c8966e6dec8204e1d67a4056f3463b7b69123c21a2eeeb1819c35cc02583f3dedc17beb2e41bd527bd023c1ffee1177dda774325154b3da64587e
7
+ data.tar.gz: 87dd8057e3150e00995bfec6f7dcdaf636b9017a369c6d7f718ae5bc9707eb774f56083e0cab3b0fe1e70275fbbf0552aad31272feadfd512a3727e1f3096af5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vagrant-guest-cygwin-*.gem
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in vagrant-guest-cygwin.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
10
+ end
11
+ group :plugins do
12
+ gem "vagrant-guest-cygwin", path: "."
13
+ end
14
+
15
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # vagrant-guest-cygwin
2
+
3
+ This is plugin for vagrant which adds support for cygwin guest.
4
+ Code is based on vagrant's build-in linux guest (with some modifications and unsupported caps removed).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,79 @@
1
+ module VagrantPlugins
2
+ module GuestCygwin
3
+ module Cap
4
+ class FileSystem
5
+ # Create a temporary file or directory on the guest
6
+ #
7
+ # @param [Vagrant::Machine] machine Vagrant guest machine
8
+ # @param [Hash] opts Path options
9
+ # @return [String] path to temporary file or directory
10
+ def self.create_tmp_path(machine, opts)
11
+ template = "vagrant-XXXXXX"
12
+ if opts[:extension]
13
+ template << opts[:extension].to_s
14
+ end
15
+ cmd = ["mktemp", "--tmpdir"]
16
+ if opts[:type] == :directory
17
+ cmd << "-d"
18
+ end
19
+ cmd << template
20
+ tmp_path = ""
21
+ machine.communicate.execute(cmd.join(" ")) do |type, data|
22
+ if type == :stdout
23
+ tmp_path << data
24
+ end
25
+ end
26
+ tmp_path.strip
27
+ end
28
+
29
+ # Decompress tgz file on guest to given location
30
+ #
31
+ # @param [Vagrant::Machine] machine Vagrant guest machine
32
+ # @param [String] compressed_file Path to compressed file on guest
33
+ # @param [String] destination Path for decompressed files on guest
34
+ def self.decompress_tgz(machine, compressed_file, destination, opts={})
35
+ comm = machine.communicate
36
+ extract_dir = create_tmp_path(machine, type: :directory)
37
+ cmds = []
38
+ if opts[:type] == :directory
39
+ cmds << "mkdir -p '#{destination}'"
40
+ else
41
+ cmds << "mkdir -p '#{File.dirname(destination)}'"
42
+ end
43
+ cmds += [
44
+ "tar -C '#{extract_dir}' -xzf '#{compressed_file}'",
45
+ "mv '#{extract_dir}'/* '#{destination}'",
46
+ "rm -f '#{compressed_file}'",
47
+ "rm -rf '#{extract_dir}'"
48
+ ]
49
+ cmds.each{ |cmd| comm.execute(cmd) }
50
+ true
51
+ end
52
+
53
+ # Decompress zip file on guest to given location
54
+ #
55
+ # @param [Vagrant::Machine] machine Vagrant guest machine
56
+ # @param [String] compressed_file Path to compressed file on guest
57
+ # @param [String] destination Path for decompressed files on guest
58
+ def self.decompress_zip(machine, compressed_file, destination, opts={})
59
+ comm = machine.communicate
60
+ extract_dir = create_tmp_path(machine, type: :directory)
61
+ cmds = []
62
+ if opts[:type] == :directory
63
+ cmds << "mkdir -p '#{destination}'"
64
+ else
65
+ cmds << "mkdir -p '#{File.dirname(destination)}'"
66
+ end
67
+ cmds += [
68
+ "unzip '#{compressed_file}' -d '#{extract_dir}'",
69
+ "mv '#{extract_dir}'/* '#{destination}'",
70
+ "rm -f '#{compressed_file}'",
71
+ "rm -rf '#{extract_dir}'"
72
+ ]
73
+ cmds.each{ |cmd| comm.execute(cmd) }
74
+ true
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,62 @@
1
+ require "tempfile"
2
+
3
+ require "vagrant/util/shell_quote"
4
+
5
+ module VagrantPlugins
6
+ module GuestCygwin
7
+ module Cap
8
+ class PublicKey
9
+ def self.insert_public_key(machine, contents)
10
+ comm = machine.communicate
11
+ contents = contents.strip << "\n"
12
+
13
+ remote_path = "/tmp/vagrant-insert-pubkey-#{Time.now.to_i}"
14
+ Tempfile.open("vagrant-linux-insert-public-key") do |f|
15
+ f.binmode
16
+ f.write(contents)
17
+ f.fsync
18
+ f.close
19
+ comm.upload(f.path, remote_path)
20
+ end
21
+
22
+ # Use execute (not sudo) because we want to execute this as the SSH
23
+ # user (which is "vagrant" by default).
24
+ comm.execute <<-EOH.gsub(/^ */, "")
25
+ mkdir -p ~/.ssh
26
+ chmod 0700 ~/.ssh
27
+ cat '#{remote_path}' >> ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
28
+ result=$?
29
+ rm -f '#{remote_path}'
30
+ exit $result
31
+ EOH
32
+ end
33
+
34
+ def self.remove_public_key(machine, contents)
35
+ comm = machine.communicate
36
+ contents = contents.strip << "\n"
37
+
38
+ remote_path = "/tmp/vagrant-remove-pubkey-#{Time.now.to_i}"
39
+ Tempfile.open("vagrant-linux-remove-public-key") do |f|
40
+ f.binmode
41
+ f.write(contents)
42
+ f.fsync
43
+ f.close
44
+ comm.upload(f.path, remote_path)
45
+ end
46
+
47
+ # Use execute (not sudo) because we want to execute this as the SSH
48
+ # user (which is "vagrant" by default).
49
+ comm.execute <<-EOH.sub(/^ */, "")
50
+ if test -f ~/.ssh/authorized_keys; then
51
+ grep -v -x -f '#{remote_path}' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.tmp
52
+ mv ~/.ssh/authorized_keys.tmp ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
53
+ result=$?
54
+ fi
55
+ rm -f '#{remote_path}'
56
+ exit $result
57
+ EOH
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,44 @@
1
+ module VagrantPlugins
2
+ module GuestCygwin
3
+ module Cap
4
+ class RSync
5
+ def self.rsync_installed(machine)
6
+ machine.communicate.test("which rsync")
7
+ end
8
+
9
+ def self.rsync_command(machine)
10
+ "sudo rsync"
11
+ end
12
+
13
+ def self.rsync_pre(machine, opts)
14
+ guest_path = Shellwords.escape(opts[:guestpath])
15
+ machine.communicate.sudo("mkdir -p #{guest_path}")
16
+ end
17
+
18
+ def self.rsync_post(machine, opts)
19
+ if opts.key?(:chown) && !opts[:chown]
20
+ return
21
+ end
22
+
23
+ machine.communicate.sudo(build_rsync_chown(opts))
24
+ end
25
+
26
+ def self.build_rsync_chown(opts)
27
+ guest_path = Shellwords.escape(opts[:guestpath])
28
+ if(opts[:exclude] && !Array(opts[:exclude]).empty?)
29
+ exclude_base = Pathname.new(opts[:guestpath])
30
+ exclusions = Array(opts[:exclude]).map do |ex_path|
31
+ ex_path = ex_path.slice(1, ex_path.size) if ex_path.start_with?(File::SEPARATOR)
32
+ "-path #{Shellwords.escape(exclude_base.join(ex_path))} -prune"
33
+ end.join(" -o ") + " -o "
34
+ end
35
+ # in cygwin group does not automatically exists for user (so ignore group)
36
+ "find #{guest_path} #{exclusions}" \
37
+ "'!' -type l -a " \
38
+ "'(' ! -user #{opts[:owner]} ')' -exec " \
39
+ "chown #{opts[:owner]} '{}' +"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ module VagrantPlugins
2
+ module GuestCygwin
3
+ module Cap
4
+ class ShellExpandGuestPath
5
+ def self.shell_expand_guest_path(machine, path)
6
+ real_path = nil
7
+ path = path.gsub(/ /, '\ ')
8
+ machine.communicate.execute("echo; printf #{path}") do |type, data|
9
+ if type == :stdout
10
+ real_path ||= ""
11
+ real_path += data
12
+ end
13
+ end
14
+
15
+ if real_path
16
+ # The last line is the path we care about
17
+ real_path = real_path.split("\n").last.chomp
18
+ end
19
+
20
+ if !real_path
21
+ # If no real guest path was detected, this is really strange
22
+ # and we raise an exception because this is a bug.
23
+ raise Vagrant::Errors::ShellExpandFailed
24
+ end
25
+
26
+ # Chomp the string so that any trailing newlines are killed
27
+ return real_path.chomp
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module GuestCygwin
3
+ class Guest < Vagrant.plugin("2", :guest)
4
+ # Name used for guest detection
5
+ GUEST_DETECTION_NAME = "cygwin".freeze
6
+
7
+ def detect?(machine)
8
+ machine.communicate.test("uname | grep -i cygwin")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestCygwin
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Cygwin guest."
7
+ description "Cygwin guest support."
8
+
9
+ guest(:cygwin) do
10
+ require_relative "guest"
11
+ Guest
12
+ end
13
+
14
+ guest_capability(:cygwin, :create_tmp_path) do
15
+ require_relative "cap/file_system"
16
+ Cap::FileSystem
17
+ end
18
+
19
+ guest_capability(:cygwin, :decompress_tgz) do
20
+ require_relative "cap/file_system"
21
+ Cap::FileSystem
22
+ end
23
+
24
+ guest_capability(:cygwin, :decompress_zip) do
25
+ require_relative "cap/file_system"
26
+ Cap::FileSystem
27
+ end
28
+
29
+ guest_capability(:cygwin, :insert_public_key) do
30
+ require_relative "cap/public_key"
31
+ Cap::PublicKey
32
+ end
33
+
34
+ guest_capability(:cygwin, :remove_public_key) do
35
+ require_relative "cap/public_key"
36
+ Cap::PublicKey
37
+ end
38
+
39
+ guest_capability(:cygwin, :shell_expand_guest_path) do
40
+ require_relative "cap/shell_expand_guest_path"
41
+ Cap::ShellExpandGuestPath
42
+ end
43
+
44
+ guest_capability(:cygwin, :rsync_installed) do
45
+ require_relative "cap/rsync"
46
+ Cap::RSync
47
+ end
48
+
49
+ guest_capability(:cygwin, :rsync_command) do
50
+ require_relative "cap/rsync"
51
+ Cap::RSync
52
+ end
53
+
54
+ guest_capability(:cygwin, :rsync_post) do
55
+ require_relative "cap/rsync"
56
+ Cap::RSync
57
+ end
58
+
59
+ guest_capability(:cygwin, :rsync_pre) do
60
+ require_relative "cap/rsync"
61
+ Cap::RSync
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module GuestCygwin
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant sshfs plugin must be run within Vagrant"
5
+ end
6
+
7
+ require "vagrant-guest-cygwin/version"
8
+ require "vagrant-guest-cygwin/plugin"
9
+
10
+ module VagrantPlugins
11
+ module GuestCygwin
12
+ # Returns the path to the source of this plugin
13
+ def self.source_root
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/vagrant-guest-cygwin/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vagrant-guest-cygwin"
7
+ spec.version = VagrantPlugins::GuestCygwin::VERSION
8
+ spec.authors = ["Zdenek Zambersky"]
9
+ spec.email = ["zzambers@redhat.com"]
10
+
11
+ spec.summary = "Vagrant cygwin guest plugin"
12
+ spec.description = "Plugin to add support for cygwin guest"
13
+ spec.homepage = "https://github.com/zzambers/vagrant-guest-cygwin"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/zzambers/vagrant-guest-cygwin/vagrant-guest-cygwin.git"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ # spec.bindir = "exe"
28
+ # spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-guest-cygwin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zdenek Zambersky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Plugin to add support for cygwin guest
14
+ email:
15
+ - zzambers@redhat.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - Rakefile
24
+ - lib/vagrant-guest-cygwin.rb
25
+ - lib/vagrant-guest-cygwin/cap/file_system.rb
26
+ - lib/vagrant-guest-cygwin/cap/public_key.rb
27
+ - lib/vagrant-guest-cygwin/cap/rsync.rb
28
+ - lib/vagrant-guest-cygwin/cap/shell_expand_guest_path.rb
29
+ - lib/vagrant-guest-cygwin/guest.rb
30
+ - lib/vagrant-guest-cygwin/plugin.rb
31
+ - lib/vagrant-guest-cygwin/version.rb
32
+ - vagrant-guest-cygwin.gemspec
33
+ homepage: https://github.com/zzambers/vagrant-guest-cygwin
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ allowed_push_host: https://rubygems.org
38
+ homepage_uri: https://github.com/zzambers/vagrant-guest-cygwin
39
+ source_code_uri: https://github.com/zzambers/vagrant-guest-cygwin/vagrant-guest-cygwin.git
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.4.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.2.22
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Vagrant cygwin guest plugin
59
+ test_files: []