1
1
package linux_installer
2
2
3
3
import (
4
- // "io"
5
4
"flag"
6
5
"fmt"
7
6
"log"
@@ -16,20 +15,9 @@ const (
16
15
// Linux terminal command string to clear the current line and reset the cursor
17
16
clearLineVT100 = "\033 [2K\r "
18
17
cliInstallerMaxLineLen = 80
18
+ logFilename = "installer.log"
19
19
)
20
20
21
- // startLogging sets up the logging
22
- func startLogging (logFilename string ) * os.File {
23
- logfile , err := os .OpenFile (logFilename , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0666 )
24
- if err != nil {
25
- log .Fatal (err )
26
- }
27
- log .SetFlags (log .Ldate | log .Ltime )
28
- // log.SetOutput(io.MultiWriter(os.Stdout, logfile))
29
- log .SetOutput (logfile )
30
- return logfile
31
- }
32
-
33
21
// Run parses commandline options (if any) and starts one of two installer modes,
34
22
// GUI or commandline mode.
35
23
//
@@ -43,15 +31,18 @@ func startLogging(logFilename string) *os.File {
43
31
// "silent" mode. -target and -accept-license are necessary to run commandline install.
44
32
// -lang will also set the default GUI language.
45
33
func Run () {
46
- logfile := startLogging ("installer.log" )
34
+ logfile := startLogging (logFilename )
47
35
defer logfile .Close ()
48
36
49
37
openBoxes ()
50
38
config , err := NewConfig ()
51
39
if err != nil {
52
40
return
53
41
}
42
+ config .Variables ["installerName" ] = os .Args [0 ]
54
43
translator := NewTranslatorVar (config .Variables )
44
+ installerTempPath := filepath .Join (os .TempDir (), "linux_installer" )
45
+ defer os .RemoveAll (installerTempPath )
55
46
56
47
target := flag .String ("target" , "" , translator .Get ("cli_help_target" ))
57
48
showLicense := flag .Bool ("license" , false , translator .Get ("cli_help_showlicense" ))
@@ -66,6 +57,7 @@ func Run() {
66
57
fmt .Printf ("Language '%s' not available" , * lang )
67
58
}
68
59
}
60
+
69
61
if * showLicense {
70
62
licenseFile , err := GetResource (
71
63
fmt .Sprintf ("licenses/license_%s.txt" , translator .language ),
@@ -82,85 +74,122 @@ func Run() {
82
74
config .NoLauncher = true
83
75
}
84
76
85
- installerTempPath := filepath .Join (os .TempDir (), "linux_installer" )
86
- defer os .RemoveAll (installerTempPath )
87
77
if len (* target ) > 0 {
88
78
if * acceptLicense {
89
- installer := NewInstallerTo (* target , installerTempPath , config )
90
- installer .CreateLauncher = ! config .NoLauncher
91
- c := make (chan os.Signal , 1 )
92
- signal .Notify (c , os .Interrupt )
93
- installer .SetProgressFunction (func (status InstallStatus ) {
94
- file := installer .NextFile ().Target
95
- if len (file ) > cliInstallerMaxLineLen {
96
- file = "..." + file [len (file )- (cliInstallerMaxLineLen - 3 ):]
97
- }
98
- fmt .Print (clearLineVT100 + file )
99
- })
100
- fmt .Println (translator .Get ("silent_installing" ))
101
- installer .PreInstall ()
102
- installer .StartInstall ()
103
- go func () {
104
- for range c {
105
- installer .Rollback ()
106
- }
107
- }()
108
- installer .WaitForDone ()
109
- installer .PostInstall (
110
- translator .Variables ,
111
- translator .GetAllStringsRaw (),
112
- )
113
- fmt .Println (clearLineVT100 + installer .SizeString ())
114
- fmt .Println (translator .Get ("silent_done" ))
79
+ RunCliInstall (installerTempPath , * target , translator , config )
115
80
} else {
116
81
fmt .Println (translator .Get ("err_cli_mustacceptlicense" ))
117
82
}
118
83
return
119
84
}
120
85
121
- var guiError error
122
- UnpackResourceDir ("gui" , filepath .Join (installerTempPath , "gui" ))
123
- guiPlugin , guiError := plugin .Open (filepath .Join (installerTempPath , "gui" , "gui.so" ))
86
+ guiError := RunGuiInstall (installerTempPath , translator , config )
124
87
if guiError != nil {
125
- fmt .Println ("load plugin" )
126
- handleGuiErr (guiError , translator )
88
+ RunTuiInstall (installerTempPath , translator )
89
+ }
90
+ }
91
+
92
+ // RunGuiInstall loads the gui.so plugin, and starts the installer GUI.
93
+ func RunGuiInstall (
94
+ installerTempPath string ,
95
+ translator * Translator ,
96
+ config * Config ,
97
+ ) (err error ) {
98
+ UnpackResourceDir ("gui" , filepath .Join (installerTempPath , "gui" ))
99
+ guiPlugin , err := plugin .Open (filepath .Join (installerTempPath , "gui" , "gui.so" ))
100
+ if err != nil {
101
+ err = osShowRawErrorDialog (translator .Get ("err_gui_startup_failed_nogtk" ))
102
+ if err != nil {
103
+ handleGuiErr (err , translator .Get ("err_gui_startup_failed_nogtk" ))
104
+ }
127
105
return
128
106
}
129
107
NewGui , err := guiPlugin .Lookup ("NewGui" )
130
108
if err != nil {
131
- fmt . Println ( "lookup NewGui" )
132
- handleGuiErr (guiError , translator )
109
+ osShowRawErrorDialog ( translator . Get ( "err_gui_startup_internal_error" ) )
110
+ handleGuiErr (err , "" )
133
111
return
134
112
}
135
113
RunGui , err := guiPlugin .Lookup ("RunGui" )
136
114
if err != nil {
137
- fmt . Println ( "lookup RunGui" )
138
- handleGuiErr (guiError , translator )
115
+ osShowRawErrorDialog ( translator . Get ( "err_gui_startup_internal_error" ) )
116
+ handleGuiErr (err , "" )
139
117
return
140
118
}
141
119
installer := NewInstaller (installerTempPath , config )
142
- guiError = NewGui .(func (string , * Installer , * Translator , * Config ) error )(
120
+ err = NewGui .(func (string , * Installer , * Translator , * Config ) error )(
143
121
installerTempPath , installer , translator , config ,
144
122
)
145
- if guiError != nil {
146
- fmt .Println ("NewGui()" )
147
- handleGuiErr (guiError , translator )
123
+ if err != nil {
124
+ handleGuiErr (err , translator .Get ("err_gui_startup_failed" ))
148
125
return
149
126
} else {
150
127
RunGui .(func ())()
151
128
}
152
- // if guiError != nil {
129
+ return
130
+ }
131
+
132
+ // RunCliInstall runs a "silent" installation, on the command line with no further user
133
+ // interaction.
134
+ func RunCliInstall (
135
+ installerTempPath , target string , translator * Translator , config * Config ,
136
+ ) {
137
+ installer := NewInstallerTo (target , installerTempPath , config )
138
+ installer .CreateLauncher = ! config .NoLauncher
139
+ cancelChannel := make (chan os.Signal , 1 )
140
+ signal .Notify (cancelChannel , os .Interrupt )
141
+ installer .SetProgressFunction (func (status InstallStatus ) {
142
+ file := installer .NextFile ().Target
143
+ if len (file ) > cliInstallerMaxLineLen {
144
+ file = "..." + file [len (file )- (cliInstallerMaxLineLen - 3 ):]
145
+ }
146
+ fmt .Print (clearLineVT100 + file )
147
+ })
148
+ fmt .Println (translator .Get ("silent_installing" ))
149
+ installer .PreInstall ()
150
+ installer .StartInstall ()
151
+ go func () {
152
+ for range cancelChannel {
153
+ installer .Rollback ()
154
+ }
155
+ }()
156
+ installer .WaitForDone ()
157
+ installer .PostInstall (
158
+ translator .Variables ,
159
+ translator .GetAllStringsRaw (),
160
+ )
161
+ fmt .Println (clearLineVT100 + installer .SizeString ())
162
+ fmt .Println (translator .Get ("silent_done" ))
163
+ }
164
+
165
+ // RunTuiInstall starts a terminal curses-based UI (currently disabled).
166
+ func RunTuiInstall (installerTempPath string , translator * Translator ) {
153
167
// tui, err := NewTui(installerTempPath, translator)
154
168
// if err != nil {
155
169
// log.Println(err)
156
170
// } else {
157
171
// tui.Run()
158
172
// }
159
- // }
160
173
}
161
174
162
- func handleGuiErr (err error , translator * Translator ) {
175
+ // startLogging sets up the logging
176
+ func startLogging (logFilename string ) * os.File {
177
+ logfile , err := os .OpenFile (logFilename , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0666 )
178
+ if err != nil {
179
+ log .Fatal (err )
180
+ }
181
+ log .SetFlags (log .Ldate | log .Ltime )
182
+ // log.SetOutput(io.MultiWriter(os.Stdout, logfile))
183
+ log .SetOutput (logfile )
184
+ return logfile
185
+ }
186
+
187
+ // handleGuiErr prints and logs GUI startup errors, and prints the commandline usage.
188
+ func handleGuiErr (err error , msg string ) {
163
189
log .Println ("Unable to load GUI:" , err )
164
- fmt .Println (translator .Get ("err_gui_startup_failed" ))
190
+ if len (msg ) > 0 {
191
+ log .Println (msg )
192
+ fmt .Println (msg )
193
+ }
165
194
flag .PrintDefaults ()
166
195
}
0 commit comments