2024-04-03 15:15:43 +08:00
|
|
|
import { execRootSync } from "admina"
|
2022-08-21 06:38:51 +08:00
|
|
|
import { dirname } from "patha"
|
2024-08-29 04:54:48 +08:00
|
|
|
import { addAptKeyViaURL, hasNala, installAptPack } from "setup-apt"
|
2022-07-25 15:40:05 +08:00
|
|
|
import which from "which"
|
2024-08-16 06:22:07 +08:00
|
|
|
import { isUbuntu } from "../utils/env/isUbuntu.js"
|
2022-07-25 15:40:05 +08:00
|
|
|
|
|
|
|
let binDir: string | undefined
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-07-28 10:07:30 +08:00
|
|
|
export async function setupNala(version: string, _setupDir: string, _arch: string) {
|
2022-07-25 15:46:23 +08:00
|
|
|
if (!isUbuntu()) {
|
2022-07-25 15:40:05 +08:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
if (typeof binDir === "string") {
|
|
|
|
return { binDir }
|
|
|
|
}
|
|
|
|
|
|
|
|
const maybeBinDir = which.sync("nala", { nothrow: true })
|
|
|
|
if (maybeBinDir !== null) {
|
|
|
|
binDir = dirname(maybeBinDir)
|
|
|
|
return { binDir }
|
|
|
|
}
|
|
|
|
|
2024-08-16 16:50:32 +08:00
|
|
|
await installAptPack([{ name: "python3-apt" }])
|
2024-08-09 07:16:36 +08:00
|
|
|
|
2024-08-08 04:16:16 +08:00
|
|
|
// https://gitlab.com/volian/nala/-/wikis/Installation
|
2024-08-29 04:54:48 +08:00
|
|
|
const keyFileName = await addAptKeyViaURL({
|
|
|
|
fileName: "volian-archive-nala.gpg",
|
|
|
|
keyUrl: "https://deb.volian.org/volian/nala.key",
|
|
|
|
})
|
2022-08-08 08:33:11 +08:00
|
|
|
execRootSync("/bin/bash", [
|
2022-07-28 11:27:12 +08:00
|
|
|
"-c",
|
2024-08-08 04:16:16 +08:00
|
|
|
`echo "deb [signed-by=${keyFileName}] http://deb.volian.org/volian/ nala main" | tee /etc/apt/sources.list.d/volian-archive-nala.list`,
|
2022-07-28 11:27:12 +08:00
|
|
|
])
|
2022-07-25 15:40:05 +08:00
|
|
|
|
2022-07-28 07:47:55 +08:00
|
|
|
try {
|
|
|
|
if (version !== "legacy") {
|
2024-08-16 16:50:32 +08:00
|
|
|
await installAptPack([{ name: "nala" }], true)
|
2022-07-28 07:47:55 +08:00
|
|
|
} else {
|
2024-08-16 16:50:32 +08:00
|
|
|
await installAptPack([{ name: "nala-legacy" }], true)
|
2022-07-28 07:47:55 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2024-08-16 16:50:32 +08:00
|
|
|
await installAptPack([{ name: "nala-legacy" }], true)
|
2022-07-25 15:40:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-28 10:07:30 +08:00
|
|
|
binDir = "/usr/bin" // eslint-disable-line require-atomic-updates
|
2022-07-25 15:40:05 +08:00
|
|
|
|
|
|
|
return { binDir }
|
|
|
|
}
|
2023-07-16 12:46:28 +08:00
|
|
|
|
|
|
|
export function bashWithNala(script: string) {
|
|
|
|
if (hasNala()) {
|
|
|
|
return `apt-get() { nala $@; }; export -f apt-get; ${script}; unset -f apt-get`
|
|
|
|
}
|
|
|
|
return script
|
|
|
|
}
|