Class: GrokCLI::Docker::UpdateEtcHosts
- Inherits:
-
Object
- Object
- GrokCLI::Docker::UpdateEtcHosts
- Defined in:
- lib/grok_cli/docker/update_etc_hosts.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(config = Configuration.new) ⇒ UpdateEtcHosts
constructor
A new instance of UpdateEtcHosts.
Constructor Details
#initialize(config = Configuration.new) ⇒ UpdateEtcHosts
Returns a new instance of UpdateEtcHosts.
3 4 5 |
# File 'lib/grok_cli/docker/update_etc_hosts.rb', line 3 def initialize(config = Configuration.new) @config = config end |
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |