-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.go
125 lines (116 loc) · 3.4 KB
/
run.go
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
package linux_installer
import (
"flag"
"fmt"
// "io"
"log"
"os"
"os/signal"
"path/filepath"
"strings"
)
const (
// Linux terminal command string to clear the current line and reset the cursor
clearLineVT100 = "\033[2K\r"
)
// startLogging sets up the logging
func startLogging(logFilename string) *os.File {
logfile, err := os.OpenFile(logFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
log.SetFlags(log.Ldate | log.Ltime)
// log.SetOutput(io.MultiWriter(os.Stdout, logfile))
log.SetOutput(logfile)
return logfile
}
// Run parses commandline options (if any) and starts one of two installer modes,
// GUI or commandline mode.
//
// Commandline parameters are:
// -target // Target directory to install to
// -show-license // Print the software license and exit
// -accept-license // Accept the license, needed to install the software in commandline mode.
// -lang // Choose install language. This also affects the GUI mode.
//
// Giving any commandline parameters except for the last will trigger commandline, or
// "silent" mode. -target and -accept-license are necessary to run commandline install.
// -lang will also set the default GUI language.
func Run() {
logfile := startLogging("installer.log")
defer logfile.Close()
openBoxes()
config, err := ConfigNew()
if err != nil {
return
}
translator := NewTranslatorVar(config)
target := flag.String("target", "", translator.Get("cli_help_target"))
showLicense := flag.Bool("show-license", false, translator.Get("cli_help_showlicense"))
acceptLicense := flag.Bool("accept-license", false, translator.Get("cli_help_acceptlicense"))
lang := flag.String("lang", "", translator.Get("cli_help_lang")+" "+strings.Join(translator.GetLanguageOptionKeys(), ", "))
flag.Parse()
if len(*lang) > 0 {
err := translator.SetLanguage(*lang)
if err != nil {
fmt.Printf("Language '%s' not available", *lang)
}
}
if *showLicense {
licenseFile, err := GetResource(
fmt.Sprintf("licenses/license_%s.txt", translator.language),
)
if err != nil {
fmt.Println(err)
} else {
fmt.Print(licenseFile)
}
return
}
installerTempPath := filepath.Join(os.TempDir(), "linux_installer")
if len(*target) > 0 {
if *acceptLicense {
installer := InstallerToNew(*target, installerTempPath)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
installer.SetProgressFunction(func(status InstallStatus) {
file := installer.NextFile().Target
maxLen := 70
if len(file) > maxLen {
file = "..." + file[len(file)-(maxLen-3):]
}
fmt.Print(clearLineVT100 + file)
})
fmt.Println(translator.Get("silent_installing"))
installer.StartInstall()
go func() {
for range c {
installer.Rollback()
}
}()
installer.WaitForDone()
fmt.Println(clearLineVT100 + installer.SizeString())
fmt.Println(translator.Get("silent_done"))
} else {
fmt.Println(translator.Get("err_cli_mustacceptlicense"))
}
return
}
var guiError error
defer os.RemoveAll(installerTempPath)
UnpackResourceDir("gui", filepath.Join(installerTempPath, "gui"))
gui, guiError := NewGui(installerTempPath, translator)
if guiError != nil {
log.Println("Unable to create window:", guiError)
} else {
gui.Run()
}
// if guiError != nil {
// tui, err := NewTui(installerTempPath, translator)
// if err != nil {
// log.Println(err)
// } else {
// tui.Run()
// }
// }
}