Module: DockerSync::Dependencies::Unox

Extended by:
Forwardable
Defined in:
lib/docker-sync/dependencies/unox.rb

Constant Summary collapse

LEGACY_UNOX_WARNING =
'You installed unison-fsmonitor (unox) the old legacy way (i.e. not using brew). We need to fix that.'.freeze
FAILED_TO_REMOVE_LEGACY_UNOX =
'Failed to remove legacy unison-fsmonitor (unox). Please delete /usr/local/bin/unison-fsmonitor manually and try again.'.freeze

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/docker-sync/dependencies/unox.rb', line 14

def self.available?
  # should never have been called anyway - fix the call that it should check for the OS
  raise 'Unox cannot be available for other platforms then MacOS' unless Environment.mac?

  return @available if defined? @available
  cmd = 'brew list unox 2>&1 > /dev/null'
  @available = Environment.system(cmd)
  @available
end

.cleanup_non_brew_version!Object



32
33
34
35
36
37
38
39
# File 'lib/docker-sync/dependencies/unox.rb', line 32

def self.cleanup_non_brew_version!
  return unless non_brew_version_installed?
  uninstall_cmd = 'sudo rm -f /usr/local/bin/unison-fsmonitor'
  say_status 'warning', LEGACY_UNOX_WARNING, :yellow
  raise(FAILED_TO_REMOVE_LEGACY_UNOX) unless yes?('Uninstall legacy unison-fsmonitor (unox)? (y/N)')
  say_status 'command', uninstall_cmd, :white
  Environment.system(uninstall_cmd)
end

.ensure!Object



24
25
26
27
28
29
30
# File 'lib/docker-sync/dependencies/unox.rb', line 24

def self.ensure!
  return if available?
  raise 'Unox cannot be installed on other platforms then MacOS' unless Environment.mac?

  cleanup_non_brew_version!
  PackageManager.install_package('eugenmayer/dockersync/unox')
end

.non_brew_version_installed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/docker-sync/dependencies/unox.rb', line 41

def self.non_brew_version_installed?
  !available? && File.exist?('/usr/local/bin/unison-fsmonitor')
end