Start fixing sandbox script
This commit is contained in:
parent
d3cd61cdd6
commit
6c7fbf7fb1
2
Makefile
2
Makefile
|
@ -81,7 +81,7 @@ else ifneq (,$(filter $(I),base lang))
|
||||||
ifeq ($(I),lang)
|
ifeq ($(I),lang)
|
||||||
@: $${L}
|
@: $${L}
|
||||||
endif
|
endif
|
||||||
docker run -it --rm --hostname $(I) -v $(VOLUME_MOUNT):/src --label riju-install-target=yes $(SHELL_PORTS) $(SHELL_ENV) $(IMAGE_HASH) riju:$(LANG_TAG) $(BASH_CMD)
|
docker run -it --rm --hostname $(LANG_TAG) -v $(VOLUME_MOUNT):/src --label riju-install-target=yes $(SHELL_PORTS) $(SHELL_ENV) $(IMAGE_HASH) riju:$(LANG_TAG) $(BASH_CMD)
|
||||||
else ifeq ($(I),runtime)
|
else ifeq ($(I),runtime)
|
||||||
docker run -it --rm --hostname $(I) -v $(VOLUME_MOUNT):/src -v /var/run/docker.sock:/var/run/docker.sock $(SHELL_PORTS) $(SHELL_ENV) $(IMAGE_HASH) riju:$(I) $(BASH_CMD)
|
docker run -it --rm --hostname $(I) -v $(VOLUME_MOUNT):/src -v /var/run/docker.sock:/var/run/docker.sock $(SHELL_PORTS) $(SHELL_ENV) $(IMAGE_HASH) riju:$(I) $(BASH_CMD)
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,10 +13,9 @@ export let langs = {};
|
||||||
// Map from language aliases and IDs to canonical language IDs.
|
// Map from language aliases and IDs to canonical language IDs.
|
||||||
export let aliases = {};
|
export let aliases = {};
|
||||||
|
|
||||||
// Read languages from JSON files in /opt/riju/langs, and update the
|
// Read languages from YAML, and update the global langs variable in
|
||||||
// global langs variable in this module. Never throw an error. If
|
// this module. Never throw an error. If there is a problem then just
|
||||||
// there is a problem then just leave the languages as they previously
|
// leave the languages as they previously were.
|
||||||
// were.
|
|
||||||
async function updateLangsFromDisk() {
|
async function updateLangsFromDisk() {
|
||||||
try {
|
try {
|
||||||
const newLangs = {};
|
const newLangs = {};
|
||||||
|
|
|
@ -5,10 +5,13 @@ if [[ -z "$L" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cfg="$(< "/opt/riju/langs/$L.json")" || exit 1
|
if [[ -z "$LANG_CONFIG" ]]; then
|
||||||
|
echo 'environment variable unset: $LANG_CONFIG' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
function get {
|
function get {
|
||||||
jq -r ".$1" <<< "${cfg}"
|
jq -r ".$1" <<< "${LANG_CONFIG}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function has {
|
function has {
|
||||||
|
|
|
@ -2,14 +2,17 @@ import { spawn } from "child_process";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import process from "process";
|
import process from "process";
|
||||||
|
|
||||||
|
import pty from "node-pty";
|
||||||
import { quote } from "shell-quote";
|
import { quote } from "shell-quote";
|
||||||
|
|
||||||
import { getUUID } from "./util.js";
|
import { readLangConfig } from "../lib/yaml.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
privilegedSetup,
|
bash,
|
||||||
privilegedSpawn,
|
getUUID,
|
||||||
privilegedTeardown,
|
privilegedExec,
|
||||||
|
privilegedPty,
|
||||||
|
privilegedSession,
|
||||||
|
privilegedWait,
|
||||||
run,
|
run,
|
||||||
} from "./util.js";
|
} from "./util.js";
|
||||||
|
|
||||||
|
@ -28,22 +31,40 @@ async function main() {
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
die("environment variable unset: $L");
|
die("environment variable unset: $L");
|
||||||
}
|
}
|
||||||
|
const langConfig = await readLangConfig(lang);
|
||||||
const uuid = getUUID();
|
const uuid = getUUID();
|
||||||
await run(privilegedSetup({ uuid }), log);
|
console.log(`Starting session with UUID ${uuid}`);
|
||||||
const args = privilegedSpawn({ uuid }, [
|
const sessionArgs = privilegedSession({ uuid, lang });
|
||||||
"bash",
|
const session = pty.spawn(sessionArgs[0], sessionArgs.slice(1), {
|
||||||
"-c",
|
name: "xterm-color",
|
||||||
`exec env L='${lang}' bash --rcfile <(cat <<< ${quote([sandboxScript])})`,
|
});
|
||||||
]);
|
await run(privilegedWait({ uuid }), log);
|
||||||
|
console.log(
|
||||||
|
bash(
|
||||||
|
`env L='${lang}' LANG_CONFIG=${quote([
|
||||||
|
JSON.stringify(langConfig),
|
||||||
|
])} bash --rcfile <(cat <<< ${quote([sandboxScript])})`
|
||||||
|
)[2]
|
||||||
|
);
|
||||||
|
const args = privilegedPty(
|
||||||
|
{ uuid },
|
||||||
|
bash(
|
||||||
|
`env L='${lang}' LANG_CONFIG=${quote([
|
||||||
|
JSON.stringify(langConfig),
|
||||||
|
])} bash --rcfile <(cat <<< ${quote([sandboxScript])})`
|
||||||
|
)
|
||||||
|
);
|
||||||
const proc = spawn(args[0], args.slice(1), {
|
const proc = spawn(args[0], args.slice(1), {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
});
|
});
|
||||||
await new Promise((resolve, reject) => {
|
try {
|
||||||
proc.on("error", reject);
|
await new Promise((resolve, reject) => {
|
||||||
proc.on("close", resolve);
|
proc.on("error", reject);
|
||||||
});
|
proc.on("close", resolve);
|
||||||
await run(privilegedTeardown({ uuid }), log);
|
});
|
||||||
await returnUser();
|
} finally {
|
||||||
|
session.kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(die);
|
main().catch(die);
|
||||||
|
|
Loading…
Reference in New Issue