bin/powder in powder-0.2.2 vs bin/powder in powder-0.3.0.pre

- old
+ new

@@ -19,10 +19,16 @@ map '-L' => 'link' map '-d' => 'default' map '-o' => 'open' map '-v' => 'version' + MAC_OS_X_VERSION_REGEXP = /^(?<major_version>\d+)\.(?<minor_version>\d+)\.(?<patch_version>\d+)/ + MAC_OS_X_MINOR_VERSION = begin + version_string = %x{sw_vers -productVersion} + version_string.match(MAC_OS_X_VERSION_REGEXP)[:minor_version].to_i + end + POWDER_CONFIG = ".powder" POW_ENV = ".powenv" POW_PATH = "#{ENV['HOME']}/.pow" POW_CONFIG = "#{ENV['HOME']}/.powconfig" POW_DAEMON_PLIST_PATH="#{ENV['HOME']}/Library/LaunchAgents/cx.pow.powd.plist" @@ -63,20 +69,15 @@ desc "prod", "An alias to production" alias :prod :production desc "up", "Enable pow" def up - if File.exists? POW_FIREWALL_PLIST_PATH - %x{sudo launchctl load #{POW_FIREWALL_PLIST_PATH}} + if MAC_OS_X_MINOR_VERSION >= 10 + start_on_yosemite else - say "Pow firewall configuration missing." + start_on_mavericks end - if File.exists? POW_DAEMON_PLIST_PATH - %x{launchctl load #{POW_DAEMON_PLIST_PATH}} - else - say "Pow daemon configuration missing." - end end desc "start", "An alias to up" alias :start :up @@ -84,25 +85,34 @@ def down if File.exists? POW_FIREWALL_PLIST_PATH if not %x{sudo launchctl list | grep cx.pow.firewall}.empty? %x{sudo launchctl unload #{POW_FIREWALL_PLIST_PATH}} end - if ports = File.open(POW_FIREWALL_PLIST_PATH).read.match(/fwd .*?,([\d]+).*?dst-port ([\d]+)/) - http_port, dst_port = ports[1..2] - end end if File.exists? POW_DAEMON_PLIST_PATH %x{launchctl unload #{POW_DAEMON_PLIST_PATH}} end - http_port ||= 20559 - dst_port ||= 80 + if MAC_OS_X_MINOR_VERSION < 10 + if File.exists? POW_FIREWALL_PLIST_PATH + if ports = File.open(POW_FIREWALL_PLIST_PATH).read.match(/fwd .*?,([\d]+).*?dst-port ([\d]+)/) + http_port, dst_port = ports[1..2] + end + end - if rule = %x{sudo ipfw show | grep ",#{http_port} .* dst-port #{dst_port} in"}.split.first - %x{sudo ipfw delete #{rule} && sudo sysctl -w net.inet.ip.forwarding=0} + http_port ||= 20559 + dst_port ||= 80 + + if rule = %x{sudo ipfw show | grep ",#{http_port} .* dst-port #{dst_port} in"}.split.first + %x{sudo ipfw delete #{rule} && sudo sysctl -w net.inet.ip.forwarding=0} + end end + + if MAC_OS_X_MINOR_VERSION >= 10 + %{sudo pfctl -a "com.apple/250.PowFirewall" -F all} + end end desc "stop", "An alias to down" alias :stop :down @@ -163,11 +173,10 @@ def no_restarts return unless is_powable? FileUtils.rm_f Dir.glob('tmp/*restart.txt') end - desc "respawn", "Restart the pow process" def respawn %x{launchctl stop cx.pow.powd} end @@ -326,11 +335,11 @@ end desc "status", "Shows current pow status" def status http_port = ":" + configured_pow_http_port.to_s - results = %x{curl --silent -H host:pow localhost#{http_port}/status.json}.gsub(':','=>') + results = %x{curl --silent -H host:pow 127.0.0.1#{http_port}/status.json}.gsub(':','=>') return say("Error: Cannot get Pow status. Pow may be down. Try 'powder up' first.") if results.empty? || !(results =~ /^\{/) json = eval results json.each {|k,v| say "#{k.ljust(12, ' ')} #{v}"} end @@ -516,8 +525,26 @@ http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) http.request(request).body end + + def start_on_yosemite + return say "Pow daemon configuration missing." unless File.exists?(POW_DAEMON_PLIST_PATH) + %x{launchctl bootstrap gui/"$UID" #{POW_DAEMON_PLIST_PATH}} + + %x{launchctl enable gui/"$UID"/cx.pow.powd} + %x{launchctl kickstart -k gui/"$UID"/cx.pow.powd} + end + + def start_on_mavericks + return say "Pow firewall configuration missing." unless File.exists?(POW_FIREWALL_PLIST_PATH) + %x{launchctl load #{POW_FIREWALL_PLIST_PATH}} + + return say "Pow daemon configuration missing." unless File.exists?(POW_DAEMON_PLIST_PATH) + %x{launchctl load #{POW_DAEMON_PLIST_PATH}} + end + end end + Powder::CLI.start