feat: installer syscheck + prompt (wip)

pull/621/head
Nicolas Giard 6 years ago
parent 96f4e89020
commit 04c972c1d0

@ -19,29 +19,75 @@ var logo = `
|__/
`
var finish = `
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| |
| Open http://localhost:3000/ in your browser |
| to complete the installation! |
| |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`
func main() {
fmt.Println(chalk.Yellow.Color(logo))
fmt.Println(chalk.Bold.TextStyle("Installer for Wiki.js 2.x"))
fmt.Printf("for %s-%s\n\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("%s-%s\n\n", runtime.GOOS, runtime.GOARCH)
// Check system requirements
fmt.Println(chalk.Bold.TextStyle("Verifying system requirements..."))
CheckNodeJs()
CheckRAM()
fmt.Println(chalk.Bold.TextStyle("\nSetup"))
// Prompt for build to install
prompt := promptui.Select{
promptBuild := promptui.Select{
Label: "Select Build to install",
Items: []string{"Stable", "Dev"},
Templates: &promptui.SelectTemplates{
Help: " ",
Selected: chalk.Green.Color("✔") + " Build: {{ . }}",
},
}
_, result, err := prompt.Run()
_, _, err := promptBuild.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
fmt.Printf("You choose %q\n", result)
// Choose database driver
promptDB := promptui.Select{
Label: "Select database driver",
Items: []string{"MariaDB", "MySQL", "MS SQL Server", "PostgreSQL", "SQLite"},
Templates: &promptui.SelectTemplates{
Help: " ",
Selected: chalk.Green.Color("✔") + " Database Driver: {{ . }}",
},
Size: 10,
}
_, _, err = promptDB.Run()
// Port
promptPort := promptui.Prompt{
Label: "Port",
Default: "3000",
Templates: &promptui.PromptTemplates{
Success: chalk.Green.Color("✔") + " Port: {{ . }}",
},
}
_, err = promptPort.Run()
// Download archives...
fmt.Println(chalk.Bold.TextStyle("\nDownloading packages..."))
uiprogress.Start()
bar := uiprogress.AddBar(100)
@ -51,4 +97,6 @@ func main() {
for bar.Incr() {
time.Sleep(time.Millisecond * 20)
}
fmt.Println("\n" + chalk.Yellow.Color(finish))
}

@ -0,0 +1,54 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"github.com/blang/semver"
"github.com/pbnjay/memory"
"github.com/ttacon/chalk"
)
const nodejsSemverRange = ">=8.11.3 <10.0.0"
const ramMin = 768
// CheckNodeJs checks if Node.js is installed and has minimal supported version
func CheckNodeJs() bool {
cmd := exec.Command("node", "-v")
cmdOutput, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
validRange := semver.MustParseRange(nodejsSemverRange)
nodeVersion, err := semver.ParseTolerant(string(cmdOutput[:]))
if !validRange(nodeVersion) {
fmt.Printf(chalk.Red.Color("Error: Installed Node.js version is not supported! %s"), nodejsSemverRange)
os.Exit(1)
}
fmt.Printf(chalk.Green.Color("✔")+" Node.js %s: OK\n", nodeVersion.String())
return true
}
// CheckRAM checks if system total RAM meets requirements
func CheckRAM() bool {
var totalRAM = memory.TotalMemory() / 1024 / 1024
if totalRAM < ramMin {
fmt.Printf(chalk.Red.Color("Error: System does not meet RAM requirements. %s MB minimum."), ramMin)
os.Exit(1)
}
fmt.Printf(chalk.Green.Color("✔")+" Total System RAM %d MB: OK\n", totalRAM)
return true
}
// CheckNetworkAccess checks if download server can be reached
func CheckNetworkAccess() bool {
// TODO
return true
}
Loading…
Cancel
Save