mirror of https://github.com/aminya/setup-cpp
fix!: rename setup-apt functions to include the name apt
This commit is contained in:
parent
e881f4079c
commit
9d12380389
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -37,10 +37,12 @@ handles adding conditions to source rc file from .bashrc and .profile
|
||||||
|
|
||||||
### `escapeString` (function)
|
### `escapeString` (function)
|
||||||
|
|
||||||
|
Escape a string for use in a shell command
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
- valGiven (`string`)
|
- valGiven (`string`) - The string to escape
|
||||||
- shouldEscapeSpace (`boolean`)
|
- shouldEscapeSpace (`boolean`) - Whether to escape spaces in the string
|
||||||
|
|
||||||
**returns:** any
|
**returns:** any
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@ import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
|
||||||
import { escapeString } from "./utils.js"
|
import { escapeString } from "./utils.js"
|
||||||
const { appendFile } = promises
|
const { appendFile } = promises
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The options for adding an environment variable
|
||||||
|
*/
|
||||||
export type AddEnvOptions = {
|
export type AddEnvOptions = {
|
||||||
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
|
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
|
||||||
escapeSpace: boolean
|
escapeSpace: boolean
|
||||||
|
|
|
@ -7,6 +7,9 @@ import { execPowershell } from "exec-powershell"
|
||||||
import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
|
import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
|
||||||
const { appendFile } = promises
|
const { appendFile } = promises
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The options for adding a PATH variable
|
||||||
|
*/
|
||||||
type AddPathOptions = {
|
type AddPathOptions = {
|
||||||
/**
|
/**
|
||||||
* The path to the RC file that the PATH variables should be added to.
|
* The path to the RC file that the PATH variables should be added to.
|
||||||
|
|
|
@ -8,6 +8,9 @@ const { appendFile, readFile, writeFile } = promises
|
||||||
|
|
||||||
export const defaultRcPath = untildifyUser("~/.bashrc")
|
export const defaultRcPath = untildifyUser("~/.bashrc")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for adding an rc file
|
||||||
|
*/
|
||||||
export type RcOptions = {
|
export type RcOptions = {
|
||||||
/** The path to the RC file that the env variables should be added to. */
|
/** The path to the RC file that the env variables should be added to. */
|
||||||
rcPath: string
|
rcPath: string
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
import escapeSpace from "escape-path-with-spaces"
|
import escapeSpace from "escape-path-with-spaces"
|
||||||
import escapeQuote from "escape-quotes"
|
import escapeQuote from "escape-quotes"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape a string for use in a shell command
|
||||||
|
* @param valGiven The string to escape
|
||||||
|
* @param shouldEscapeSpace Whether to escape spaces in the string
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
export function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
|
export function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
|
||||||
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
||||||
return escapeQuote(spaceEscaped, "\"", "\\")
|
return escapeQuote(spaceEscaped, "\"", "\\")
|
||||||
|
|
|
@ -64,7 +64,7 @@ Check if a package matching a regexp is installed
|
||||||
|
|
||||||
**returns:** Promise<boolean>
|
**returns:** Promise<boolean>
|
||||||
|
|
||||||
### `updateRepos` (function)
|
### `updateAptRepos` (function)
|
||||||
|
|
||||||
Update the apt repositories
|
Update the apt repositories
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ If nala is installed, use that, otherwise use apt-get
|
||||||
|
|
||||||
**returns:** string
|
**returns:** string
|
||||||
|
|
||||||
### `getEnv` (function)
|
### `getAptEnv` (function)
|
||||||
|
|
||||||
Get the environment variables to use for the apt command
|
Get the environment variables to use for the apt command
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { type ExecaError, execa } from "execa"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { addAptKeyViaServer } from "./apt-key.js"
|
import { addAptKeyViaServer } from "./apt-key.js"
|
||||||
import { isAptPackInstalled } from "./is-installed.js"
|
import { isAptPackInstalled } from "./is-installed.js"
|
||||||
import { updateRepos } from "./update.js"
|
import { updateAptRepos } from "./update.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The information about an installation result
|
* The information about an installation result
|
||||||
|
@ -63,7 +63,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
||||||
|
|
||||||
// Update the repos if needed
|
// Update the repos if needed
|
||||||
if (update) {
|
if (update) {
|
||||||
updateRepos(apt)
|
updateAptRepos(apt)
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,10 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
||||||
|
|
||||||
// Install
|
// Install
|
||||||
try {
|
try {
|
||||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], { ...defaultExecOptions, env: getEnv(apt) })
|
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], {
|
||||||
|
...defaultExecOptions,
|
||||||
|
env: getAptEnv(apt),
|
||||||
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isExecaError(err)) {
|
if (isExecaError(err)) {
|
||||||
if (retryErrors.some((error) => err.stderr.includes(error))) {
|
if (retryErrors.some((error) => err.stderr.includes(error))) {
|
||||||
|
@ -93,7 +96,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
||||||
execRootSync(
|
execRootSync(
|
||||||
apt,
|
apt,
|
||||||
["install", "--fix-broken", "-y", "-o", aptTimeout, ...needToInstall],
|
["install", "--fix-broken", "-y", "-o", aptTimeout, ...needToInstall],
|
||||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,7 +137,7 @@ export function getApt() {
|
||||||
* @param apt The apt command to use
|
* @param apt The apt command to use
|
||||||
* @private Used internally
|
* @private Used internally
|
||||||
*/
|
*/
|
||||||
export function getEnv(apt: string) {
|
export function getAptEnv(apt: string) {
|
||||||
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
|
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
|
||||||
|
|
||||||
if (apt === "nala") {
|
if (apt === "nala") {
|
||||||
|
@ -185,9 +188,9 @@ async function addRepositories(apt: string, packages: AptPackage[]) {
|
||||||
await installAddAptRepo(apt)
|
await installAddAptRepo(apt)
|
||||||
for (const repo of allRepositories) {
|
for (const repo of allRepositories) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getEnv(apt) })
|
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getAptEnv(apt) })
|
||||||
}
|
}
|
||||||
updateRepos(apt)
|
updateAptRepos(apt)
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +201,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
||||||
"search",
|
"search",
|
||||||
"--names-only",
|
"--names-only",
|
||||||
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
|
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
|
||||||
], { env: getEnv(apt), stdio: "pipe" })
|
], { env: getAptEnv(apt), stdio: "pipe" })
|
||||||
if (stdout.trim() !== "") {
|
if (stdout.trim() !== "") {
|
||||||
return AptPackageType.NameDashVersion
|
return AptPackageType.NameDashVersion
|
||||||
}
|
}
|
||||||
|
@ -206,7 +209,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
||||||
try {
|
try {
|
||||||
// check if apt-get show can find the version
|
// check if apt-get show can find the version
|
||||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||||
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getEnv(apt) })
|
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getAptEnv(apt) })
|
||||||
if (stdout.trim() === "") {
|
if (stdout.trim() === "") {
|
||||||
return AptPackageType.NameEqualsVersion
|
return AptPackageType.NameEqualsVersion
|
||||||
}
|
}
|
||||||
|
@ -216,7 +219,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getEnv(apt), stdio: "pipe" })
|
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getAptEnv(apt), stdio: "pipe" })
|
||||||
if (showStdout.trim() !== "") {
|
if (showStdout.trim() !== "") {
|
||||||
return AptPackageType.Name
|
return AptPackageType.Name
|
||||||
}
|
}
|
||||||
|
@ -226,7 +229,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
||||||
|
|
||||||
// If apt-cache fails, update the repos and try again
|
// If apt-cache fails, update the repos and try again
|
||||||
if (!didUpdate) {
|
if (!didUpdate) {
|
||||||
updateRepos(getApt())
|
updateAptRepos(getApt())
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
return aptPackageType(apt, name, version)
|
return aptPackageType(apt, name, version)
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,7 @@ async function installAddAptRepo(apt: string) {
|
||||||
execRootSync(
|
execRootSync(
|
||||||
apt,
|
apt,
|
||||||
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
|
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
|
||||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +269,7 @@ async function installAddAptRepo(apt: string) {
|
||||||
async function initApt(apt: string) {
|
async function initApt(apt: string) {
|
||||||
// Update the repos if needed
|
// Update the repos if needed
|
||||||
if (!didUpdate) {
|
if (!didUpdate) {
|
||||||
updateRepos(apt)
|
updateAptRepos(apt)
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +282,7 @@ async function initApt(apt: string) {
|
||||||
if (toInstall.length !== 0) {
|
if (toInstall.length !== 0) {
|
||||||
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, ...toInstall], {
|
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, ...toInstall], {
|
||||||
...defaultExecOptions,
|
...defaultExecOptions,
|
||||||
env: getEnv(apt),
|
env: getAptEnv(apt),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { execa } from "execa"
|
import { execa } from "execa"
|
||||||
import { getEnv } from "./install.js"
|
import { getAptEnv } from "./install.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a package is installed
|
* Check if a package is installed
|
||||||
|
@ -9,7 +9,7 @@ import { getEnv } from "./install.js"
|
||||||
export async function isAptPackInstalled(pack: string) {
|
export async function isAptPackInstalled(pack: string) {
|
||||||
try {
|
try {
|
||||||
// check if a package is installed
|
// check if a package is installed
|
||||||
const { stdout } = await execa("dpkg", ["-s", pack], { env: getEnv("apt-get"), stdio: "pipe" })
|
const { stdout } = await execa("dpkg", ["-s", pack], { env: getAptEnv("apt-get"), stdio: "pipe" })
|
||||||
if (typeof stdout !== "string") {
|
if (typeof stdout !== "string") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ export async function isAptPackInstalled(pack: string) {
|
||||||
export async function isAptPackRegexInstalled(regexp: string) {
|
export async function isAptPackRegexInstalled(regexp: string) {
|
||||||
try {
|
try {
|
||||||
// check if a package matching the regexp is installed
|
// check if a package matching the regexp is installed
|
||||||
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getEnv("apt-get"), stdio: "pipe" })
|
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getAptEnv("apt-get"), stdio: "pipe" })
|
||||||
if (typeof stdout !== "string") {
|
if (typeof stdout !== "string") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import { defaultExecOptions, execRootSync } from "admina"
|
import { defaultExecOptions, execRootSync } from "admina"
|
||||||
import { aptTimeout, getApt, getEnv } from "./install.js"
|
import { aptTimeout, getApt, getAptEnv } from "./install.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the apt repositories
|
* Update the apt repositories
|
||||||
* @param apt The apt command to use (optional)
|
* @param apt The apt command to use (optional)
|
||||||
*/
|
*/
|
||||||
export function updateRepos(apt: string = getApt()) {
|
export function updateAptRepos(apt: string = getApt()) {
|
||||||
execRootSync(
|
execRootSync(
|
||||||
apt,
|
apt,
|
||||||
apt !== "nala" ? ["update", "-y", "-o", aptTimeout] : ["update", "-o", aptTimeout],
|
apt !== "nala" ? ["update", "-y", "-o", aptTimeout] : ["update", "-o", aptTimeout],
|
||||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue