-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
128 lines (108 loc) · 2.5 KB
/
Copy pathmain.go
File metadata and controls
128 lines (108 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"os"
"path/filepath"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
const (
binaryBackName = "go-genesis.exe"
binaryFrontName = "Genesis.exe"
dbHost = "localhost"
dbPort = 5430
dbUser = "postgres"
dbPassword = "postgres"
dbNamePattern = "genesis%d"
centrifugoSecret = "secret"
centrifugoPort = 8000
nodeLogLevel = "INFO"
firstBlockFile = "1block"
systemPort = 7078
waitTablesCount = 32
demoPageURL = "https://raw.githubusercontent.com/GenesisKernel/apps/60ddda1608e4770aabb8732127ee5c4db3facdc1/quick-start/quick-start.json"
walletBalance = 100
apiBaseURL = "http://localhost:7079/api/v2"
)
var (
executablePath string
dataPath string
centrifugoURL string
centrifugoProcess *os.Process
nodeProcesses []*os.Process
frontProcesses []*os.Process
)
func init() {
var err error
executablePath, err = filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
fmt.Println("Can't find the current directory: ", err)
return
}
dataPath = filepath.Join(executablePath, "data")
centrifugoURL = fmt.Sprintf("http://localhost:%d", centrifugoPort)
}
func printMenu() {
lines := []string{
`Type "i" to perform a new installation`,
`Type "c" to remove all nodes and databases`,
}
if isInstalled() {
lines = append(lines, `Type "r" to restart the previous installation`)
}
lines = append(lines,
`Type "s" to stop the services without clearing the data`,
`Type "q" to exit.`,
)
for i, line := range lines {
fmt.Printf("%d. %s\n", i+1, line)
}
fmt.Print("> ")
}
func printRestartMessage() {
if isInstalled() {
fmt.Println(`Quickstart already installed. Do you want to start it now? y/n`)
fmt.Print("> ")
var action string
_, err := fmt.Scanf("%s \n", &action)
if err != nil {
fmt.Println("Error: ", err)
} else if action == "y" {
restartNodes()
}
}
}
func main() {
defer stopNodes()
go waitSignal()
printRestartMessage()
for {
printMenu()
var action string
_, err := fmt.Scanf("%s \n", &action)
if err != nil {
fmt.Println("Error: ", err)
} else {
switch action {
case "i":
var nodesNumber int
fmt.Println("How many nodes do you want to install? Example: 3")
fmt.Print("> ")
_, err := fmt.Scanf("%d \n", &nodesNumber)
if err != nil {
fmt.Println("Error: ", err)
} else {
startNodes(nodesNumber)
}
case "c":
clearNodes()
case "r":
restartNodes()
case "s":
stopNodes()
}
}
if action == "q" {
break
}
}
}