Skip to content

Commit 837e856

Browse files
committed
add start scripts
1 parent a7cb1e5 commit 837e856

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

cmd/setup/main.go

+30-32
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ func password(message string) string {
3535
return strings.TrimSpace(string(pass))
3636
}
3737

38-
func openBrowser(url string) {
39-
switch os := osType(); os {
40-
case "darwin":
41-
exec.Command("open", url).Start()
42-
case "linux":
43-
exec.Command("xdg-open", url).Start()
44-
case "windows":
45-
exec.Command("cmd", "/c", "start", url).Start()
46-
}
47-
}
48-
4938
func osType() string {
5039
return strings.ToLower(runtime.GOOS)
5140
}
@@ -69,6 +58,14 @@ func main() {
6958

7059
if osType() == "windows" {
7160
tibulaCommand += ".exe"
61+
} else if tibulaCommand == "tibula" {
62+
tibulaCommand = "./tibula"
63+
}
64+
65+
if osType() == "linux" && !term.IsTerminal(int(os.Stdout.Fd())) {
66+
fmt.Println("No terminal available, use setup.sh instead.")
67+
os.WriteFile(cwd+"/setup.sh", []byte(fmt.Sprintf("#!/bin/sh\n\n%s/setup\n", cwd)), 0755)
68+
exit()
7269
}
7370

7471
if _, err := os.Stat(tibulaCommand); err != nil {
@@ -78,21 +75,10 @@ func main() {
7875

7976
sys.Configure()
8077
if _, err := os.Stat(tibulaJson); err == nil {
81-
start := prompt("A configuration file already exists. Do you want to start Tibula instead? (Y/n)")
82-
if strings.ToLower(start) != "n" {
83-
if err := sys.ConfigRead(tibulaJson); err != nil {
84-
fmt.Println(err)
85-
exit()
86-
}
87-
if sys.Options.WebTlsPrivate != "" && sys.Options.WebTlsPublic != "" {
88-
openBrowser(fmt.Sprintf("https://%s:%d", sys.Options.WebHost, sys.Options.WebPort))
89-
} else {
90-
openBrowser(fmt.Sprintf("http://%s:%d", sys.Options.WebHost, sys.Options.WebPort))
91-
}
92-
runCommand(tibulaCommand, "--config", tibulaJson, "--start")
93-
exit()
94-
}
78+
fmt.Println("A configuration file already exists, remove it and try again.")
79+
exit()
9580
}
81+
9682
//setup
9783
setupUser := prompt("Choose an administrator username (admin)")
9884
if setupUser != "" {
@@ -148,6 +134,10 @@ func main() {
148134
} else {
149135
sys.Options.DbName = dbName
150136
}
137+
if _, err := os.Stat(sys.Options.DbName); err == nil {
138+
fmt.Println("An sqlite database with the same name already exists, remove it and try again.")
139+
exit()
140+
}
151141
}
152142
//misc
153143
language := prompt("Choose default language (en)")
@@ -178,13 +168,21 @@ func main() {
178168
exit()
179169
}
180170

181-
//start
182-
if sys.Options.WebTlsPrivate != "" && sys.Options.WebTlsPublic != "" {
183-
openBrowser(fmt.Sprintf("https://%s:%d", sys.Options.WebHost, sys.Options.WebPort))
184-
} else {
185-
openBrowser(fmt.Sprintf("http://%s:%d", sys.Options.WebHost, sys.Options.WebPort))
171+
switch osType() {
172+
case "windows":
173+
os.WriteFile(cwd+"/start.bat", []byte(fmt.Sprintf("#@echo off\n%s --config %s --start\n", tibulaCommand, jsonFile)), 0755)
174+
case "darwin":
175+
os.WriteFile(cwd+"/start.command", []byte(fmt.Sprintf("#!/bin/sh\n\n%s --config %s --start\n", tibulaCommand, jsonFile)), 0755)
176+
case "linux":
177+
os.WriteFile(cwd+"/start.sh", []byte(fmt.Sprintf("#!/bin/sh\n\n%s --config %s --start\n", tibulaCommand, jsonFile)), 0755)
186178
}
187-
if err := runCommand(tibulaCommand, "--config", jsonFile, "--start"); err != nil {
188-
exit()
179+
180+
//start
181+
start := prompt("Do you want to start it now? (Y/n)")
182+
if start != "n" {
183+
if err := runCommand(tibulaCommand, "--config", jsonFile, "--start"); err != nil {
184+
exit()
185+
}
189186
}
187+
exit()
190188
}

0 commit comments

Comments
 (0)