-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from EugenMayer/precondition_strategy
implemented precondition os based strategy, implemented brew being ma…
- Loading branch information
Showing
21 changed files
with
418 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.3 | ||
0.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'docker-sync/config/config_locator' | ||
require 'docker-sync/config/global_config' | ||
require 'docker-sync/config/project_config' | ||
require 'docker-sync/preconditions' | ||
require 'docker-sync/preconditions/strategy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module DockerSync | ||
module Preconditions | ||
class Linux | ||
def check_all_preconditions(config) | ||
end | ||
|
||
def docker_available | ||
end | ||
|
||
def docker_running | ||
end | ||
|
||
def fswatch_available | ||
end | ||
|
||
def rsync_available | ||
end | ||
|
||
def unison_available | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
require 'mkmf' | ||
module DockerSync | ||
module Preconditions | ||
class Osx | ||
def check_all_preconditions(config) | ||
return unless should_run_precondition? | ||
|
||
docker_available | ||
docker_running | ||
|
||
if config.unison_required? | ||
unison_available | ||
end | ||
|
||
if config.rsync_required? | ||
rsync_available | ||
fswatch_available | ||
end | ||
end | ||
|
||
def 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 | ||
|
||
def 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 | ||
|
||
def rsync_available | ||
if should_run_precondition? | ||
if (find_executable0 'rsync').nil? | ||
raise('Could not find rsync binary in path. Please install it, e.g. using "brew install rsync"') | ||
end | ||
end | ||
end | ||
|
||
def unison_available | ||
if should_run_precondition? | ||
if (find_executable0 'unison').nil? | ||
cmd1 = 'brew install unison"' | ||
|
||
Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison binary in $PATH. Trying to install now', :red | ||
if Thor::Shell::Basic.new.yes?('I will install unison using brew for you? (y/N)') | ||
system cmd1 | ||
else | ||
raise('Please install it yourself using: brew install unison') | ||
end | ||
end | ||
|
||
unox_available | ||
end | ||
end | ||
|
||
def fswatch_available | ||
if should_run_precondition? | ||
if (find_executable0 'fswatch').nil? | ||
cmd1 = 'brew install fswatch"' | ||
|
||
Thor::Shell::Basic.new.say_status 'warning', 'No fswatch available. Install it by "brew install fswatch Trying to install now', :red | ||
if Thor::Shell::Basic.new.yes?('I will install fswatch using brew for you? (y/N)') | ||
system cmd1 | ||
else | ||
raise('Please install it yourself using: brew install fswatch') | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
private | ||
|
||
def should_run_precondition?(silent = false) | ||
unless has_brew? | ||
Thor::Shell::Basic.new.say_status 'inf', 'Not running any precondition checks since you have no brew and that is unsupported. Is all up to you know.', :white unless silent | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
def has_brew? | ||
return find_executable0 'brew' | ||
end | ||
|
||
|
||
def unox_available | ||
if should_run_precondition? | ||
`brew list unox` | ||
if $?.exitstatus > 0 | ||
unless (find_executable0 'unison-fsmonitor').nil? | ||
# unox installed, but not using brew, we do not allow that anymore | ||
Thor::Shell::Basic.new.say_status 'error', 'You install unison-fsmonitor (unox) not using brew. Please uninstall it and run docker-sync again, so we can install it for you', :red | ||
exit 1 | ||
end | ||
cmd1 = 'brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox' | ||
|
||
Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison-fsmonitor (unox) binary in $PATH. Trying to install now', :red | ||
if Thor::Shell::Basic.new.yes?('I will install unox through brew for you? (y/N)') | ||
system cmd1 | ||
else | ||
raise('Please install it yourself using: brew tap eugenmayer/dockersync && brew install unox') | ||
end | ||
end | ||
end | ||
end | ||
|
||
def install_pip(package, test = nil) | ||
test ? `python -c 'import #{test}'` : `python -c 'import #{package}'` | ||
|
||
unless $?.success? | ||
Thor::Shell::Basic.new.say_status 'warning', "Could not find #{package}. Will try to install it using pip", :red | ||
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 #{package}" | ||
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 #{package}" | ||
end | ||
if sudo | ||
question = "I will ask you for you root password to install #{package} by running (This will ask for sudo, since we use the system python)" | ||
else | ||
question = "I will now install #{package} 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 #{package}, please file an issue with the output of the error") | ||
end | ||
test ? `python -c 'import #{test}'` : `python -c 'import #{package}'` | ||
unless $?.success? | ||
raise("Somehow I could not successfully install #{package} even though I tried. Please report this issue.") | ||
end | ||
else | ||
raise("Please install #{package} manually, see https://github.com/EugenMayer/docker-sync/wiki/1.-Installation") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.