Module: Preconditions

Defined in:
lib/docker-sync/preconditions.rb

Class Method Summary collapse

Class Method Details

.check_all_preconditionsObject



4
5
6
7
8
# File 'lib/docker-sync/preconditions.rb', line 4

def self.check_all_preconditions
  docker_available
  docker_running
  fswatch_available
end

.docker_availableObject



10
11
12
13
14
# File 'lib/docker-sync/preconditions.rb', line 10

def self.docker_available
  if (find_executable0 'docker').nil?
    raise('Could not find docker binary in path. Please install it, e.g. using "brew install docker" or install docker-for-mac')
  end
end

.docker_runningObject



16
17
18
19
20
21
# File 'lib/docker-sync/preconditions.rb', line 16

def self.docker_running
  `docker ps`
  if $?.exitstatus > 0
    raise('No docker daemon seems to be running. Did you start your docker-for-mac / docker-machine?')
  end
end

.docker_sync_availableObject



29
30
31
32
33
# File 'lib/docker-sync/preconditions.rb', line 29

def self.docker_sync_available
  if (find_executable0 'docker-sync').nil?
    raise('No docker-sync available. Install it by "gem install docker-sync"')
  end
end

.fswatch_availableObject



23
24
25
26
27
# File 'lib/docker-sync/preconditions.rb', line 23

def self.fswatch_available
  if (find_executable0 'fswatch').nil?
    raise('No fswatch available. Install it by "brew install fswatch"')
  end
end

.rsync_availableObject



35
36
37
38
39
# File 'lib/docker-sync/preconditions.rb', line 35

def self.rsync_available
  if (find_executable0 'rsync').nil?
    raise('Could not find rsync binary in path. Please install it, e.g. using "brew install rsync"')
  end
end

.unison_availableObject



41
42
43
44
45
# File 'lib/docker-sync/preconditions.rb', line 41

def self.unison_available
  if (find_executable0 'unison').nil?
    raise('Could not find unison binary in path. Please install it, e.g. using "brew install unison"')
  end
end

.unox_availableObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/docker-sync/preconditions.rb', line 47

def self.unox_available
  if (find_executable0 'unison-fsmonitor').nil?
    cmd1 = 'curl "https://raw.githubusercontent.com/hnsl/unox/master/unox.py" -o "/usr/local/bin/unison-fsmonitor" \
    && chmod +x /usr/local/bin/unison-fsmonitor'
    cmd2 = 'sudo easy_install pip && sudo pip install macfsevents'
    Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison-fsmonitor (for file watching) binary in $PATH. Please install unox before you continue, see https://github.com/hnsl/unox.', :yellow
    if Thor::Shell::Basic.new.yes?('Shall I install unison-fsmonitor for you? ')
      system cmd1
      if $?.exitstatus > 0
        raise('Failed to install unison-fsmonitor, please file an issue with the output of the error')
      end
      Thor::Shell::Basic.new.say_status 'ok','install macfsevents using pip (This will ask for sudo, since we use the system python)', :yellow
      system cmd2
      if $?.exitstatus > 0
        raise('Failed to install macfsevents, please file an issue with the output of the error')
      end
    else
      raise("Please install it, see https://github.com/hnsl/unox, or simply run :\n #{cmd1} && #{cmd2}")
    end
  end
end