diff options
Diffstat (limited to 'cmd/deploy/host/update.go')
| -rw-r--r-- | cmd/deploy/host/update.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/cmd/deploy/host/update.go b/cmd/deploy/host/update.go index 6f1b43b..aa47ed8 100644 --- a/cmd/deploy/host/update.go +++ b/cmd/deploy/host/update.go | |||
| @@ -40,11 +40,11 @@ func runUpdate(cmd *cobra.Command, args []string) error { | |||
| 40 | yes, _ := cmd.Flags().GetBool("yes") | 40 | yes, _ := cmd.Flags().GetBool("yes") |
| 41 | if !yes { | 41 | if !yes { |
| 42 | fmt.Printf("This will run apt update && apt upgrade on %s\n", host) | 42 | fmt.Printf("This will run apt update && apt upgrade on %s\n", host) |
| 43 | fmt.Print("Continue? [y/N]: ") | 43 | fmt.Print("Continue? [Y/n]: ") |
| 44 | reader := bufio.NewReader(os.Stdin) | 44 | reader := bufio.NewReader(os.Stdin) |
| 45 | response, _ := reader.ReadString('\n') | 45 | response, _ := reader.ReadString('\n') |
| 46 | response = strings.TrimSpace(response) | 46 | response = strings.TrimSpace(response) |
| 47 | if response != "y" && response != "Y" { | 47 | if response == "n" || response == "N" { |
| 48 | fmt.Println("Aborted.") | 48 | fmt.Println("Aborted.") |
| 49 | return nil | 49 | return nil |
| 50 | } | 50 | } |
| @@ -70,8 +70,21 @@ func runUpdate(cmd *cobra.Command, args []string) error { | |||
| 70 | 70 | ||
| 71 | fmt.Println() | 71 | fmt.Println() |
| 72 | if output, err := client.Run("[ -f /var/run/reboot-required ] && echo 'yes' || echo 'no'"); err == nil { | 72 | if output, err := client.Run("[ -f /var/run/reboot-required ] && echo 'yes' || echo 'no'"); err == nil { |
| 73 | if output == "yes\n" { | 73 | if strings.TrimSpace(output) == "yes" { |
| 74 | fmt.Println("Note: A reboot is required to complete the update.") | 74 | fmt.Print("A reboot is required to complete the update. Reboot now? [Y/n]: ") |
| 75 | reader := bufio.NewReader(os.Stdin) | ||
| 76 | response, _ := reader.ReadString('\n') | ||
| 77 | response = strings.TrimSpace(response) | ||
| 78 | if response == "" || response == "y" || response == "Y" { | ||
| 79 | fmt.Println("Rebooting...") | ||
| 80 | if _, err := client.RunSudo("reboot"); err != nil { | ||
| 81 | // reboot command often returns an error as connection drops | ||
| 82 | // this is expected behavior | ||
| 83 | } | ||
| 84 | fmt.Println("Reboot initiated. The host will be back online shortly.") | ||
| 85 | return nil | ||
| 86 | } | ||
| 87 | fmt.Println("Skipping reboot. Run 'sudo reboot' manually when ready.") | ||
| 75 | } | 88 | } |
| 76 | } | 89 | } |
| 77 | 90 | ||
