From 43dacc9aaf5cbd1c7a16a95f87ca990860c76b2d Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 8 Jul 2018 15:39:19 +0900 Subject: [PATCH] Automatically run "make ports" if needed --- README.md | 4 ---- main.go | 5 ++++- ports.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 ports.go diff --git a/README.md b/README.md index 031725bc..e6608881 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,6 @@ curl -s https://raw.githubusercontent.com/animenotifier/notify.moe/go/install.sh * In your browser, import the file `security/default/root.crt` as a trusted Root authority * Open `https://beta.notify.moe` -## OS restarts - -* If you restart your operating system, run `make ports` to update your port bindings - ## Author | [![Eduard Urbach on Twitter](https://gravatar.com/avatar/16ed4d41a5f244d1b10de1b791657989?s=70)](https://twitter.com/eduardurbach "Follow @eduardurbach on Twitter") | diff --git a/main.go b/main.go index c2445532..d08f7686 100644 --- a/main.go +++ b/main.go @@ -49,9 +49,12 @@ func configure(app *aero.Application) *aero.Application { // API arn.API.Install(app) - // Domain + // Development server configuration if arn.IsDevelopment() { app.Config.Domain = "beta.notify.moe" + + // Test connectivity + app.OnStart(testConnectivity) } // Authentication diff --git a/ports.go b/ports.go new file mode 100644 index 00000000..2641db9c --- /dev/null +++ b/ports.go @@ -0,0 +1,33 @@ +package main + +import ( + "crypto/tls" + "fmt" + "os" + "os/exec" + + "github.com/fatih/color" +) + +// testConnectivity will test if port 443 is accessible or not. +// If not, it will attempt to run "sudo make ports" and consume +// execution once the user has entered the password. +func testConnectivity() { + config := tls.Config{ + InsecureSkipVerify: true, + } + + _, err := tls.Dial("tcp", ":443", &config) + + if err != nil { + fmt.Println("--------------------------------------------------------------------------------") + color.Red("HTTPS port 443 is not accessible") + fmt.Println("Running", color.YellowString("make ports"), "to be able to access", color.GreenString("https://"+app.Config.Domain)) + + cmd := exec.Command("sudo", "make", "ports") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + cmd.Run() + } +}