Module: Preconditions

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

Class Method Summary collapse

Class Method Details

.check_all_preconditionsObject



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

def self.check_all_preconditions
  docker_available
  docker_running
  unison_available
  unox_available
  macfsevents_available
end

.docker_availableObject



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

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



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

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



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

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



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

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

.macfsevents_availableObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/docker-sync/preconditions.rb', line 64

def self.macfsevents_available
  `python -c 'import fsevents'`
  unless $?.success?
    Thor::Shell::Basic.new.say_status 'warning','Could not find macfsevents. Will try to install it using pip', :red
    sudo = false
    if find_executable0('python') == '/usr/bin/python'
      Thor::Shell::Basic.new.say_status 'ok','You seem to use the system python, we will need sudo below'
      sudo = true
      cmd2 = 'sudo easy_install pip && sudo pip install macfsevents'
    else
      Thor::Shell::Basic.new.say_status 'ok','You seem to have a custom python, using non-sudo commands'
      sudo = false
      cmd2 = 'easy_install pip && pip install macfsevents'
    end
    if sudo
      question = 'I will ask you for you root password to install macfsevent by running (This will ask for sudo, since we use the system python)'
    else
      question = 'I will now install macfsevents for you by running'
    end

    Thor::Shell::Basic.new.say_status 'info', "#{question}: `#{cmd2}\n\n"
    if Thor::Shell::Basic.new.yes?('Shall i continue? (y/N)')
      system cmd2
      if $?.exitstatus > 0
        raise('Failed to install macfsevents, please file an issue with the output of the error')
      end
      `python -c 'import fsevents'`
      unless $?.success?
        raise('Somehow could not successfully install macfsevents even though i treed. Please report this issue')
      end
    else
      raise('Please install macfsevents manually, see https://github.com/EugenMayer/docker-sync/wiki/1.-Installation')
    end
  end


end

.rsync_availableObject



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

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



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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/docker-sync/preconditions.rb', line 49

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'

    Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison-fsmonitor (for file watching) binary in $PATH. We try to install unox now (for manual instracutions see https://github.com/hnsl/unox.)', :red
    if Thor::Shell::Basic.new.yes?('Shall I install unison-fsmonitor for you? (y/N)')
      system cmd1
    else
      raise("Please install it, see https://github.com/hnsl/unox, or simply run :\n #{cmd1} && #{cmd2}")
    end
  end

end