Skip to content
This repository has been archived by the owner on May 22, 2018. It is now read-only.

Commit

Permalink
fix offline check for run
Browse files Browse the repository at this point in the history
  • Loading branch information
wfarr committed Mar 7, 2014
1 parent d9a7850 commit 06fe5ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/boxen/command/run.rb
Expand Up @@ -2,14 +2,15 @@

class Boxen::Command::Run < Boxen::Command
preflight \
Boxen::Preflight::Creds,
Boxen::Preflight::OS,
Boxen::Preflight::Directories,
Boxen::Preflight::EtcMyCnf,
Boxen::Preflight::Homebrew,
Boxen::Preflight::Identity,
Boxen::Preflight::OS,
Boxen::Preflight::Rbenv,
Boxen::Preflight::RVM
Boxen::Preflight::RVM,
Boxen::Preflight::Offline,
Boxen::Preflight::Creds,
Boxen::Preflight::Identity

postflight \
Boxen::Postflight::Active,
Expand Down Expand Up @@ -48,7 +49,7 @@ def run
create_clean_working_environment
run_librarian_puppet

warn command.join(" ") if config.debug?
warn command.join(" ") if debug?

puts "Running puppet"
Boxen::Util.sudo(*command)
Expand Down Expand Up @@ -99,9 +100,9 @@ def run_librarian_puppet
end

librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
librarian_command << "--verbose" if config.debug?
librarian_command << "--verbose" if debug?

warn librarian_command.join(" ") if config.debug?
warn librarian_command.join(" ") if debug?
unless system(*librarian_command)
abort "Can't run Puppet, fetching dependencies with librarian failed."
end
Expand Down Expand Up @@ -164,14 +165,15 @@ def puppet_flags

class Boxen::Command::Run::Noop < Boxen::Command::Run
preflight \
Boxen::Preflight::Creds,
Boxen::Preflight::OS,
Boxen::Preflight::Directories,
Boxen::Preflight::EtcMyCnf,
Boxen::Preflight::Homebrew,
Boxen::Preflight::Identity,
Boxen::Preflight::OS,
Boxen::Preflight::Rbenv,
Boxen::Preflight::RVM
Boxen::Preflight::RVM,
Boxen::Preflight::Offline,
Boxen::Preflight::Creds,
Boxen::Preflight::Identity

postflight \
Boxen::Postflight::Active,
Expand All @@ -180,7 +182,6 @@ class Boxen::Command::Run::Noop < Boxen::Command::Run
def noop
true
end

end

Boxen::Command.register :run, Boxen::Command::Run
Expand Down
32 changes: 32 additions & 0 deletions lib/boxen/preflight/offline.rb
@@ -0,0 +1,32 @@
require "boxen/preflight"

class Boxen::Preflight::Offline < Boxen::Preflight
SUPPORTED_RELEASES = %w(10.8 10.9)

def ok?
config.offline = !google_reachable?

warn "Running boxen in offline mode as we couldn't reach google." if config.offline?

true
end

def run
end

private

def google_reachable?
@online = begin
timeout(1) do
s = TCPSocket.new('google.com', 80)
s.close
end
true
rescue Errno::ECONNREFUSED
true
rescue Timeout::Error, StandardError
false
end
end
end

0 comments on commit 06fe5ac

Please sign in to comment.