|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "github.com/fatih/color"
|
5 | 6 | "github.com/moby/sys/user"
|
6 | 7 | "github.com/swiftwave-org/swiftwave/swiftwave_service/cmd"
|
@@ -45,9 +46,54 @@ func main() {
|
45 | 46 | // management node also needs docker for running postgres or registry at-least
|
46 | 47 | _, err = exec.LookPath("docker")
|
47 | 48 | if err != nil {
|
48 |
| - color.Red("Docker is not installed. Aborting.") |
49 |
| - os.Exit(1) |
| 49 | + color.Red("Docker is not installed.") |
| 50 | + isDockerInstalled := false |
| 51 | + color.Blue("Run `curl -fsSL get.docker.com | bash -` to install docker.") |
| 52 | + color.Blue("Do you want to install docker now? (y/n)") |
| 53 | + fmt.Print("> ") |
| 54 | + var response string |
| 55 | + _, err := fmt.Scanln(&response) |
| 56 | + if err != nil { |
| 57 | + color.Red("Error reading response. Aborting.") |
| 58 | + os.Exit(1) |
| 59 | + } |
| 60 | + if strings.Compare(response, "y") == 0 || strings.Compare(response, "Y") == 0 { |
| 61 | + color.Blue("Installing docker...") |
| 62 | + // install docker |
| 63 | + err = runCommand(exec.Command("bash", "-c", "curl -fsSL get.docker.com | bash -")) |
| 64 | + if err != nil { |
| 65 | + color.Red("Error installing docker. Aborting.") |
| 66 | + os.Exit(1) |
| 67 | + } |
| 68 | + // enable docker service |
| 69 | + err = runCommand(exec.Command("systemctl", "enable", "docker")) |
| 70 | + if err != nil { |
| 71 | + color.Red("Error enabling docker. Aborting.") |
| 72 | + os.Exit(1) |
| 73 | + } |
| 74 | + // start docker service |
| 75 | + err = runCommand(exec.Command("systemctl", "start", "docker")) |
| 76 | + if err != nil { |
| 77 | + color.Red("Error starting docker. Aborting.") |
| 78 | + os.Exit(1) |
| 79 | + } |
| 80 | + isDockerInstalled = true |
| 81 | + } |
| 82 | + if !isDockerInstalled { |
| 83 | + color.Red("Docker is not installed. Aborting.") |
| 84 | + os.Exit(1) |
| 85 | + } else { |
| 86 | + color.Green("Docker is installed.") |
| 87 | + } |
50 | 88 | }
|
51 | 89 | // Start the command line interface
|
52 | 90 | cmd.Execute()
|
53 | 91 | }
|
| 92 | + |
| 93 | +// private function |
| 94 | +func runCommand(command *exec.Cmd) error { |
| 95 | + command.Stdout = os.Stdout |
| 96 | + command.Stderr = os.Stderr |
| 97 | + command.Stdin = os.Stdin |
| 98 | + return command.Run() |
| 99 | +} |
0 commit comments