This repository was archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcmds.go
257 lines (194 loc) · 6.65 KB
/
cmds.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package main
import (
"os"
"runtime"
"strings"
)
// List installed packages.
func listPkgs() {
installedPkgs := make([]string, 0)
files := dirContents(infoPath, "An error occurred while getting list of installed packages")
if len(files) == 0 {
log(1, "No packages installed.")
os.Exit(0)
}
for _, file := range files {
installedPkgs = append(installedPkgs, strings.ReplaceAll(file.Name(), ".json", ""))
}
rawLog(strings.Join(installedPkgs, "\n") + "\n")
}
// Gets info for a package.
func infoPkg(pkgName string) {
pkg := loadPkg(getPkgInfo(pkgName, isValidURL(pkgName)), pkgName)
safePrintVal := func(name string, val string) {
if val != "" {
log(1, "%s: %s", name, val)
} else {
log(1, "%s: Undefined", name)
}
}
rawLog("\n")
log(1, "Name: %s", pkg.Name)
log(1, "Author: %s", pkg.Author)
log(1, "Description: %s", pkg.Description)
safePrintVal("License", pkg.License)
safePrintVal("Programming Language", pkg.Language)
safePrintVal("Git URL", pkg.URL)
if pkg.Bin != nil {
log(1, "Binaries: %s", strings.Join(pkg.Bin.Installed, ", "))
}
if deps := getDeps(pkg.Deps); deps != nil {
log(1, "Dependencies: %s", strings.Join(deps, ", "))
}
if deps := getDeps(pkg.FileDeps); deps != nil {
log(1, "File dependencies: %s", strings.Join(deps, ", "))
}
getNotes(pkg)
}
// Removes data for packages.
func rmData(pkgNames []string) {
log(3, "Warning: This will remove the data for the selected packages stored in %s", mainPath)
log(3, "This will %snot%s run the uninstall commands.", textFx.Bold, RESETCOL)
log(3, "You should only use this in case a package installation has failed at a certain step, or you want to separate an installed package from indiepkg.")
displayPkgs(pkgNames, "remove the data for")
for _, pkgName := range pkgNames {
chapLog("=>", "", "Removing data for %s", pkgName)
pkgDisplayName := bolden(pkgName)
log(1, "Deleting source files for %s...", pkgDisplayName)
delPath(false, srcPath+pkgName, "An error occurred while deleting source files for %s", pkgDisplayName)
log(1, "Deleting info file for %s...", pkgDisplayName)
delPath(false, infoPath+pkgName+".json", "An error occurred while deleting info file for %s", pkgDisplayName)
log(0, "Successfully deleted the data for %s.\n", pkgDisplayName)
}
chapLog("=>", textCol.Green, "Success")
log(0, "Successfully deleted data.")
}
// Searches for a package.
func search(query string) {
initDirs(false)
loadConfig()
pkgs, _ := getPkgFromGh(query)
rawLog("\n")
log(1, "Found %d packages:", len(pkgs))
for _, pkg := range pkgs {
rawLog(" " + pkg.Name + " - " + pkg.Repo + "\n")
}
}
// Lists all packages in the repos.
func listAll() {
initDirs(false)
loadConfig()
pkgs, _ := getAllPkgsFromGh()
rawLog("\n")
log(1, "Found %d packages:", len(pkgs))
for _, pkg := range pkgs {
rawLog(" " + pkg.Name + " - " + repoLabel(pkg.Repo, true) + "\n")
}
}
// Fetches and displays system & go info.
func fetch() {
configExists := pathExists(configPath+"config.toml", "config file")
if configExists {
loadConfig()
} else {
log(3, "No config file found, skipping configuration related info.")
}
chapLog("=>", "", "OS & Environment")
log(1, "OS: %s", runtime.GOOS)
log(1, "Arch: %s", runtime.GOARCH)
log(1, "Go Version: %s", strings.TrimPrefix(runtime.Version(), "go"))
if isRoot() {
log(3, "Running as %s", textCol.Red+"root"+RESETCOL)
} else {
log(1, "Running as %s", textCol.Green+"normal user"+RESETCOL)
}
macOSVer, err := runCommand(".", "sw_vers", "-productVersion")
if err == nil {
log(1, "macOS version: %s", macOSVer)
}
if pathExists("/etc/os-release", "os release") {
log(1, "OS-Release:")
indent(readFile("/etc/os-release", "An error occurred while reading /etc/os-release"))
}
kern, err := runCommand(".", "uname", "-rsp")
if err != nil {
log(3, "Could not get kernel info. Error: %s", err.Error())
} else {
log(1, "Kernel: %s", kern)
}
chapLog("=>", "", "IndiePKG Information")
log(1, "IndiePKG Version: %s", version)
indiePkgPath, err := os.Executable()
if err != nil {
log(3, "Could not get IndiePKG path. Error: %s", err.Error())
} else {
log(1, "IndiePKG Path: %s", indiePkgPath)
}
if configExists {
log(1, "IndiePKG Branch: %s", config.Updating.Branch)
}
chapLog("=>", "", "CLI Information")
log(1, "Shell: %s", os.Getenv("SHELL"))
log(1, "TERM: %s", os.Getenv("TERM"))
bashVer, err := runCommand(".", "bash", "--version")
if err == nil {
log(1, "Bash version: %s", strings.Split(strings.TrimPrefix(strings.Split(bashVer, "\n")[0], "GNU bash, version "), "(")[0])
} else {
log(3, "Could not get bash version. Error: %s", err.Error())
}
zshVer, err := runCommand(".", "zsh", "--version")
if err == nil {
log(1, "Zsh version: %s", strings.Split(strings.TrimPrefix(zshVer, "zsh "), "(")[0])
} else {
log(3, "Could not get zsh version. Error: %s", err.Error())
}
}
// Runs help2man for indiepkg.
func help2man() {
log(1, "Compiling IndiePKG...")
_, err := runCommand(".", "make")
errorLog(err, "An error occurred while compiling IndiePKG")
log(1, "Running help2man...")
output, _ := runCommand(".", "help2man", "-h", "help", "-v", "raw-version", "./indiepkg")
log(1, "Parsing generated manpage...")
output = strings.ReplaceAll(output, ".TP", ".SS")
output = strings.ReplaceAll(output, ".SS \"Commands:\"\n", "")
output = strings.ReplaceAll(output, ".SS \"Developer & Debugging Commands:\"\n", "")
log(1, "Writing final manpage...")
newFile("indiepkg.1", output, "An error occurred while writing generated manpage")
}
func reCompile(pkgNames []string) {
displayPkgs(pkgNames, "re-compile")
fullInit()
for _, pkgName := range pkgNames {
pkgDispName := bolden(pkgName)
chapLog("==>", "", "Preparing for re-compilation of %s", pkgDispName)
chapLog("===>", "", "Checking if already installed")
log(1, "Checking if %s is already installed...", pkgDispName)
if !pkgExists(pkgName) {
if force {
log(3, "%s is not installed, but force is on, so continuing.", pkgDispName)
} else {
errorLogRaw("%s is not installed, so it can't be re-compiled", pkgDispName)
}
}
chapLog("===>", "", "Getting info")
pkg := readLoad(pkgName)
cmds := getInstCmd(pkg)
chapLog("===>", "", "Checking dependencies")
checkDeps(pkg)
checkFileDeps(pkg)
chapLog("==>", "", "Re-installing")
if len(cmds) > 0 {
chapLog("===>", "", "Compiling")
runCmds(cmds, pkg, srcPath+pkg.Name, "install")
}
chapLog("===>", "", "Moving files")
copyBins(pkg, srcPath)
copyManpages(pkg, srcPath)
chapLog("===>", textCol.Green, "Success")
log(0, "Successfully re-compiled %s.", pkgDispName)
}
chapLog("=>", textCol.Green, "Success")
log(0, "Successfully re-compiled all selected packages.")
}