Skip to content

Commit d204be8

Browse files
committed
feat: support add apt key via download or from a server
1 parent 5183c0d commit d204be8

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

cspell.config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ words:
1212
- aarch
1313
- aminya
1414
- applellvm
15+
- bazel
16+
- copr
17+
- vbatts
1518
- buildtools
1619
- caxa
1720
- ccache

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/setup_cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/bazel/bazel.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setupAptPack } from "../utils/setup/setupAptPack"
1+
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
22
import { setupBrewPack } from "../utils/setup/setupBrewPack"
33
import { setupChocoPack } from "../utils/setup/setupChocoPack"
44
import { isArch } from "../utils/env/isArch"
@@ -26,14 +26,13 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
2626
return setupDnfPack("bazel4", undefined)
2727
} else if (isUbuntu()) {
2828
// https://bazel.build/install/ubuntu
29+
const keyFileName = await addAptKeyViaDownload(
30+
"bazel-archive-keyring.gpg",
31+
"https://bazel.build/bazel-release.pub.gpg"
32+
)
2933
execSudo("bash", [
3034
"-c",
31-
"wget -qO - https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg > /dev/null",
32-
])
33-
execSudo("bash", ["-c", "mv bazel-archive-keyring.gpg /usr/share/keyrings"])
34-
execSudo("bash", [
35-
"-c",
36-
'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list',
35+
`echo "deb [arch=amd64 signed-by=${keyFileName}] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list`,
3736
])
3837
return setupAptPack("bazel", version, [], true)
3938
}

src/nala/nala.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { dirname } from "path"
22
import which from "which"
33
import { isUbuntu } from "../utils/env/isUbuntu"
44
import { execSudo } from "../utils/exec/sudo"
5-
import { setupAptPack } from "../utils/setup/setupAptPack"
5+
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
66

77
let binDir: string | undefined
88

@@ -22,15 +22,11 @@ export async function setupNala(version: string, _setupDir: string, _arch: strin
2222
}
2323

2424
// https://github.com/volitank/nala#-installation
25-
await setupAptPack("wget")
26-
execSudo("/bin/bash", [
27-
"-c",
28-
`wget -qO - https://deb.volian.org/volian/scar.key | tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null`,
29-
])
30-
execSudo("/bin/bash", [
31-
"-c",
32-
`echo "deb http://deb.volian.org/volian/ scar main" | tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list`,
33-
])
25+
const keyFileName = await addAptKeyViaDownload(
26+
"volian-archive-scar-unstable.gpg",
27+
"https://deb.volian.org/volian/scar.key"
28+
)
29+
execSudo("/bin/bash", ["-c", `echo "deb http://deb.volian.org/volian/ scar main" | tee ${keyFileName}`])
3430

3531
try {
3632
if (version !== "legacy") {

src/utils/setup/setupAptPack.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { InstallationInfo } from "./setupBin"
33
import { execSudo } from "../exec/sudo"
44
import { info } from "@actions/core"
5-
import { warning } from "../io/io"
65
import { isGitHubCI } from "../env/isCI"
76
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"
87
import { appendFileSync, existsSync } from "fs"
@@ -18,10 +17,10 @@ export async function setupAptPack(
1817
repositories: string[] = [],
1918
update = false
2019
): Promise<InstallationInfo> {
21-
info(`Installing ${name} ${version ?? ""} via apt`)
22-
2320
const apt: string = getApt()
2421

22+
info(`Installing ${name} ${version ?? ""} via ${apt}`)
23+
2524
process.env.DEBIAN_FRONTEND = "noninteractive"
2625

2726
if (!didUpdate || update) {
@@ -80,33 +79,42 @@ async function initApt(apt: string) {
8079
"ca-certificates",
8180
"gnupg",
8281
])
83-
addAptKey(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg")
84-
addAptKey(["1E9377A2BA9EF27F"], "setup-cpp-launchpad-toolchain.gpg")
82+
addAptKeyViaServer(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg")
83+
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg")
8584
if (apt === "nala") {
8685
// enable utf8 otherwise it fails because of the usage of ASCII encoding
8786
await addEnv("LANG", "C.UTF-8")
8887
await addEnv("LC_ALL", "C.UTF-8")
8988
}
9089
}
9190

92-
function addAptKey(keys: string[], name: string) {
93-
try {
94-
if (!existsSync(`/root/.gnupg/${name}`)) {
95-
for (const key of keys) {
96-
execSudo("gpg", [
97-
"--no-default-keyring",
98-
"--keyring",
99-
name,
100-
"--keyserver",
101-
"keyserver.ubuntu.com",
102-
"--recv-keys",
103-
key,
104-
])
105-
}
91+
export function addAptKeyViaServer(keys: string[], name: string, server = "keyserver.ubuntu.com") {
92+
const fileName = `/etc/apt/trusted.gpg.d/${name}`
93+
if (!existsSync(fileName)) {
94+
for (const key of keys) {
95+
execSudo("gpg", [
96+
"--no-default-keyring",
97+
"--keyring",
98+
`gnupg-ring:${fileName}`,
99+
"--keyserver",
100+
server,
101+
"--recv-keys",
102+
key,
103+
])
104+
execSudo("chmod", ["644", fileName])
106105
}
107-
} catch (err) {
108-
warning(`Failed to add keys: ${err}`)
109106
}
107+
return fileName
108+
}
109+
110+
export async function addAptKeyViaDownload(name: string, url: string) {
111+
const fileName = `/etc/apt/trusted.gpg.d/${name}`
112+
if (!existsSync(fileName)) {
113+
await setupAptPack("curl", undefined)
114+
execSudo("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
115+
execSudo("chmod", ["644", fileName])
116+
}
117+
return fileName
110118
}
111119

112120
export function updateAptAlternatives(name: string, path: string) {

0 commit comments

Comments
 (0)