-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
75 lines (60 loc) · 1.74 KB
/
main.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
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"github.com/abiiranathan/qtinstaller/qtinstaller"
"github.com/joho/godotenv"
)
func init() {
godotenv.Load()
}
func main() {
log.SetPrefix("qtinstaller: ")
log.SetFlags(log.Lshortfile)
// If init argument, generate config file and exit.
if len(os.Args) > 1 && os.Args[1] == "init" {
err := qtinstaller.GenerateConfigFile()
if err != nil {
log.Fatalln(err)
}
os.Exit(0)
}
// Make sure windeployqt and binarycreator are installed and in PATH
windeployqt, binarycreator, err := qtinstaller.GetQtBinaries()
if err != nil {
log.Fatalln(err)
}
// Create default configuration
config := qtinstaller.NewConfig()
// Assert that all expected files exist
qtinstaller.AssertFilesExist(config)
// Get installation directories
dirs := qtinstaller.GetInstallerDirs(config)
err = qtinstaller.CreateDirectoryStructure(dirs)
if err != nil {
log.Fatalln(err)
}
// write the installer files to disk.
err = qtinstaller.WriteFiles(config, dirs)
if err != nil {
log.Fatalln(err)
}
// get path to target exe in data directory.
targetExe := filepath.Join(dirs.Data, filepath.Base(config.Executable))
// Run windeployqt on the executable to gather neccessary dlls.
output, err := exec.Command(windeployqt, "--no-translations", "--dir", dirs.Data, targetExe).CombinedOutput()
if err != nil {
log.Fatalln(string(output))
}
// Run binary creator to generate the installer.
output, err = exec.Command(
binarycreator, "--offline-only", "-c", "config/config.xml", "-p", "packages",
config.InstallerName).CombinedOutput()
if err != nil {
log.Fatalln(string(output))
}
wd, _ := os.Getwd()
log.Printf("Installer created at path %q\n", filepath.Join(wd, config.InstallerName))
}