Skip to content

Commit 04c972c

Browse files
committed
feat: installer syscheck + prompt (wip)
1 parent 96f4e89 commit 04c972c

File tree

2 files changed

+106
-4
lines changed

2 files changed

+106
-4
lines changed

dev/installer/main.go

+52-4
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,75 @@ var logo = `
1919
|__/
2020
`
2121

22+
var finish = `
23+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
24+
| |
25+
| Open http://localhost:3000/ in your browser |
26+
| to complete the installation! |
27+
| |
28+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
29+
`
30+
2231
func main() {
2332
fmt.Println(chalk.Yellow.Color(logo))
2433
fmt.Println(chalk.Bold.TextStyle("Installer for Wiki.js 2.x"))
25-
fmt.Printf("for %s-%s\n\n", runtime.GOOS, runtime.GOARCH)
34+
fmt.Printf("%s-%s\n\n", runtime.GOOS, runtime.GOARCH)
35+
36+
// Check system requirements
37+
38+
fmt.Println(chalk.Bold.TextStyle("Verifying system requirements..."))
39+
CheckNodeJs()
40+
CheckRAM()
41+
fmt.Println(chalk.Bold.TextStyle("\nSetup"))
2642

2743
// Prompt for build to install
2844

29-
prompt := promptui.Select{
45+
promptBuild := promptui.Select{
3046
Label: "Select Build to install",
3147
Items: []string{"Stable", "Dev"},
48+
Templates: &promptui.SelectTemplates{
49+
Help: " ",
50+
Selected: chalk.Green.Color("✔") + " Build: {{ . }}",
51+
},
3252
}
3353

34-
_, result, err := prompt.Run()
54+
_, _, err := promptBuild.Run()
3555

3656
if err != nil {
3757
fmt.Printf("Prompt failed %v\n", err)
3858
return
3959
}
4060

41-
fmt.Printf("You choose %q\n", result)
61+
// Choose database driver
62+
63+
promptDB := promptui.Select{
64+
Label: "Select database driver",
65+
Items: []string{"MariaDB", "MySQL", "MS SQL Server", "PostgreSQL", "SQLite"},
66+
Templates: &promptui.SelectTemplates{
67+
Help: " ",
68+
Selected: chalk.Green.Color("✔") + " Database Driver: {{ . }}",
69+
},
70+
Size: 10,
71+
}
72+
73+
_, _, err = promptDB.Run()
74+
75+
// Port
76+
77+
promptPort := promptui.Prompt{
78+
Label: "Port",
79+
Default: "3000",
80+
Templates: &promptui.PromptTemplates{
81+
Success: chalk.Green.Color("✔") + " Port: {{ . }}",
82+
},
83+
}
84+
85+
_, err = promptPort.Run()
4286

4387
// Download archives...
4488

89+
fmt.Println(chalk.Bold.TextStyle("\nDownloading packages..."))
90+
4591
uiprogress.Start()
4692
bar := uiprogress.AddBar(100)
4793

@@ -51,4 +97,6 @@ func main() {
5197
for bar.Incr() {
5298
time.Sleep(time.Millisecond * 20)
5399
}
100+
101+
fmt.Println("\n" + chalk.Yellow.Color(finish))
54102
}

dev/installer/syscheck.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"os/exec"
8+
9+
"github.com/blang/semver"
10+
"github.com/pbnjay/memory"
11+
"github.com/ttacon/chalk"
12+
)
13+
14+
const nodejsSemverRange = ">=8.11.3 <10.0.0"
15+
const ramMin = 768
16+
17+
// CheckNodeJs checks if Node.js is installed and has minimal supported version
18+
func CheckNodeJs() bool {
19+
cmd := exec.Command("node", "-v")
20+
cmdOutput, err := cmd.CombinedOutput()
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
25+
validRange := semver.MustParseRange(nodejsSemverRange)
26+
nodeVersion, err := semver.ParseTolerant(string(cmdOutput[:]))
27+
if !validRange(nodeVersion) {
28+
fmt.Printf(chalk.Red.Color("Error: Installed Node.js version is not supported! %s"), nodejsSemverRange)
29+
os.Exit(1)
30+
}
31+
32+
fmt.Printf(chalk.Green.Color("✔")+" Node.js %s: OK\n", nodeVersion.String())
33+
34+
return true
35+
}
36+
37+
// CheckRAM checks if system total RAM meets requirements
38+
func CheckRAM() bool {
39+
var totalRAM = memory.TotalMemory() / 1024 / 1024
40+
if totalRAM < ramMin {
41+
fmt.Printf(chalk.Red.Color("Error: System does not meet RAM requirements. %s MB minimum."), ramMin)
42+
os.Exit(1)
43+
}
44+
45+
fmt.Printf(chalk.Green.Color("✔")+" Total System RAM %d MB: OK\n", totalRAM)
46+
47+
return true
48+
}
49+
50+
// CheckNetworkAccess checks if download server can be reached
51+
func CheckNetworkAccess() bool {
52+
// TODO
53+
return true
54+
}

0 commit comments

Comments
 (0)