class GrokCLI::Docker::UpdateEtcHosts

Public Class Methods

new(config = Configuration.new) click to toggle source
# File lib/grok_cli/docker/update_etc_hosts.rb, line 3
def initialize(config = Configuration.new)
  @config = config
end

Public Instance Methods

execute() click to toggle source
# File lib/grok_cli/docker/update_etc_hosts.rb, line 7
    def execute
      system <<~CMD

        IP=`docker-machine ip #{@config.machine_name}`

        IP_MAP="$IP #{@config.hostname}"

        if grep -Fxq "$IP_MAP" /etc/hosts; then
          :
        else

          if sudo -n true 2>/dev/null; then
            :
          else
            echo "You may be prompted for your password; this is to permit updating your /etc/hosts for #{@config.hostname}"
          fi

          sudo sed -i '' '/#{@config.hostname.gsub('.', '\.')}$/d' /etc/hosts

          echo $IP_MAP | sudo tee -a /etc/hosts
        fi

      CMD
    end