-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
173 lines (169 loc) · 3.97 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package main
import (
"github.com/urfave/cli/v2"
"h-devops/cmd"
"log"
"os"
"time"
)
const VERSION = "0.5.3"
const PhpDefaultVersion = "7.4"
func main() {
app := &cli.App{
Name: "h-devops",
Version: VERSION,
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "VoHoang",
Email: "[email protected]",
},
},
Usage: "Tools to assist devops using CLI",
Suggest: true,
Commands: []*cli.Command{
{
Name: "commands",
Aliases: []string{"cmd"},
Usage: "List of available commands",
Action: cmd.ListCommands,
},
{
Name: "nvm",
Aliases: []string{"nvm"},
Usage: "Node version manager (NVM)",
Subcommands: []*cli.Command{
{
Name: "install",
Usage: "Install Node version manager (NVM)",
Aliases: []string{"i"},
Action: cmd.InstallNVM,
},
},
},
{
Name: "add-sudoers",
Aliases: []string{"su"},
Usage: "Add a user to sudoers file",
Action: cmd.AddSudoers,
},
{
Name: "postgres-backup-s3",
Aliases: []string{"pbs3"},
Usage: "Get service backup data postgres to S3",
Description: "A handy Docker container to periodically backup PostgresSQL to S3",
Action: cmd.GetTempPostgresBackupToS3,
},
{
Name: "elasticsearch-snapshot-s3",
Aliases: []string{"ens"},
Usage: "Get service elasticsearch snapshot to S3",
Description: "A handy Docker container to periodically snapshot Elasticsearch to S3",
Action: cmd.GetTempEnsToS3,
},
{
Name: "setup-docker-env",
Aliases: []string{"docker", "d"},
Usage: "Setup Docker env",
Subcommands: []*cli.Command{
{
Name: "install",
Usage: "Install Docker and Docker-compose",
Aliases: []string{"i"},
Action: cmd.SetupDockerEnv,
},
{
Name: "add-user-to-group",
Usage: "Add user to group docker",
Aliases: []string{"add"},
ArgsUsage: "<username>",
Action: cmd.AddUserToDockerGroup,
},
},
},
{
Name: "certbot",
Aliases: []string{"cert", "c"},
Usage: "Certbot helper",
Subcommands: []*cli.Command{
{
Name: "install",
Usage: "Install Certbot",
Aliases: []string{"i"},
Action: cmd.InstallCertbot,
},
{
Name: "auto-renew-guide",
Usage: "Auto renew Let's encrypt certificate for Nginx",
Aliases: []string{"a"},
Action: cmd.AutoRenewCertbotGuide,
},
{
Name: "expiry",
Usage: "Check Certificates expiry date",
Aliases: []string{"ex"},
Action: cmd.CertBotCheckExpiry,
},
},
},
{
Name: "php",
Aliases: []string{"php"},
Usage: "PHP helper",
Subcommands: []*cli.Command{
{
Name: "install",
Usage: "Install PHP",
Aliases: []string{"i"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Aliases: []string{"v"},
Value: PhpDefaultVersion, // Default PHP version
Usage: "Specify the PHP version to install",
},
},
Action: cmd.InstallPHP,
},
{
Name: "remove",
Usage: "Remove PHP",
Aliases: []string{"r"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Specify the PHP version to remove",
},
},
Action: cmd.RemovePHP,
},
},
},
{
Name: "fail2ban",
Usage: "Fail2ban Helper Commands",
Aliases: []string{"f2b"},
Subcommands: []*cli.Command{
{
Name: "install",
Usage: "Install Fail2Ban",
Aliases: []string{"i"},
Action: cmd.InstallFail2Ban,
},
{
Name: "config",
Aliases: []string{"c"},
Usage: "Generate config Fail2Ban",
Action: cmd.ConfigureFail2Ban,
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Println(err)
os.Exit(1)
}
}