Sha256: 9cb3e5fb5eeb07dd5b2ee7c1a7ffbeff5772daae55f85875f0abc088741c4f74

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'forwardable'

module DockerSync
  module Dependencies
    module Unox
      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 << self
        extend Forwardable
        def_delegators :"Thor::Shell::Color.new", :say_status, :yes?
      end

      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 = defined?(Bundler) ? Bundler.clean_system(cmd) : system(cmd)
        @available
      end

      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

      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
        system(uninstall_cmd)
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docker-sync-0.5.11.pre.beta1 lib/docker-sync/dependencies/unox.rb