@@ -35,17 +35,6 @@ func password(message string) string {
35
35
return strings .TrimSpace (string (pass ))
36
36
}
37
37
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
-
49
38
func osType () string {
50
39
return strings .ToLower (runtime .GOOS )
51
40
}
@@ -69,6 +58,14 @@ func main() {
69
58
70
59
if osType () == "windows" {
71
60
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 ()
72
69
}
73
70
74
71
if _ , err := os .Stat (tibulaCommand ); err != nil {
@@ -78,21 +75,10 @@ func main() {
78
75
79
76
sys .Configure ()
80
77
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 ()
95
80
}
81
+
96
82
//setup
97
83
setupUser := prompt ("Choose an administrator username (admin)" )
98
84
if setupUser != "" {
@@ -148,6 +134,10 @@ func main() {
148
134
} else {
149
135
sys .Options .DbName = dbName
150
136
}
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
+ }
151
141
}
152
142
//misc
153
143
language := prompt ("Choose default language (en)" )
@@ -178,13 +168,21 @@ func main() {
178
168
exit ()
179
169
}
180
170
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 )
186
178
}
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
+ }
189
186
}
187
+ exit ()
190
188
}
0 commit comments