2024-08-29 06:17:21 +08:00
|
|
|
import { defaultExecOptions, execRootSync } from "admina"
|
|
|
|
import { getAptEnv } from "./apt-env.js"
|
|
|
|
import { aptTimeout } from "./apt-timeout.js"
|
|
|
|
import { getApt } from "./get-apt.js"
|
2024-08-29 06:29:31 +08:00
|
|
|
import { initAptMemoized } from "./init-apt.js"
|
2024-08-29 06:17:21 +08:00
|
|
|
import { isAptPackInstalled } from "./is-installed.js"
|
2024-08-29 06:29:31 +08:00
|
|
|
import { updateAptReposMemoized } from "./update.js"
|
2024-08-29 06:17:21 +08:00
|
|
|
|
|
|
|
export async function addAptRepository(repo: string, apt = getApt()) {
|
2024-08-29 06:29:31 +08:00
|
|
|
await initAptMemoized(apt)
|
2024-08-29 06:17:21 +08:00
|
|
|
await installAddAptRepo(apt)
|
|
|
|
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getAptEnv(apt) })
|
2024-08-29 06:29:31 +08:00
|
|
|
|
|
|
|
// clear the cache
|
|
|
|
updateAptReposMemoized.cache.keys = []
|
|
|
|
updateAptReposMemoized.cache.values = []
|
|
|
|
updateAptReposMemoized(apt)
|
2024-08-29 06:17:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function installAddAptRepo(apt: string) {
|
|
|
|
if (await isAptPackInstalled("software-properties-common")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
execRootSync(
|
|
|
|
apt,
|
|
|
|
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
|
|
|
|
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
|
|
|
)
|
|
|
|
}
|