forked from kyma-project/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructured OS specific /etc/hosts related files (kyma-project#86)
- Loading branch information
Igor
authored
May 21, 2019
1 parent
d042ac9
commit 07d1041
Showing
6 changed files
with
87 additions
and
84 deletions.
There are no files selected for viewing
File renamed without changes.
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,8 @@ | ||
// +build !windows | ||
// +build !darwin | ||
|
||
package minikube | ||
|
||
const hostsFile = "/etc/hosts" | ||
|
||
const defaultVMDriver = vmDriverNone |
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,7 @@ | ||
// +build windows | ||
|
||
package minikube | ||
|
||
const hostsFile = "C:\\Windows\\system32\\drivers\\etc\\hosts" | ||
|
||
const defaultVMDriver = vmDriverVirtualBox |
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 |
---|---|---|
@@ -1,8 +1,77 @@ | ||
// +build !windows | ||
// +build !darwin | ||
|
||
package minikube | ||
|
||
const hostsFile = "/etc/hosts" | ||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
const defaultVMDriver = vmDriverNone | ||
"github.com/kyma-project/cli/internal" | ||
"github.com/kyma-project/cli/internal/step" | ||
) | ||
|
||
func isWithSudo() bool { | ||
return os.Getenv("SUDO_UID") != "" | ||
} | ||
|
||
func promptUser() bool { | ||
for { | ||
fmt.Print("Type [y/n]: ") | ||
var res string | ||
if _, err := fmt.Scanf("%s", &res); err != nil { | ||
return false | ||
} | ||
switch res { | ||
case "yes", "y": | ||
return true | ||
case "no", "n": | ||
return false | ||
default: | ||
continue | ||
} | ||
} | ||
} | ||
|
||
func addDevDomainsToEtcHostsOSSpecific(o *MinikubeOptions, s step.Step, hostAlias string) error { | ||
notifyUserFunc := func(err error) { | ||
if err != nil { | ||
s.LogInfof("Error: %s", err.Error()) | ||
} | ||
s.LogInfof("Execute the following command manually to add domain entries: sudo sed -i '' \"/"+o.Domain+"/d\" "+hostsFile+" && echo '%s' | sudo tee -a /etc/hosts\r\n", hostAlias) | ||
} | ||
|
||
s.LogInfo("Adding domain mappings to your 'hosts' file") | ||
if isWithSudo() { | ||
s.LogInfo("You're running CLI with sudo. CLI has to add Kyma domain entries to your 'hosts'. Type 'y' to allow this action") | ||
if !promptUser() { | ||
notifyUserFunc(nil) | ||
return nil | ||
} | ||
} | ||
_, err := internal.RunCmd("sudo", []string{ | ||
"sed", "-i", | ||
"''", | ||
fmt.Sprintf("/%s/d", o.Domain), | ||
hostsFile}) | ||
if err != nil { | ||
notifyUserFunc(err) | ||
return nil | ||
} | ||
|
||
cmd := exec.Command("sudo", "tee", "-a", hostsFile) | ||
buf := &bytes.Buffer{} | ||
_, err = fmt.Fprint(buf, hostAlias) | ||
if err != nil { | ||
notifyUserFunc(err) | ||
return nil | ||
} | ||
cmd.Stdin = buf | ||
err = cmd.Run() | ||
if err != nil { | ||
notifyUserFunc(err) | ||
return nil | ||
} | ||
return nil | ||
} |
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