-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstallCommand.go
113 lines (91 loc) · 2.66 KB
/
installCommand.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
package main
import (
"fmt"
"os"
"os/user"
"runtime"
"github.com/mkideal/cli"
)
type install struct {
cli.Helper
}
var installCommand = &cli.Command{
Name: "install",
Desc: "install needed binaries, run check command before to be sure you need it",
Argv: func() interface{} { return new(install) },
Fn: func(ctx *cli.Context) error {
printHeader()
if checkIfRoot() {
if runtime.GOOS == "linux" {
linuxInstall()
} else if runtime.GOOS == "darwin" {
darwinInstall()
} else {
fmt.Printf("You need to have %s or %s (MacOS) in order to be compatible with this binary.\n", underline("linux"), underline("darwin"))
}
fmt.Printf("Run %s command to verify if everything was installed.\n", yellow("pomdok check"))
}
return nil
},
}
func checkIfRoot() bool {
user, _ := user.Current()
if "root" != user.Username {
fmt.Printf("You need to use %s in order to use this command.\n", underline("sudo"))
return false
}
if "root" == user.Username && "" == os.Getenv("SUDO_USER") {
fmt.Printf("Please do not run this command as %s but with %s.\n", underline("root"), underline("sudo"))
return false
}
return true
}
func linuxInstall() {
phpInstall("apt install php -y")
symfonyCliInstall()
return
}
func darwinInstall() {
phpInstall("brew install php nss")
symfonyCliInstall()
return
}
func phpInstall(command string) {
exists, _ := checkBinaryExists("php")
if exists == false {
fmt.Printf("Starting %s installation 🏃\n", yellow("php"))
runCommand(command)
exists, _ = checkBinaryExists("php")
if exists == false {
fmt.Printf("%s installation error ... 😭\n", yellow("php"))
os.Exit(1)
}
fmt.Printf("%s installed ✔\n", yellow("php"))
fmt.Printf("With this command we only installed %s binary but no extensions,\n", yellow("php"))
fmt.Printf("if you do need extensions you'll have to install them by yourself.\n")
fmt.Print("\n")
}
}
func symfonyCliInstall() {
exists, _ := checkBinaryExists("symfony")
if exists == false {
fmt.Printf("Starting %s installation 🏃\n", yellow("symfony"))
runCommand("brew install symfony-cli")
runCommand("symfony version")
exists, _ = checkBinaryExists("symfony")
if exists == false {
fmt.Printf("%s installation error ... 😭\n", yellow("symfony"))
os.Exit(1)
}
currentUser, _ := user.Current()
username := currentUser.Username
configPath := getSymfonyCliConfigPath()
if runtime.GOOS == "darwin" {
runCommand(fmt.Sprintf("sudo chown -R %s:staff %s", username, configPath))
} else {
runCommand(fmt.Sprintf("sudo chown -R %s:%s %s", username, username, configPath))
}
fmt.Printf("%s installed ✔\n", yellow("symfony"))
fmt.Print("\n")
}
}