Repository navigation
Expand file tree
/
Copy pathflatpak.ts
More file actions
87 lines (75 loc) · 2.8 KB
/
Copy pathflatpak.ts
File metadata and controls
87 lines (75 loc) · 2.8 KB
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
import chalk from "chalk"
import { Config } from "@quados/models"
import {
flatpakExec,
flatpakExecNoninteractive,
execAsync,
} from "@quados/helpers"
const getInstalled = async () =>
(await flatpakExec("list --app --columns application"))
.split("\n")
.filter((line) => line.length) ?? []
export const install = async (config: Config) => {
const installedFlatpaks = await getInstalled()
const pkgsToInstall = config.pkgs.filter(
(pkg) => !installedFlatpaks.includes(pkg.id)
)
if (pkgsToInstall.length) {
await flatpakExecNoninteractive(
`install ${pkgsToInstall.map((pkg) => pkg.id).join(" ")}`
)
try {
const mask = `pkexec flatpak mask "*"`
await execAsync(`${mask} --remove`)
for (const pkg of config.pkgs) {
const commit = (
await execAsync(
`flatpak remote-info --log ${pkg.origin} ${pkg.id} --system | grep 'Commit: ${pkg.commit}' | sed 's/^.*: //'`
)
).replace("\n", "")
if (!commit) throw chalk.red.bold("Invalid commit provided!")
await execAsync(
`pkexec flatpak update ${pkg.id} --commit ${commit} --noninteractive --system`
)
}
await execAsync(mask)
} catch (error) {
if (!error.includes("No current masked pattern matching *"))
throw error
}
}
}
// export const configure = async (config: Config) => {
// for (const pkg of config.pkgs) {
// const localBin = join(homedir(), ".local", "bin")
// await execAsync(`mkdir -p ${localBin}`)
// await writeFile(
// join(localBin, pkg.name),
// `#!/usr/bin/env bash
// exec flatpak run ${pkg.id} "$@"`,
// { mode: 0o755 }
// )
// const configFolder = join(homedir(), ".var", "app", pkg.id, "config")
// await execAsync(`mkdir -p ${configFolder}`)
// for (const configSymlink in pkg.config.symlinks) {
// const sym = pkg.config.symlinks[configSymlink]
// try {
// await symlink(sym.source, join(configFolder, configSymlink))
// } catch {}
// await flatpakAddPermission(
// pkg.id,
// configSymlink,
// sym.readonly ?? false
// )
// }
// for (const configFile in pkg.config.files) {
// const file = pkg.config.files[configFile]
// await writeFile(join(configFolder, configFile), file.source)
// await flatpakAddPermission(
// pkg.id,
// configFile,
// file.readonly ?? false
// )
// }
// }
// }