mirror of
https://github.com/DeterminateSystems/nix-installer-action.git
synced 2024-12-23 13:32:06 +01:00
Merge branch 'main' into hoverbear/fh-160-action-should-work-under-nektosact-in-the-absence-of-systemd
This commit is contained in:
commit
4126bb83b3
3 changed files with 35 additions and 15 deletions
22
dist/index.js
generated
vendored
22
dist/index.js
generated
vendored
|
@ -495,11 +495,14 @@ class NixInstallerAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async setup_kvm() {
|
async setup_kvm() {
|
||||||
|
const current_user = (0,node_os__WEBPACK_IMPORTED_MODULE_8__.userInfo)();
|
||||||
|
const is_root = current_user.uid === 0;
|
||||||
|
const maybe_sudo = is_root ? "" : "sudo";
|
||||||
const kvm_rules = "/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
|
const kvm_rules = "/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
|
||||||
try {
|
try {
|
||||||
const write_file_exit_code = await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec("sh", [
|
const write_file_exit_code = await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec("sh", [
|
||||||
"-c",
|
"-c",
|
||||||
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee ${kvm_rules} > /dev/null`,
|
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | ${maybe_sudo} tee ${kvm_rules} > /dev/null`,
|
||||||
], {
|
], {
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
|
@ -520,7 +523,11 @@ class NixInstallerAction {
|
||||||
if (write_file_exit_code !== 0) {
|
if (write_file_exit_code !== 0) {
|
||||||
throw new Error(`Non-zero exit code of \`${write_file_exit_code}\` detected while writing '${kvm_rules}'`);
|
throw new Error(`Non-zero exit code of \`${write_file_exit_code}\` detected while writing '${kvm_rules}'`);
|
||||||
}
|
}
|
||||||
const debug_run_throw = async (action, command, args) => {
|
const debug_root_run_throw = async (action, command, args) => {
|
||||||
|
if (!is_root) {
|
||||||
|
args = [command, ...args];
|
||||||
|
command = "sudo";
|
||||||
|
}
|
||||||
const reload_exit_code = await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(command, args, {
|
const reload_exit_code = await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(command, args, {
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
|
@ -542,20 +549,23 @@ class NixInstallerAction {
|
||||||
throw new Error(`Non-zero exit code of \`${reload_exit_code}\` detected while ${action}.`);
|
throw new Error(`Non-zero exit code of \`${reload_exit_code}\` detected while ${action}.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await debug_run_throw("reloading udev rules", `sudo`, [
|
await debug_root_run_throw("reloading udev rules", "udevadm", [
|
||||||
"udevadm",
|
|
||||||
"control",
|
"control",
|
||||||
"--reload-rules",
|
"--reload-rules",
|
||||||
]);
|
]);
|
||||||
await debug_run_throw("triggering udev against kvm", `sudo`, [
|
await debug_root_run_throw("triggering udev against kvm", "udevadm", [
|
||||||
"udevadm",
|
|
||||||
"trigger",
|
"trigger",
|
||||||
"--name-match=kvm",
|
"--name-match=kvm",
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
if (is_root) {
|
||||||
|
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec("rm", ["-f", kvm_rules]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec("sudo", ["rm", "-f", kvm_rules]);
|
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec("sudo", ["rm", "-f", kvm_rules]);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
22
src/main.ts
22
src/main.ts
|
@ -637,6 +637,10 @@ class NixInstallerAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setup_kvm(): Promise<boolean> {
|
private async setup_kvm(): Promise<boolean> {
|
||||||
|
const current_user = userInfo();
|
||||||
|
const is_root = current_user.uid === 0;
|
||||||
|
const maybe_sudo = is_root ? "" : "sudo";
|
||||||
|
|
||||||
const kvm_rules =
|
const kvm_rules =
|
||||||
"/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
|
"/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
|
||||||
try {
|
try {
|
||||||
|
@ -644,7 +648,7 @@ class NixInstallerAction {
|
||||||
"sh",
|
"sh",
|
||||||
[
|
[
|
||||||
"-c",
|
"-c",
|
||||||
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee ${kvm_rules} > /dev/null`,
|
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | ${maybe_sudo} tee ${kvm_rules} > /dev/null`,
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
silent: true,
|
silent: true,
|
||||||
|
@ -671,11 +675,15 @@ class NixInstallerAction {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const debug_run_throw = async (
|
const debug_root_run_throw = async (
|
||||||
action: string,
|
action: string,
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
|
if (!is_root) {
|
||||||
|
args = [command, ...args];
|
||||||
|
command = "sudo";
|
||||||
|
}
|
||||||
const reload_exit_code = await actions_exec.exec(command, args, {
|
const reload_exit_code = await actions_exec.exec(command, args, {
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
|
@ -701,21 +709,23 @@ class NixInstallerAction {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await debug_run_throw("reloading udev rules", `sudo`, [
|
await debug_root_run_throw("reloading udev rules", "udevadm", [
|
||||||
"udevadm",
|
|
||||||
"control",
|
"control",
|
||||||
"--reload-rules",
|
"--reload-rules",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await debug_run_throw("triggering udev against kvm", `sudo`, [
|
await debug_root_run_throw("triggering udev against kvm", "udevadm", [
|
||||||
"udevadm",
|
|
||||||
"trigger",
|
"trigger",
|
||||||
"--name-match=kvm",
|
"--name-match=kvm",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (is_root) {
|
||||||
|
await actions_exec.exec("rm", ["-f", kvm_rules]);
|
||||||
|
} else {
|
||||||
await actions_exec.exec("sudo", ["rm", "-f", kvm_rules]);
|
await actions_exec.exec("sudo", ["rm", "-f", kvm_rules]);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue