forked from epos-eu/opensource-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_platform.go
84 lines (76 loc) · 2.47 KB
/
check_platform.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
package main
import (
"database/sql"
"os"
"os/exec"
)
// See if Docker is installed
func (a *App) IsDockerInstalled() bool {
// Add +"usr/local/bin:" to the PATH
os.Setenv("PATH", "/usr/local/bin:"+os.Getenv("PATH"))
// Add to the PATH the location of the docker and docker-compose executables from the database
db, err := sql.Open("sqlite3", databasePath)
if err == nil {
defer db.Close()
// Query the database for the path to the docker and docker-compose executables
rows, err := db.Query("SELECT path FROM platform_paths WHERE platform = ?", "docker")
if err == nil {
defer rows.Close()
// If the query matched a row, add the path to the PATH
if rows.Next() {
var path string
if err = rows.Scan(&path); err == nil {
os.Setenv("PATH", path+":"+os.Getenv("PATH"))
}
}
}
}
// Check if docker is installed
// Run "docker compose --version", if it fails, run "docker-compose --version"
// command := exec.Command("docker", "compose", "--version")
// err = command.Run()
_, err = RunCommand(exec.Command("docker", "compose", "--version"))
if err != nil {
// command = exec.Command("docker-compose", "--version")
// err = command.Run()
_, err = RunCommand(exec.Command("docker-compose", "--version"))
if err != nil {
return false
}
}
return true
}
func (a *App) IsDockerRunning() bool {
// Run the command to see if docker is running
// command := exec.Command("docker", "info")
// _, err := command.Output()
_, err := RunCommand(exec.Command("docker", "info"))
return err == nil
}
// See if Kubernetes is installed
func (a *App) IsKubernetesInstalled() bool {
// Add +"usr/local/bin:" to the PATH
os.Setenv("PATH", "/usr/local/bin:"+os.Getenv("PATH"))
// Add to the PATH the location of the kubectl executable from the database
db, err := sql.Open("sqlite3", databasePath)
if err == nil {
defer db.Close()
// Query the database for the path to the kubectl executable
rows, err := db.Query("SELECT path FROM platform_paths WHERE platform = ?", "kubernetes")
if err == nil {
defer rows.Close()
// If the query matched a row, add the path to the PATH
if rows.Next() {
var path string
if err = rows.Scan(&path); err == nil {
os.Setenv("PATH", path+":"+os.Getenv("PATH"))
}
}
}
}
// Run the command to see if kubectl is installed
// command := exec.Command("kubectl", "version", "--client")
// _, err = command.Output()
_, err = RunCommand(exec.Command("kubectl", "version", "--client"))
return err == nil
}