-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathpkgutil.ts
341 lines (334 loc) · 9.38 KB
/
pkgutil.ts
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
interface PostProcessPkgFilenames {
pathPrefix?: string;
}
const postProcessPkgFilenames =
(options: PostProcessPkgFilenames = {}): Fig.Generator["postProcess"] =>
(out) => {
const { pathPrefix = "" } = options;
const names = new Set<string>();
out.split("\n").map((line) => {
if (line.startsWith(pathPrefix)) {
const result = line.replace(pathPrefix, "").split("/")[0];
if (result) {
names.add(result + "/");
}
}
});
const suggestions = [];
names.forEach((name) => suggestions.push({ name }));
return suggestions;
};
export const pkgutilGenerators: Record<string, Fig.Generator> = {
// BOM files
bom: {
script: ["find", ".", "-type", "f", "-name", "*.bom", "-maxdepth", "1"],
postProcess: function (out) {
return out.split("\n").map((filepath) => ({
name: filepath.replace("./", ""),
}));
},
},
// Installed package ids
packageIds: {
script: ["pkgutil", "--pkgs"],
splitOn: "\n",
},
// .pkg files
pkgs: {
script: ["find", ".", "-type", "f", "-name", "*.pkg", "-maxdepth", "1"],
postProcess: function (out) {
return out.split("\n").map((filepath) => ({
name: filepath.replace("./", ""),
}));
},
},
// group ids
groupIds: {
script: ["pkgutil", "--groups"],
splitOn: "\n",
},
// filenames within a package
pkgFilenames: {
custom: async (tokens, executeShellCommand) => {
const editPkgIndex = tokens.indexOf("--edit-pkg");
const pkgIdIndex = editPkgIndex + 1;
if (editPkgIndex === -1 || pkgIdIndex >= tokens.length) {
return [];
}
const pkgId = tokens[pkgIdIndex];
const pathPrefix = tokens[tokens.length - 1];
const pp = postProcessPkgFilenames({ pathPrefix });
return pp(
(
await executeShellCommand({
command: "pkgutil",
args: ["--files", pkgId],
})
).stdout,
tokens
);
},
trigger: "/",
},
};
const completionSpec: Fig.Spec = {
name: "pkgutil",
description: "Query and manipulate for macOS Installer packages and receipts",
subcommands: [
{
name: ["--packages", "--pkgs"],
description: "List all installed package IDs on the specified --volume",
},
{
name: "--pkgs-plist",
description:
"List all installed package IDs, in Mac OS X plist(5) format, on the specified --volume",
},
{
name: "--files",
description: "List all of the files installed under the package-id",
args: {
name: "package-id",
description: "The package ID to list the files of",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--export-plist",
description:
"Print all receipt information about the specified package-id in Mac OS X plist(5) format",
args: {
name: "package-id",
description: "The package ID to export the plist of",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--verify",
description: "Run repair_packages(8) to verify the specified package-id",
args: {
name: "package-id",
description: "The package ID to verify",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--repair",
description: "Run repair_packages(8) to repair the specified package-id",
args: {
name: "package-id",
description: "The package ID to repair",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--pkg-info",
description: "Print extended information about the specified package-id",
args: {
name: "package-id",
description: "The package ID to print the info of",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--pkg-info-plist",
description:
"Print extended information about the specified package-id in Mac OS X plist(5) format",
args: {
name: "package-id",
description: "The package ID to print the info of",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--forget",
description:
"Discard all receipt data about package-id, but don't touch installed files",
args: {
name: "package-id",
description: "The package ID to forget",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--learn",
description:
"Update the ACLs of the given path in the receipt identified by --edit-pkg",
args: {
name: "path",
description: "The path to update ACLs on",
generators: pkgutilGenerators.pkgFilenames,
},
},
{
name: "--pkg-groups",
description:
"List all of the package groups this package-id is a member of",
args: {
name: "package-id",
description: "The package ID to list the groups of",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--groups",
description: "List all of the package groups ont he specified --volume",
},
{
name: "--group-plist",
description:
"List all of the package groups ont he specified --volume in Mac OS X plist(5) format",
},
{
name: "--group-pkgs",
description: "List all of the packages that are members of this group-id",
args: {
name: "group-id",
description: "The group ID to list the packages of",
generators: pkgutilGenerators.groupIds,
},
},
{
name: "--file-info",
description: "Show the metadata known about path",
args: {
name: "path",
description: "The path to show the metadata of",
template: "filepaths",
},
},
{
name: "--file-info-plist",
description:
"Show the metadata known about path in Mac OS X plist(5) format",
args: {
name: "path",
description: "The path to show the metadata of",
template: "filepaths",
},
},
{
name: "--expand",
description:
"Expand the flat package at pkg-path into a new directory specified by dir-path",
args: [
{
name: "pkg-path",
description: "The path to the flat package to expand",
template: "filepaths",
},
{
name: "dir-path",
description: "The path to the directory to expand the package into",
template: "folders",
},
],
},
{
name: "--flatten",
description:
"Flatten the dir-path into a new flat package created at pkg-path",
args: [
{
name: "dir-path",
description: "The path to the directory to flatten",
template: "folders",
},
{
name: "pkg-path",
description: "The path to the flat package to create",
template: "filepaths",
},
],
},
{
name: "--bom",
description:
"Extract any BOM files from the flat pkg at path into /tmp and return the filename(s)",
args: {
name: "path",
description: "The path to the flat package to extract the BOM from",
generators: pkgutilGenerators.bom,
},
},
{
name: "--payload-files",
description:
"List the files archived within the uninstalled flat package(s) at path",
args: {
name: "path",
description:
"The path to the flat package to list the archived files of",
generators: pkgutilGenerators.pkgs,
},
},
{
name: "--check-signature",
description:
"Check the validity and trust of the signature on the package at pkg-path",
args: {
name: "pkg-path",
description: "The path to the flat package to check the signature of",
generators: pkgutilGenerators.pkgs,
},
},
],
options: [
{
name: ["-h", "--help"],
description: "A brief summary of commands and usage",
},
{
name: ["-f", "--force"],
description:
"Skip confirmation before a potentially destructive or ambiguous action",
},
{
name: ["-v", "--verbose"],
description: "Output in a human-readable format",
},
{
name: "--volume",
description: "Perform all operations on specified volume",
args: {
name: "volume",
description: "Volume to perform operations on",
template: "folders",
},
},
{
name: "--edit-pkg",
description:
"Specifies an existing receipt to be modified in-place by --learn",
args: {
name: "package-id",
description: "Package ID of the receipt to modify",
generators: pkgutilGenerators.packageIds,
},
},
{
name: "--only-files",
description: "List only files (not directories) in --files listing",
},
{
name: "--only-dirs",
description: "List only directories (not files) in --files listing",
},
{
name: "--regexp",
description:
"Use regex to match package-id arguments, if an exact match isn't found",
},
{
name: "--pkgs",
description:
"List all installed package IDs, optionally matching kwarg REGEXP, on the specified --volume",
requiresSeparator: true,
args: {
name: "REGEXP",
description: "Regular expression",
},
},
],
};
export default completionSpec;