2022-07-25 15:40:05 +08:00
|
|
|
import { dirname } from "path"
|
|
|
|
import which from "which"
|
2022-07-25 15:46:23 +08:00
|
|
|
import { isUbuntu } from "../utils/env/isUbuntu"
|
2022-07-25 15:40:05 +08:00
|
|
|
import { execSudo } from "../utils/exec/sudo"
|
|
|
|
import { setupAptPack } from "../utils/setup/setupAptPack"
|
|
|
|
|
|
|
|
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 }
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/volitank/nala#-installation
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("wget")
|
2022-07-25 15:40:05 +08:00
|
|
|
execSudo("/bin/bash", [
|
|
|
|
"-c",
|
2022-07-28 07:38:10 +08:00
|
|
|
`wget -qO - https://deb.volian.org/volian/scar.key | tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null`,
|
2022-07-25 15:40:05 +08:00
|
|
|
])
|
|
|
|
execSudo("/bin/bash", [
|
|
|
|
"-c",
|
2022-07-28 07:38:10 +08:00
|
|
|
`echo "deb http://deb.volian.org/volian/ scar main" | tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list`,
|
2022-07-25 15:40:05 +08:00
|
|
|
])
|
|
|
|
|
2022-07-28 07:47:55 +08:00
|
|
|
try {
|
|
|
|
if (version !== "legacy") {
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("nala", undefined, [], true)
|
2022-07-28 07:47:55 +08:00
|
|
|
} else {
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("nala-legacy", undefined, [], true)
|
2022-07-28 07:47:55 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2022-07-28 10:07:30 +08:00
|
|
|
await setupAptPack("nala-legacy", undefined, [], 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 }
|
|
|
|
}
|