-
Notifications
You must be signed in to change notification settings - Fork 90
/
installation.go
70 lines (60 loc) · 1.61 KB
/
installation.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
package main
import "C"
import (
"fmt"
"io/ioutil"
"os"
"path"
"github.com/mholt/archiver"
)
//export ReadInstallation
func ReadInstallation(socket, archivePath string) {
go func() {
var ffiResult *FFIResult
statusClient, err := connectToStatusServer(socket)
if err != nil {
fmt.Printf("failed to connect to status server: %s\n", err)
return
}
defer func() {
statusClient.end(ffiResult)
}()
tmpRoot, err := ioutil.TempDir("", "kots")
if err != nil {
fmt.Printf("failed to create temp path: %s\n", err.Error())
ffiResult = NewFFIResult(-1).WithError(err)
return
}
defer os.RemoveAll(tmpRoot)
// extract the current archive to this root
tarGz := archiver.TarGz{
Tar: &archiver.Tar{
ImplicitTopLevelFolder: false,
},
}
if err := tarGz.Unarchive(archivePath, tmpRoot); err != nil {
fmt.Printf("failed to unarchive: %s\n", err.Error())
ffiResult = NewFFIResult(-1).WithError(err)
return
}
installationFilePath := path.Join(tmpRoot, "upstream", "userdata", "installation.yaml")
_, err = os.Stat(installationFilePath)
if os.IsNotExist(err) {
fmt.Printf("not installation data: %s\n", err.Error())
ffiResult = NewFFIResult(-1).WithError(err)
return
}
if err != nil {
fmt.Printf("failed to find file: %s\n", err.Error())
ffiResult = NewFFIResult(-1).WithError(err)
return
}
installationData, err := ioutil.ReadFile(installationFilePath)
if err != nil {
fmt.Printf("failed to read file: %s\n", err.Error())
ffiResult = NewFFIResult(-1).WithError(err)
return
}
ffiResult = NewFFIResult(0).WithData(string(installationData))
}()
}