@mark1russell7/stack-setup 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,7 +67,7 @@ const layer: SetupLayer = {
67
67
  | `package` | It installs the packages with `apt-get`. | Each package is installed. |
68
68
  | `user` | It makes a user with a home folder. It sets the login shell, the groups and the SSH keys. | The user has the shell, each group and the keys. |
69
69
  | `file` | It writes a file with its text, its mode, its owner and its group. | The file has the text, the mode, the owner and the group. |
70
- | `download` | It downloads a file over HTTPS, and it compares the SHA-256. | The file has the SHA-256 and the mode. |
70
+ | `download` | It downloads a file over HTTPS, and it compares the SHA-256. After a transient error, it tries again 4 times in 120 seconds or less. | The file has the SHA-256 and the mode. |
71
71
  | `swap` | It makes a swap file of a size in MiB. It turns it on and adds it to `/etc/fstab`. | The file has the size, the swap is on, and `/etc/fstab` has it. |
72
72
  | `service` | It writes the unit of a `systemd` service, and it enables and starts the service. | The unit has the text, and the service is enabled and active. |
73
73
  | `command` | It starts a program with its arguments, as root or as a user. | Its own check command passes. |
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/order.ts","../src/check.ts","../src/join.ts","../src/script.ts","../src/sample.ts"],"mappings":";;;iBAQiB;;WAEN,mBAAmB;;WAEnB;;;wBAIK,WAAW,OAAO;;wBAOlB,aAAa,OAAO,YAAY,eAAe;;;;;;;;;wBAY/C,eAAe,mBAAmB,WAAW,OAAO;;;;;;;;;;;;;;;wBAyBpD,aAAa,OAAO,YAAY,OAAO,OAAO,eAAe;;qBCpChE;;YA6CD,oBAAoB;;;;;;;;;iBAUf,mBAAmB;WACzB,MAAM;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+MK,WAAW,OAAO,YAAY,OAAO,QAAQ;;wBAyB7C,cAAc,iBAAiB;;;;;;;;;;;;;wBCzS/B,UAAU,iBAAiB,WAAW,gBAAgB,WAAW;;qBCYpE;WAAuB;WAAgB;WAAoB;WAAqB;;;qBAGhF;;YAGD;WAAyB;WAAmB;;WAA8B;WAAoB,iBAAiB;;;;;;wBA+F3G,UAAU,MAAM;;;;;;;;;;;;;;;;;;;wBA8OhB,YAAY,OAAO,YAAY,OAAO,OAAO,eAAe;;;;;;;;;qBCpV/D,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/order.ts","../src/check.ts","../src/join.ts","../src/script.ts","../src/sample.ts"],"mappings":";;;iBAQiB;;WAEN,mBAAmB;;WAEnB;;;wBAIK,WAAW,OAAO;;wBAOlB,aAAa,OAAO,YAAY,eAAe;;;;;;;;;wBAY/C,eAAe,mBAAmB,WAAW,OAAO;;;;;;;;;;;;;;;wBAyBpD,aAAa,OAAO,YAAY,OAAO,OAAO,eAAe;;qBCpChE;;YA6CD,oBAAoB;;;;;;;;;iBAUf,mBAAmB;WACzB,MAAM;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+MK,WAAW,OAAO,YAAY,OAAO,QAAQ;;wBAyB7C,cAAc,iBAAiB;;;;;;;;;;;;;wBCzS/B,UAAU,iBAAiB,WAAW,gBAAgB,WAAW;;qBCYpE;WAAuB;WAAgB;WAAoB;WAAqB;;;qBAGhF;;YAGD;WAAyB;WAAmB;;WAA8B;WAAoB,iBAAiB;;;;;;wBA+F3G,UAAU,MAAM;;;;;;;;;;;;;;;;;;;wBAoPhB,YAAY,OAAO,YAAY,OAAO,OAAO,eAAe;;;;;;;;;qBC1V/D,cAAc"}
package/build/index.js CHANGED
@@ -168,6 +168,10 @@ function fileCode(step) {
168
168
  tmp: true
169
169
  };
170
170
  }
171
+ /** The count of times that a download starts again after a transient error. The waits between them are 1, 2, 4 and 8 seconds, or the Retry-After of the server. */
172
+ const DOWNLOAD_RETRIES = 4;
173
+ /** The largest time in seconds of the retries of one download. */
174
+ const DOWNLOAD_RETRY_SECONDS = 120;
171
175
  function downloadCode(step) {
172
176
  const path = q(step.path);
173
177
  const mode = modeText(step.mode ?? "644");
@@ -180,7 +184,7 @@ function downloadCode(step) {
180
184
  `[ "$(stat -c '%a %U %G' ${path})" = ${q(`${mode} root root`)} ]`
181
185
  ],
182
186
  apply: [
183
- `curl -fsSL --proto =https --proto-redir =https --tlsv1.2 -o "$tmp" ${q(step.url)} || return 1`,
187
+ `curl -fsSL --proto =https --proto-redir =https --tlsv1.2 --retry ${DOWNLOAD_RETRIES} --retry-max-time ${DOWNLOAD_RETRY_SECONDS} -o "$tmp" ${q(step.url)} || return 1`,
184
188
  `if [ "$(sha256sum "$tmp" | cut -d' ' -f1)" != ${sha} ]; then`,
185
189
  " echo \"setup: the SHA-256 of the download does not agree\" >&2",
186
190
  " return 1",
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/script.ts","../src/sample.ts"],"sourcesContent":["import type { Stack } from \"@mark1russell7/system-stack\";\nimport { escapeShell } from \"@mark1russell7/text/shell\";\nimport { checkSetup, hasSetupError, type SetupFault } from \"./check.ts\";\nimport { DEFAULT_MODE, DEFAULT_SHELL, modeText } from \"./forms.ts\";\nimport {\n stepAddress,\n stepTexts,\n textParts,\n textVariables,\n unitPath,\n SETUP_SCHEMA,\n type CommandStep,\n type DownloadStep,\n type FileStep,\n type PackageStep,\n type ServiceStep,\n type SetupLayer,\n type SetupText,\n type Step,\n type SwapStep,\n type UserStep,\n} from \"./layer.ts\";\nimport { profileOrder } from \"./order.ts\";\n\n// The generator of the setup script of one host. The script is POSIX `sh`, and each step checks before it changes:\n// a step with a passing check changes nothing. A second run of the script thus shows no change.\n// The script holds no value of a variable. It reads each value from its environment when it runs.\n\n/** The exit codes of a setup script. */\nexport const SETUP_EXIT: { readonly ok: 0; readonly failed: 1; readonly changes: 2; readonly usage: 64 } = { ok: 0, failed: 1, changes: 2, usage: 64 };\n\n/** The modes of a setup script, its first argument. `apply` is the default. */\nexport const SETUP_MODES: readonly [\"apply\", \"check\"] = [\"apply\", \"check\"];\n\n/** The result of the generator: the script, or the faults of the gate. */\nexport type SetupScript = { readonly ok: true; readonly script: string } | { readonly ok: false; readonly faults: readonly SetupFault[] };\n\n/** The shell functions that the steps use. The script has only the functions that its steps use. */\ntype Helper = \"installed\" | \"apt_install\" | \"in_group\" | \"login_shell\" | \"user_home\" | \"file_is\" | \"swap_on\" | \"in_fstab\";\n\nconst HELPERS: readonly (readonly [Helper, readonly string[]])[] = [\n [\n \"installed\",\n [\n \"# This function tells if the package $1 is installed.\",\n \"installed() {\",\n ` [ \"$(dpkg-query -W -f='\\${Status}' \"$1\" 2>/dev/null || true)\" = \"install ok installed\" ]`,\n \"}\",\n ],\n ],\n [\n \"apt_install\",\n [\n \"# This function installs the packages. The first call reads the lists of the packages.\",\n \"apt_install() {\",\n ' if [ \"$apt_updated\" -eq 0 ]; then',\n \" apt-get update -q || return 1\",\n \" apt_updated=1\",\n \" fi\",\n ' DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \"$@\"',\n \"}\",\n ],\n ],\n [\n \"in_group\",\n [\n \"# This function tells if the user $1 is in the group $2.\",\n \"in_group() {\",\n ` id -nG \"$1\" 2>/dev/null | tr ' ' '\\\\n' | grep -qxF \"$2\"`,\n \"}\",\n ],\n ],\n [\"login_shell\", [\"# This function gives the login shell of the user $1.\", \"login_shell() {\", ' getent passwd \"$1\" | cut -d: -f7', \"}\"]],\n [\"user_home\", [\"# This function gives the home folder of the user $1.\", \"user_home() {\", ' getent passwd \"$1\" | cut -d: -f6', \"}\"]],\n [\n \"file_is\",\n [\n \"# This function tells if the file $1 has the text of the temporary file, the mode $2, the owner $3 and the group $4.\",\n \"file_is() {\",\n ` [ -f \"$1\" ] && cmp -s \"$tmp\" \"$1\" && [ \"$(stat -c '%a %U %G' \"$1\")\" = \"$2 $3 $4\" ]`,\n \"}\",\n ],\n ],\n [\"swap_on\", [\"# This function tells if the swap file $1 is on.\", \"swap_on() {\", ' swapon --show=NAME --noheadings 2>/dev/null | grep -qxF \"$1\"', \"}\"]],\n [\n \"in_fstab\",\n [\n \"# This function tells if /etc/fstab has the swap file $1.\",\n \"in_fstab() {\",\n ` awk -v path=\"$1\" '$1 == path && $3 == \"swap\" { found = 1 } END { exit !found }' /etc/fstab`,\n \"}\",\n ],\n ],\n];\n\n/** The shell functions that report a step. */\nconst REPORTS: readonly string[] = [\n \"# These functions report a step.\",\n \"ok() {\",\n ' echo \"ok: $1\"',\n \"}\",\n \"change() {\",\n \" changes=$((changes + 1))\",\n ' echo \"change: $1\"',\n \"}\",\n \"changed() {\",\n \" changes=$((changes + 1))\",\n ' echo \"changed: $1\"',\n \"}\",\n \"fail() {\",\n ' echo \"failed: $1: $2\" >&2',\n ` exit ${String(SETUP_EXIT.failed)}`,\n \"}\",\n];\n\n/** The code of one step: its check, its change and the shell functions that they use. */\ninterface StepCode {\n readonly helpers: readonly Helper[];\n /** The conditions of the check. The check passes when each condition passes. */\n readonly check: readonly string[];\n /** The lines of the change. Each command line ends with `|| return 1`. */\n readonly apply: readonly string[];\n /** `true`: the step uses the temporary file. */\n readonly tmp: boolean;\n}\n\n/**\n * This function gives one word of the shell for a text. A literal part is quoted with `escapeShell` of `@mark1russell7/text/shell`.\n * A variable part is `\"$NAME\"`. Thus the shell expands only the variables of the text.\n */\nexport function shellWord(text: SetupText): string {\n // Two literal parts next to each other become one literal, so a quoted part is next to a variable or at an end.\n const parts: (string | { readonly $var: string })[] = [];\n for (const part of textParts(text)) {\n const last = parts.at(-1);\n if (typeof part === \"string\" && typeof last === \"string\") parts[parts.length - 1] = last + part;\n else parts.push(part);\n }\n const word = parts.map((part) => (typeof part === \"string\" ? escapeShell(part) : `\"$${part.$var}\"`)).join(\"\");\n return word === \"\" ? \"''\" : word;\n}\n\nconst q = escapeShell;\n\n/** This function gives the line that writes a text to the temporary file. */\nfunction writeTmp(text: SetupText): string {\n return `printf '%s' ${shellWord(text)} >\"$tmp\"`;\n}\n\nfunction packageCode(step: PackageStep): StepCode {\n if (step.names.length === 0) return { helpers: [], check: [\"true\"], apply: [\":\"], tmp: false };\n return {\n helpers: [\"installed\", \"apt_install\"],\n check: step.names.map((name) => `installed ${q(name)}`),\n apply: [`apt_install ${step.names.map(q).join(\" \")} || return 1`],\n tmp: false,\n };\n}\n\nfunction userCode(step: UserStep): StepCode {\n const name = q(step.name);\n const shell = q(step.shell ?? DEFAULT_SHELL);\n const groups = step.groups ?? [];\n const helpers: Helper[] = [\"login_shell\"];\n const check = [`id -u ${name} >/dev/null 2>&1`, `[ \"$(login_shell ${name})\" = ${shell} ]`];\n const apply = [\n `if ! id -u ${name} >/dev/null 2>&1; then`,\n ` useradd --create-home --shell ${shell} ${name} || return 1`,\n \"fi\",\n `if [ \"$(login_shell ${name})\" != ${shell} ]; then`,\n ` usermod --shell ${shell} ${name} || return 1`,\n \"fi\",\n ];\n if (groups.length > 0) {\n helpers.push(\"in_group\");\n const tests = groups.map((group) => `in_group ${name} ${q(group)}`);\n check.push(...tests);\n apply.push(`if ! { ${tests.join(\" && \")}; }; then`, ` usermod -aG ${q(groups.join(\",\"))} ${name} || return 1`, \"fi\");\n }\n const keys = step.keys;\n if (keys === undefined) return { helpers, check, apply, tmp: false };\n helpers.push(\"user_home\", \"file_is\");\n // An empty list of keys gives an empty file. A printf with no argument writes one line break.\n const write = keys.length === 0 ? ': >\"$tmp\"' : `printf '%s\\\\n' ${keys.map(q).join(\" \")} >\"$tmp\"`;\n check.push(write, `home=$(user_home ${name})`, '[ -n \"$home\" ]', `[ \"$(stat -c '%a %U' \"$home/.ssh\")\" = ${q(`700 ${step.name}`)} ]`, `file_is \"$home/.ssh/authorized_keys\" 600 ${name} \"$(id -gn ${name})\"`);\n // The group is explicit: `chown user:` with no group does not set the login group with each `chown`, for example the Rust coreutils.\n apply.push(\n `home=$(user_home ${name}) || return 1`,\n '[ -n \"$home\" ] || return 1',\n `group=$(id -gn ${name}) || return 1`,\n 'mkdir -p \"$home/.ssh\" || return 1',\n 'chmod 700 \"$home/.ssh\" || return 1',\n `chown ${name}:\"$group\" \"$home/.ssh\" || return 1`,\n `${write} || return 1`,\n `install -m 600 -o ${name} -g \"$group\" \"$tmp\" \"$home/.ssh/authorized_keys\" || return 1`,\n );\n return { helpers, check, apply, tmp: true };\n}\n\nfunction fileCode(step: FileStep): StepCode {\n const path = q(step.path);\n const mode = modeText(step.mode ?? DEFAULT_MODE);\n const owner = q(step.owner ?? \"root\");\n const group = q(step.group ?? \"root\");\n const write = writeTmp(step.text);\n return {\n helpers: [\"file_is\"],\n check: [write, `file_is ${path} ${mode} ${owner} ${group}`],\n apply: [`${write} || return 1`, `install -D -m ${mode} -o ${owner} -g ${group} \"$tmp\" ${path} || return 1`],\n tmp: true,\n };\n}\n\nfunction downloadCode(step: DownloadStep): StepCode {\n const path = q(step.path);\n const mode = modeText(step.mode ?? DEFAULT_MODE);\n const sha = q(step.sha256);\n return {\n helpers: [],\n check: [`[ -f ${path} ]`, `[ \"$(sha256sum ${path} | cut -d' ' -f1)\" = ${sha} ]`, `[ \"$(stat -c '%a %U %G' ${path})\" = ${q(`${mode} root root`)} ]`],\n apply: [\n `curl -fsSL --proto =https --proto-redir =https --tlsv1.2 -o \"$tmp\" ${q(step.url)} || return 1`,\n `if [ \"$(sha256sum \"$tmp\" | cut -d' ' -f1)\" != ${sha} ]; then`,\n ' echo \"setup: the SHA-256 of the download does not agree\" >&2',\n \" return 1\",\n \"fi\",\n `install -D -m ${mode} -o root -g root \"$tmp\" ${path} || return 1`,\n ],\n tmp: true,\n };\n}\n\nfunction swapCode(step: SwapStep): StepCode {\n const path = q(step.path);\n const form = q(`${String(step.mib * 1048576)} 600 root`);\n return {\n helpers: [\"swap_on\", \"in_fstab\"],\n check: [`swap_on ${path}`, `[ \"$(stat -c '%s %a %U' ${path})\" = ${form} ]`, `in_fstab ${path}`],\n apply: [\n `if [ \"$(stat -c '%s %a %U' ${path} 2>/dev/null || true)\" != ${form} ]; then`,\n ` if swap_on ${path}; then`,\n ` swapoff ${path} || return 1`,\n \" fi\",\n ` rm -f ${path} || return 1`,\n ` dd if=/dev/zero of=${path} bs=1M count=${String(step.mib)} status=none || return 1`,\n ` chmod 600 ${path} || return 1`,\n ` mkswap ${path} || return 1`,\n \"fi\",\n `if ! swap_on ${path}; then`,\n ` swapon ${path} || return 1`,\n \"fi\",\n `if ! in_fstab ${path}; then`,\n ` printf '%s none swap sw 0 0\\\\n' ${path} >>/etc/fstab || return 1`,\n \"fi\",\n ],\n tmp: false,\n };\n}\n\nfunction serviceCode(step: ServiceStep): StepCode {\n const name = q(step.name);\n const unit = q(unitPath(step.name));\n const write = writeTmp(step.unit);\n const file = `file_is ${unit} 644 root root`;\n if (step.enable === false) {\n return {\n helpers: [\"file_is\"],\n check: [write, file],\n apply: [`${write} || return 1`, `if ! ${file}; then`, ` install -D -m 644 -o root -g root \"$tmp\" ${unit} || return 1`, \" systemctl daemon-reload || return 1\", \"fi\"],\n tmp: true,\n };\n }\n return {\n helpers: [\"file_is\"],\n check: [write, file, `systemctl is-enabled --quiet ${name}`, `systemctl is-active --quiet ${name}`],\n apply: [\n \"unit_new=0\",\n `${write} || return 1`,\n `if ! ${file}; then`,\n ` install -D -m 644 -o root -g root \"$tmp\" ${unit} || return 1`,\n \" systemctl daemon-reload || return 1\",\n \" unit_new=1\",\n \"fi\",\n `systemctl enable --quiet ${name} || return 1`,\n 'if [ \"$unit_new\" -eq 1 ]; then',\n ` systemctl restart ${name} || return 1`,\n \"else\",\n ` systemctl start ${name} || return 1`,\n \"fi\",\n ],\n tmp: true,\n };\n}\n\nfunction commandCode(step: CommandStep): StepCode {\n // `env` starts the program from the PATH, so no function, builtin or keyword of the shell is the program.\n const start = step.as === undefined || step.as === \"root\" ? \"env\" : `runuser -u ${q(step.as)} --`;\n const line = (command: readonly SetupText[]): string => [start, ...command.map(shellWord)].join(\" \");\n return { helpers: [], check: [line(step.check)], apply: [`${line(step.run)} || return 1`], tmp: false };\n}\n\n/** This function gives the code of a step. */\nfunction stepCode(step: Step): StepCode {\n switch (step.kind) {\n case \"package\":\n return packageCode(step);\n case \"user\":\n return userCode(step);\n case \"file\":\n return fileCode(step);\n case \"download\":\n return downloadCode(step);\n case \"swap\":\n return swapCode(step);\n case \"service\":\n return serviceCode(step);\n case \"command\":\n return commandCode(step);\n }\n}\n\n/**\n * This function gives the lines of one step: its two functions and the report.\n * The exit code of the check is the number of its first condition that fails. Thus a fault after the change names the condition, and it prints no value.\n */\nfunction stepLines(number: number, address: string, code: StepCode): string[] {\n const check = `check_${String(number)}`;\n const apply = `apply_${String(number)}`;\n const at = q(address);\n const conditions = code.check.map((condition, index) => ` ${condition} || return ${String(index + 1)}`);\n return [\n `# The step ${address}`,\n `${check}() {`,\n ...conditions,\n \"}\",\n `${apply}() {`,\n ...code.apply.map((line) => ` ${line}`),\n \"}\",\n `if ${check} >/dev/null 2>&1; then`,\n ` ok ${at}`,\n 'elif [ \"$mode\" = check ]; then',\n ` change ${at}`,\n \"else\",\n ` ${apply} >&2 || fail ${at} \"the change failed\"`,\n ` ${check} >/dev/null 2>&1 || fail ${at} \"the condition $? of the check fails after the change\"`,\n ` changed ${at}`,\n \"fi\",\n ];\n}\n\n/**\n * This function gives the setup script of one host. The gate `checkSetup` comes first: a layer with an error gives no script.\n *\n * The script:\n * - It is POSIX `sh`, and it passes `shellcheck -s sh`. It needs root, `apt`, `systemd` and the GNU tools of Debian or Ubuntu.\n * - Its first argument is the mode. `apply` makes each change. `check` makes no change, and it exits with 2 when a step has a change.\n * - It exits with 64 for a usage fault. A usage fault is a mode that is not known, a start that is not root, or a variable with no value.\n * - Each step starts its check first. Only a step with a failing check makes its change, and then its check must pass.\n * - It reads the value of each variable from its environment. It names the variables of the steps of this host only.\n * - It holds no description of a record. Only names, paths and the texts of the steps are in it.\n *\n * The steps come in the order of `profileOrder`: a profile comes after each profile of the host whose part its part needs.\n *\n * @param layer - The setup layer.\n * @param stack - The stack.\n * @param host - The `id` of the host.\n * @returns The script, or the faults of the gate.\n */\nexport function setupScript(layer: SetupLayer, stack: Stack, host: string): SetupScript {\n const faults = checkSetup(layer, stack);\n if (hasSetupError(faults)) return { ok: false, faults };\n const { profiles } = profileOrder(layer, stack, host);\n if (profiles.length === 0) {\n return { ok: false, faults: [...faults, { level: \"error\", code: \"setup-host\", at: host, message: `No profile of the layer names the host \"${host}\".`, host }] };\n }\n const steps = profiles.flatMap((profile) => profile.steps.map((step) => ({ address: stepAddress(profile, step), step, code: stepCode(step) })));\n const variables: string[] = [];\n for (const { step } of steps) for (const text of stepTexts(step)) for (const name of textVariables(text)) if (!variables.includes(name)) variables.push(name);\n const helpers = new Set(steps.flatMap(({ code }) => code.helpers));\n const tmp = steps.some(({ code }) => code.tmp);\n const lines: string[] = [\n \"#!/bin/sh\",\n // A directive next to the shebang holds for the whole file. Each literal text is in single quotes on purpose, so the shell expands no \"$\" in it.\n \"# shellcheck disable=SC2016\",\n `# The setup of the host ${JSON.stringify(host)}, from a layer ${SETUP_SCHEMA} of a system stack.`,\n \"# Each literal text is in single quotes, so the shell expands nothing in it. The shell expands only the variables of the layer.\",\n \"# Start it as root with the mode apply or check. The mode check makes no change.\",\n \"# The exit codes: 0 when each step is ok, 1 when a step fails, 2 when the mode check finds a change, 64 for a usage fault.\",\n \"set -eu\",\n \"\",\n \"mode=${1:-apply}\",\n \"case $mode in\",\n ` ${SETUP_MODES.join(\" | \")}) ;;`,\n \" *)\",\n ` echo \"usage: $0 [${SETUP_MODES.join(\"|\")}]\" >&2`,\n ` exit ${String(SETUP_EXIT.usage)}`,\n \" ;;\",\n \"esac\",\n 'if [ \"$(id -u)\" -ne 0 ]; then',\n ' echo \"setup: start the script as root\" >&2',\n ` exit ${String(SETUP_EXIT.usage)}`,\n \"fi\",\n ];\n for (const name of variables) {\n lines.push(`if [ -z \"\\${${name}-}\" ]; then`, ` echo \"setup: the variable ${name} has no value\" >&2`, ` exit ${String(SETUP_EXIT.usage)}`, \"fi\");\n }\n lines.push(\"\");\n if (tmp) lines.push('tmp=$(mktemp)', `trap 'rm -f \"$tmp\"' EXIT`, `trap 'exit ${String(SETUP_EXIT.failed)}' INT TERM HUP`);\n lines.push(\"changes=0\");\n if (helpers.has(\"apt_install\")) lines.push(\"apt_updated=0\");\n for (const [name, text] of HELPERS) if (helpers.has(name)) lines.push(\"\", ...text);\n if (steps.length > 0) lines.push(\"\", ...REPORTS);\n steps.forEach(({ address, code }, index) => lines.push(\"\", ...stepLines(index + 1, address, code)));\n lines.push(\n \"\",\n 'echo \"changes: $changes\"',\n 'if [ \"$mode\" = check ] && [ \"$changes\" -gt 0 ]; then',\n ` exit ${String(SETUP_EXIT.changes)}`,\n \"fi\",\n \"\",\n );\n return { ok: true, script: lines.join(\"\\n\") };\n}\n","import { SETUP_SCHEMA, type SetupLayer } from \"./layer.ts\";\n\n/** The unit of the sample service. Each name in it is an example. */\nconst SAMPLE_UNIT = [\n \"[Unit]\",\n \"Description=The alert program\",\n \"After=network-online.target\",\n \"Wants=network-online.target\",\n \"\",\n \"[Service]\",\n \"User=alerts\",\n \"EnvironmentFile=/etc/alerts/env\",\n \"ExecStart=/opt/alerts/alerts\",\n \"Restart=on-failure\",\n \"\",\n \"[Install]\",\n \"WantedBy=multi-user.target\",\n \"\",\n].join(\"\\n\");\n\n/**\n * A sample setup layer for `SAMPLE_STACK` of the core. Each name, address and checksum is an example: the file at the address does not exist.\n *\n * - The profile `program` sets up the part `program-cloud` on the host `cloud-host`: the program, its environment file and its service.\n * - The profile `base` sets up the host itself: the packages, a swap file and the user of the program.\n *\n * The layer has `program` first. The part `program-cloud` needs `cloud-host`, so the order of the setup has `base` first.\n */\nexport const SAMPLE_SETUP: SetupLayer = {\n schema: SETUP_SCHEMA,\n variables: [{ name: \"ALERTS_TOKEN\", sensitive: true, description: \"The token of the push service\" }],\n profiles: [\n {\n name: \"program\",\n part: \"program-cloud\",\n hosts: [\"cloud-host\"],\n steps: [\n {\n kind: \"download\",\n id: \"binary\",\n url: \"https://example.org/alerts/1.4.0/alerts\",\n sha256: \"0000000000000000000000000000000000000000000000000000000000000000\",\n path: \"/opt/alerts/alerts\",\n mode: \"755\",\n },\n { kind: \"file\", id: \"env\", path: \"/etc/alerts/env\", text: [\"ALERTS_TOKEN=\", { $var: \"ALERTS_TOKEN\" }, \"\\n\"], mode: \"600\" },\n { kind: \"command\", id: \"data\", run: [\"install\", \"-d\", \"-o\", \"alerts\", \"-g\", \"alerts\", \"/var/lib/alerts\"], check: [\"test\", \"-d\", \"/var/lib/alerts\"] },\n { kind: \"service\", id: \"service\", name: \"alerts\", unit: SAMPLE_UNIT },\n ],\n },\n {\n name: \"base\",\n part: \"cloud-host\",\n hosts: [\"cloud-host\"],\n steps: [\n { kind: \"package\", id: \"packages\", manager: \"apt\", names: [\"ca-certificates\", \"curl\"] },\n { kind: \"swap\", id: \"swap\", path: \"/swapfile\", mib: 1024 },\n { kind: \"user\", id: \"user\", name: \"alerts\", groups: [\"systemd-journal\"], shell: \"/usr/sbin/nologin\" },\n ],\n },\n ],\n};\n"],"mappings":";;;;;AA6BA,MAAa,aAA8F;CAAE,IAAI;CAAG,QAAQ;CAAG,SAAS;CAAG,OAAO;AAAG;;AAGrJ,MAAa,cAA2C,CAAC,SAAS,OAAO;AAQzE,MAAM,UAA6D;CACjE,CACE,aACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CACE,eACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,CACE,YACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CAAC,eAAe;EAAC;EAAyD;EAAmB;EAAsC;CAAG,CAAC;CACvI,CAAC,aAAa;EAAC;EAAyD;EAAiB;EAAsC;CAAG,CAAC;CACnI,CACE,WACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CAAC,WAAW;EAAC;EAAoD;EAAe;EAAkE;CAAG,CAAC;CACtJ,CACE,YACA;EACE;EACA;EACA;EACA;CACF,CACF;AACF;;AAGA,MAAM,UAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,UAAU,OAAO,W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AAI;;;;;;;;;AAUX,MAAa,eAA2B;CACtC,QAAQ;CACR,WAAW,CAAC;EAAE,MAAM;EAAgB,WAAW;EAAM,aAAa;CAAgC,CAAC;CACnG,UAAU,CACR;EACE,MAAM;EACN,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,OAAO;GACL;IACE,MAAM;IACN,IAAI;IACJ,KAAK;IACL,QAAQ;IACR,MAAM;IACN,MAAM;GACR;GACA;IAAE,MAAM;IAAQ,IAAI;IAAO,MAAM;IAAmB,MAAM;KAAC;KAAiB,EAAE,MAAM,eAAe;KAAG;IAAI;IAAG,MAAM;GAAM;GACzH;IAAE,MAAM;IAAW,IAAI;IAAQ,KAAK;KAAC;KAAW;KAAM;KAAM;KAAU;KAAM;KAAU;IAAiB;IAAG,OAAO;KAAC;KAAQ;KAAM;IAAiB;GAAE;GACnJ;IAAE,MAAM;IAAW,IAAI;IAAW,MAAM;IAAU,MAAM;GAAY;EACtE;CACF,GACA;EACE,MAAM;EACN,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,OAAO;GACL;IAAE,MAAM;IAAW,IAAI;IAAY,SAAS;IAAO,OAAO,CAAC,mBAAmB,MAAM;GAAE;GACtF;IAAE,MAAM;IAAQ,IAAI;IAAQ,MAAM;IAAa,KAAK;GAAK;GACzD;IAAE,MAAM;IAAQ,IAAI;IAAQ,MAAM;IAAU,QAAQ,CAAC,iBAAiB;IAAG,OAAO;GAAoB;EACtG;CACF,CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/script.ts","../src/sample.ts"],"sourcesContent":["import type { Stack } from \"@mark1russell7/system-stack\";\nimport { escapeShell } from \"@mark1russell7/text/shell\";\nimport { checkSetup, hasSetupError, type SetupFault } from \"./check.ts\";\nimport { DEFAULT_MODE, DEFAULT_SHELL, modeText } from \"./forms.ts\";\nimport {\n stepAddress,\n stepTexts,\n textParts,\n textVariables,\n unitPath,\n SETUP_SCHEMA,\n type CommandStep,\n type DownloadStep,\n type FileStep,\n type PackageStep,\n type ServiceStep,\n type SetupLayer,\n type SetupText,\n type Step,\n type SwapStep,\n type UserStep,\n} from \"./layer.ts\";\nimport { profileOrder } from \"./order.ts\";\n\n// The generator of the setup script of one host. The script is POSIX `sh`, and each step checks before it changes:\n// a step with a passing check changes nothing. A second run of the script thus shows no change.\n// The script holds no value of a variable. It reads each value from its environment when it runs.\n\n/** The exit codes of a setup script. */\nexport const SETUP_EXIT: { readonly ok: 0; readonly failed: 1; readonly changes: 2; readonly usage: 64 } = { ok: 0, failed: 1, changes: 2, usage: 64 };\n\n/** The modes of a setup script, its first argument. `apply` is the default. */\nexport const SETUP_MODES: readonly [\"apply\", \"check\"] = [\"apply\", \"check\"];\n\n/** The result of the generator: the script, or the faults of the gate. */\nexport type SetupScript = { readonly ok: true; readonly script: string } | { readonly ok: false; readonly faults: readonly SetupFault[] };\n\n/** The shell functions that the steps use. The script has only the functions that its steps use. */\ntype Helper = \"installed\" | \"apt_install\" | \"in_group\" | \"login_shell\" | \"user_home\" | \"file_is\" | \"swap_on\" | \"in_fstab\";\n\nconst HELPERS: readonly (readonly [Helper, readonly string[]])[] = [\n [\n \"installed\",\n [\n \"# This function tells if the package $1 is installed.\",\n \"installed() {\",\n ` [ \"$(dpkg-query -W -f='\\${Status}' \"$1\" 2>/dev/null || true)\" = \"install ok installed\" ]`,\n \"}\",\n ],\n ],\n [\n \"apt_install\",\n [\n \"# This function installs the packages. The first call reads the lists of the packages.\",\n \"apt_install() {\",\n ' if [ \"$apt_updated\" -eq 0 ]; then',\n \" apt-get update -q || return 1\",\n \" apt_updated=1\",\n \" fi\",\n ' DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \"$@\"',\n \"}\",\n ],\n ],\n [\n \"in_group\",\n [\n \"# This function tells if the user $1 is in the group $2.\",\n \"in_group() {\",\n ` id -nG \"$1\" 2>/dev/null | tr ' ' '\\\\n' | grep -qxF \"$2\"`,\n \"}\",\n ],\n ],\n [\"login_shell\", [\"# This function gives the login shell of the user $1.\", \"login_shell() {\", ' getent passwd \"$1\" | cut -d: -f7', \"}\"]],\n [\"user_home\", [\"# This function gives the home folder of the user $1.\", \"user_home() {\", ' getent passwd \"$1\" | cut -d: -f6', \"}\"]],\n [\n \"file_is\",\n [\n \"# This function tells if the file $1 has the text of the temporary file, the mode $2, the owner $3 and the group $4.\",\n \"file_is() {\",\n ` [ -f \"$1\" ] && cmp -s \"$tmp\" \"$1\" && [ \"$(stat -c '%a %U %G' \"$1\")\" = \"$2 $3 $4\" ]`,\n \"}\",\n ],\n ],\n [\"swap_on\", [\"# This function tells if the swap file $1 is on.\", \"swap_on() {\", ' swapon --show=NAME --noheadings 2>/dev/null | grep -qxF \"$1\"', \"}\"]],\n [\n \"in_fstab\",\n [\n \"# This function tells if /etc/fstab has the swap file $1.\",\n \"in_fstab() {\",\n ` awk -v path=\"$1\" '$1 == path && $3 == \"swap\" { found = 1 } END { exit !found }' /etc/fstab`,\n \"}\",\n ],\n ],\n];\n\n/** The shell functions that report a step. */\nconst REPORTS: readonly string[] = [\n \"# These functions report a step.\",\n \"ok() {\",\n ' echo \"ok: $1\"',\n \"}\",\n \"change() {\",\n \" changes=$((changes + 1))\",\n ' echo \"change: $1\"',\n \"}\",\n \"changed() {\",\n \" changes=$((changes + 1))\",\n ' echo \"changed: $1\"',\n \"}\",\n \"fail() {\",\n ' echo \"failed: $1: $2\" >&2',\n ` exit ${String(SETUP_EXIT.failed)}`,\n \"}\",\n];\n\n/** The code of one step: its check, its change and the shell functions that they use. */\ninterface StepCode {\n readonly helpers: readonly Helper[];\n /** The conditions of the check. The check passes when each condition passes. */\n readonly check: readonly string[];\n /** The lines of the change. Each command line ends with `|| return 1`. */\n readonly apply: readonly string[];\n /** `true`: the step uses the temporary file. */\n readonly tmp: boolean;\n}\n\n/**\n * This function gives one word of the shell for a text. A literal part is quoted with `escapeShell` of `@mark1russell7/text/shell`.\n * A variable part is `\"$NAME\"`. Thus the shell expands only the variables of the text.\n */\nexport function shellWord(text: SetupText): string {\n // Two literal parts next to each other become one literal, so a quoted part is next to a variable or at an end.\n const parts: (string | { readonly $var: string })[] = [];\n for (const part of textParts(text)) {\n const last = parts.at(-1);\n if (typeof part === \"string\" && typeof last === \"string\") parts[parts.length - 1] = last + part;\n else parts.push(part);\n }\n const word = parts.map((part) => (typeof part === \"string\" ? escapeShell(part) : `\"$${part.$var}\"`)).join(\"\");\n return word === \"\" ? \"''\" : word;\n}\n\nconst q = escapeShell;\n\n/** This function gives the line that writes a text to the temporary file. */\nfunction writeTmp(text: SetupText): string {\n return `printf '%s' ${shellWord(text)} >\"$tmp\"`;\n}\n\nfunction packageCode(step: PackageStep): StepCode {\n if (step.names.length === 0) return { helpers: [], check: [\"true\"], apply: [\":\"], tmp: false };\n return {\n helpers: [\"installed\", \"apt_install\"],\n check: step.names.map((name) => `installed ${q(name)}`),\n apply: [`apt_install ${step.names.map(q).join(\" \")} || return 1`],\n tmp: false,\n };\n}\n\nfunction userCode(step: UserStep): StepCode {\n const name = q(step.name);\n const shell = q(step.shell ?? DEFAULT_SHELL);\n const groups = step.groups ?? [];\n const helpers: Helper[] = [\"login_shell\"];\n const check = [`id -u ${name} >/dev/null 2>&1`, `[ \"$(login_shell ${name})\" = ${shell} ]`];\n const apply = [\n `if ! id -u ${name} >/dev/null 2>&1; then`,\n ` useradd --create-home --shell ${shell} ${name} || return 1`,\n \"fi\",\n `if [ \"$(login_shell ${name})\" != ${shell} ]; then`,\n ` usermod --shell ${shell} ${name} || return 1`,\n \"fi\",\n ];\n if (groups.length > 0) {\n helpers.push(\"in_group\");\n const tests = groups.map((group) => `in_group ${name} ${q(group)}`);\n check.push(...tests);\n apply.push(`if ! { ${tests.join(\" && \")}; }; then`, ` usermod -aG ${q(groups.join(\",\"))} ${name} || return 1`, \"fi\");\n }\n const keys = step.keys;\n if (keys === undefined) return { helpers, check, apply, tmp: false };\n helpers.push(\"user_home\", \"file_is\");\n // An empty list of keys gives an empty file. A printf with no argument writes one line break.\n const write = keys.length === 0 ? ': >\"$tmp\"' : `printf '%s\\\\n' ${keys.map(q).join(\" \")} >\"$tmp\"`;\n check.push(write, `home=$(user_home ${name})`, '[ -n \"$home\" ]', `[ \"$(stat -c '%a %U' \"$home/.ssh\")\" = ${q(`700 ${step.name}`)} ]`, `file_is \"$home/.ssh/authorized_keys\" 600 ${name} \"$(id -gn ${name})\"`);\n // The group is explicit: `chown user:` with no group does not set the login group with each `chown`, for example the Rust coreutils.\n apply.push(\n `home=$(user_home ${name}) || return 1`,\n '[ -n \"$home\" ] || return 1',\n `group=$(id -gn ${name}) || return 1`,\n 'mkdir -p \"$home/.ssh\" || return 1',\n 'chmod 700 \"$home/.ssh\" || return 1',\n `chown ${name}:\"$group\" \"$home/.ssh\" || return 1`,\n `${write} || return 1`,\n `install -m 600 -o ${name} -g \"$group\" \"$tmp\" \"$home/.ssh/authorized_keys\" || return 1`,\n );\n return { helpers, check, apply, tmp: true };\n}\n\nfunction fileCode(step: FileStep): StepCode {\n const path = q(step.path);\n const mode = modeText(step.mode ?? DEFAULT_MODE);\n const owner = q(step.owner ?? \"root\");\n const group = q(step.group ?? \"root\");\n const write = writeTmp(step.text);\n return {\n helpers: [\"file_is\"],\n check: [write, `file_is ${path} ${mode} ${owner} ${group}`],\n apply: [`${write} || return 1`, `install -D -m ${mode} -o ${owner} -g ${group} \"$tmp\" ${path} || return 1`],\n tmp: true,\n };\n}\n\n/** The count of times that a download starts again after a transient error. The waits between them are 1, 2, 4 and 8 seconds, or the Retry-After of the server. */\nconst DOWNLOAD_RETRIES = 4;\n/** The largest time in seconds of the retries of one download. */\nconst DOWNLOAD_RETRY_SECONDS = 120;\n\nfunction downloadCode(step: DownloadStep): StepCode {\n const path = q(step.path);\n const mode = modeText(step.mode ?? DEFAULT_MODE);\n const sha = q(step.sha256);\n return {\n helpers: [],\n check: [`[ -f ${path} ]`, `[ \"$(sha256sum ${path} | cut -d' ' -f1)\" = ${sha} ]`, `[ \"$(stat -c '%a %U %G' ${path})\" = ${q(`${mode} root root`)} ]`],\n apply: [\n // curl tries again after a transient error (a time-out, or the HTTP status 408, 429, 500, 502, 503 or 504), and obeys Retry-After.\n `curl -fsSL --proto =https --proto-redir =https --tlsv1.2 --retry ${DOWNLOAD_RETRIES} --retry-max-time ${DOWNLOAD_RETRY_SECONDS} -o \"$tmp\" ${q(step.url)} || return 1`,\n `if [ \"$(sha256sum \"$tmp\" | cut -d' ' -f1)\" != ${sha} ]; then`,\n ' echo \"setup: the SHA-256 of the download does not agree\" >&2',\n \" return 1\",\n \"fi\",\n `install -D -m ${mode} -o root -g root \"$tmp\" ${path} || return 1`,\n ],\n tmp: true,\n };\n}\n\nfunction swapCode(step: SwapStep): StepCode {\n const path = q(step.path);\n const form = q(`${String(step.mib * 1048576)} 600 root`);\n return {\n helpers: [\"swap_on\", \"in_fstab\"],\n check: [`swap_on ${path}`, `[ \"$(stat -c '%s %a %U' ${path})\" = ${form} ]`, `in_fstab ${path}`],\n apply: [\n `if [ \"$(stat -c '%s %a %U' ${path} 2>/dev/null || true)\" != ${form} ]; then`,\n ` if swap_on ${path}; then`,\n ` swapoff ${path} || return 1`,\n \" fi\",\n ` rm -f ${path} || return 1`,\n ` dd if=/dev/zero of=${path} bs=1M count=${String(step.mib)} status=none || return 1`,\n ` chmod 600 ${path} || return 1`,\n ` mkswap ${path} || return 1`,\n \"fi\",\n `if ! swap_on ${path}; then`,\n ` swapon ${path} || return 1`,\n \"fi\",\n `if ! in_fstab ${path}; then`,\n ` printf '%s none swap sw 0 0\\\\n' ${path} >>/etc/fstab || return 1`,\n \"fi\",\n ],\n tmp: false,\n };\n}\n\nfunction serviceCode(step: ServiceStep): StepCode {\n const name = q(step.name);\n const unit = q(unitPath(step.name));\n const write = writeTmp(step.unit);\n const file = `file_is ${unit} 644 root root`;\n if (step.enable === false) {\n return {\n helpers: [\"file_is\"],\n check: [write, file],\n apply: [`${write} || return 1`, `if ! ${file}; then`, ` install -D -m 644 -o root -g root \"$tmp\" ${unit} || return 1`, \" systemctl daemon-reload || return 1\", \"fi\"],\n tmp: true,\n };\n }\n return {\n helpers: [\"file_is\"],\n check: [write, file, `systemctl is-enabled --quiet ${name}`, `systemctl is-active --quiet ${name}`],\n apply: [\n \"unit_new=0\",\n `${write} || return 1`,\n `if ! ${file}; then`,\n ` install -D -m 644 -o root -g root \"$tmp\" ${unit} || return 1`,\n \" systemctl daemon-reload || return 1\",\n \" unit_new=1\",\n \"fi\",\n `systemctl enable --quiet ${name} || return 1`,\n 'if [ \"$unit_new\" -eq 1 ]; then',\n ` systemctl restart ${name} || return 1`,\n \"else\",\n ` systemctl start ${name} || return 1`,\n \"fi\",\n ],\n tmp: true,\n };\n}\n\nfunction commandCode(step: CommandStep): StepCode {\n // `env` starts the program from the PATH, so no function, builtin or keyword of the shell is the program.\n const start = step.as === undefined || step.as === \"root\" ? \"env\" : `runuser -u ${q(step.as)} --`;\n const line = (command: readonly SetupText[]): string => [start, ...command.map(shellWord)].join(\" \");\n return { helpers: [], check: [line(step.check)], apply: [`${line(step.run)} || return 1`], tmp: false };\n}\n\n/** This function gives the code of a step. */\nfunction stepCode(step: Step): StepCode {\n switch (step.kind) {\n case \"package\":\n return packageCode(step);\n case \"user\":\n return userCode(step);\n case \"file\":\n return fileCode(step);\n case \"download\":\n return downloadCode(step);\n case \"swap\":\n return swapCode(step);\n case \"service\":\n return serviceCode(step);\n case \"command\":\n return commandCode(step);\n }\n}\n\n/**\n * This function gives the lines of one step: its two functions and the report.\n * The exit code of the check is the number of its first condition that fails. Thus a fault after the change names the condition, and it prints no value.\n */\nfunction stepLines(number: number, address: string, code: StepCode): string[] {\n const check = `check_${String(number)}`;\n const apply = `apply_${String(number)}`;\n const at = q(address);\n const conditions = code.check.map((condition, index) => ` ${condition} || return ${String(index + 1)}`);\n return [\n `# The step ${address}`,\n `${check}() {`,\n ...conditions,\n \"}\",\n `${apply}() {`,\n ...code.apply.map((line) => ` ${line}`),\n \"}\",\n `if ${check} >/dev/null 2>&1; then`,\n ` ok ${at}`,\n 'elif [ \"$mode\" = check ]; then',\n ` change ${at}`,\n \"else\",\n ` ${apply} >&2 || fail ${at} \"the change failed\"`,\n ` ${check} >/dev/null 2>&1 || fail ${at} \"the condition $? of the check fails after the change\"`,\n ` changed ${at}`,\n \"fi\",\n ];\n}\n\n/**\n * This function gives the setup script of one host. The gate `checkSetup` comes first: a layer with an error gives no script.\n *\n * The script:\n * - It is POSIX `sh`, and it passes `shellcheck -s sh`. It needs root, `apt`, `systemd` and the GNU tools of Debian or Ubuntu.\n * - Its first argument is the mode. `apply` makes each change. `check` makes no change, and it exits with 2 when a step has a change.\n * - It exits with 64 for a usage fault. A usage fault is a mode that is not known, a start that is not root, or a variable with no value.\n * - Each step starts its check first. Only a step with a failing check makes its change, and then its check must pass.\n * - It reads the value of each variable from its environment. It names the variables of the steps of this host only.\n * - It holds no description of a record. Only names, paths and the texts of the steps are in it.\n *\n * The steps come in the order of `profileOrder`: a profile comes after each profile of the host whose part its part needs.\n *\n * @param layer - The setup layer.\n * @param stack - The stack.\n * @param host - The `id` of the host.\n * @returns The script, or the faults of the gate.\n */\nexport function setupScript(layer: SetupLayer, stack: Stack, host: string): SetupScript {\n const faults = checkSetup(layer, stack);\n if (hasSetupError(faults)) return { ok: false, faults };\n const { profiles } = profileOrder(layer, stack, host);\n if (profiles.length === 0) {\n return { ok: false, faults: [...faults, { level: \"error\", code: \"setup-host\", at: host, message: `No profile of the layer names the host \"${host}\".`, host }] };\n }\n const steps = profiles.flatMap((profile) => profile.steps.map((step) => ({ address: stepAddress(profile, step), step, code: stepCode(step) })));\n const variables: string[] = [];\n for (const { step } of steps) for (const text of stepTexts(step)) for (const name of textVariables(text)) if (!variables.includes(name)) variables.push(name);\n const helpers = new Set(steps.flatMap(({ code }) => code.helpers));\n const tmp = steps.some(({ code }) => code.tmp);\n const lines: string[] = [\n \"#!/bin/sh\",\n // A directive next to the shebang holds for the whole file. Each literal text is in single quotes on purpose, so the shell expands no \"$\" in it.\n \"# shellcheck disable=SC2016\",\n `# The setup of the host ${JSON.stringify(host)}, from a layer ${SETUP_SCHEMA} of a system stack.`,\n \"# Each literal text is in single quotes, so the shell expands nothing in it. The shell expands only the variables of the layer.\",\n \"# Start it as root with the mode apply or check. The mode check makes no change.\",\n \"# The exit codes: 0 when each step is ok, 1 when a step fails, 2 when the mode check finds a change, 64 for a usage fault.\",\n \"set -eu\",\n \"\",\n \"mode=${1:-apply}\",\n \"case $mode in\",\n ` ${SETUP_MODES.join(\" | \")}) ;;`,\n \" *)\",\n ` echo \"usage: $0 [${SETUP_MODES.join(\"|\")}]\" >&2`,\n ` exit ${String(SETUP_EXIT.usage)}`,\n \" ;;\",\n \"esac\",\n 'if [ \"$(id -u)\" -ne 0 ]; then',\n ' echo \"setup: start the script as root\" >&2',\n ` exit ${String(SETUP_EXIT.usage)}`,\n \"fi\",\n ];\n for (const name of variables) {\n lines.push(`if [ -z \"\\${${name}-}\" ]; then`, ` echo \"setup: the variable ${name} has no value\" >&2`, ` exit ${String(SETUP_EXIT.usage)}`, \"fi\");\n }\n lines.push(\"\");\n if (tmp) lines.push('tmp=$(mktemp)', `trap 'rm -f \"$tmp\"' EXIT`, `trap 'exit ${String(SETUP_EXIT.failed)}' INT TERM HUP`);\n lines.push(\"changes=0\");\n if (helpers.has(\"apt_install\")) lines.push(\"apt_updated=0\");\n for (const [name, text] of HELPERS) if (helpers.has(name)) lines.push(\"\", ...text);\n if (steps.length > 0) lines.push(\"\", ...REPORTS);\n steps.forEach(({ address, code }, index) => lines.push(\"\", ...stepLines(index + 1, address, code)));\n lines.push(\n \"\",\n 'echo \"changes: $changes\"',\n 'if [ \"$mode\" = check ] && [ \"$changes\" -gt 0 ]; then',\n ` exit ${String(SETUP_EXIT.changes)}`,\n \"fi\",\n \"\",\n );\n return { ok: true, script: lines.join(\"\\n\") };\n}\n","import { SETUP_SCHEMA, type SetupLayer } from \"./layer.ts\";\n\n/** The unit of the sample service. Each name in it is an example. */\nconst SAMPLE_UNIT = [\n \"[Unit]\",\n \"Description=The alert program\",\n \"After=network-online.target\",\n \"Wants=network-online.target\",\n \"\",\n \"[Service]\",\n \"User=alerts\",\n \"EnvironmentFile=/etc/alerts/env\",\n \"ExecStart=/opt/alerts/alerts\",\n \"Restart=on-failure\",\n \"\",\n \"[Install]\",\n \"WantedBy=multi-user.target\",\n \"\",\n].join(\"\\n\");\n\n/**\n * A sample setup layer for `SAMPLE_STACK` of the core. Each name, address and checksum is an example: the file at the address does not exist.\n *\n * - The profile `program` sets up the part `program-cloud` on the host `cloud-host`: the program, its environment file and its service.\n * - The profile `base` sets up the host itself: the packages, a swap file and the user of the program.\n *\n * The layer has `program` first. The part `program-cloud` needs `cloud-host`, so the order of the setup has `base` first.\n */\nexport const SAMPLE_SETUP: SetupLayer = {\n schema: SETUP_SCHEMA,\n variables: [{ name: \"ALERTS_TOKEN\", sensitive: true, description: \"The token of the push service\" }],\n profiles: [\n {\n name: \"program\",\n part: \"program-cloud\",\n hosts: [\"cloud-host\"],\n steps: [\n {\n kind: \"download\",\n id: \"binary\",\n url: \"https://example.org/alerts/1.4.0/alerts\",\n sha256: \"0000000000000000000000000000000000000000000000000000000000000000\",\n path: \"/opt/alerts/alerts\",\n mode: \"755\",\n },\n { kind: \"file\", id: \"env\", path: \"/etc/alerts/env\", text: [\"ALERTS_TOKEN=\", { $var: \"ALERTS_TOKEN\" }, \"\\n\"], mode: \"600\" },\n { kind: \"command\", id: \"data\", run: [\"install\", \"-d\", \"-o\", \"alerts\", \"-g\", \"alerts\", \"/var/lib/alerts\"], check: [\"test\", \"-d\", \"/var/lib/alerts\"] },\n { kind: \"service\", id: \"service\", name: \"alerts\", unit: SAMPLE_UNIT },\n ],\n },\n {\n name: \"base\",\n part: \"cloud-host\",\n hosts: [\"cloud-host\"],\n steps: [\n { kind: \"package\", id: \"packages\", manager: \"apt\", names: [\"ca-certificates\", \"curl\"] },\n { kind: \"swap\", id: \"swap\", path: \"/swapfile\", mib: 1024 },\n { kind: \"user\", id: \"user\", name: \"alerts\", groups: [\"systemd-journal\"], shell: \"/usr/sbin/nologin\" },\n ],\n },\n ],\n};\n"],"mappings":";;;;;AA6BA,MAAa,aAA8F;CAAE,IAAI;CAAG,QAAQ;CAAG,SAAS;CAAG,OAAO;AAAG;;AAGrJ,MAAa,cAA2C,CAAC,SAAS,OAAO;AAQzE,MAAM,UAA6D;CACjE,CACE,aACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CACE,eACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,CACE,YACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CAAC,eAAe;EAAC;EAAyD;EAAmB;EAAsC;CAAG,CAAC;CACvI,CAAC,aAAa;EAAC;EAAyD;EAAiB;EAAsC;CAAG,CAAC;CACnI,CACE,WACA;EACE;EACA;EACA;EACA;CACF,CACF;CACA,CAAC,WAAW;EAAC;EAAoD;EAAe;EAAkE;CAAG,CAAC;CACtJ,CACE,YACA;EACE;EACA;EACA;EACA;CACF,CACF;AACF;;AAGA,MAAM,UAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,UAAU,OAAO,WAAW,MAAM;CAClC;AACF;;;;;AAiBA,SAAgB,UAAU,MAAyB;CAEjD,MAAM,QAAgD,CAAC;CACvD,KAAK,MAAM,QAAQ,UAAU,IAAI,GAAG;EAClC,MAAM,OAAO,MAAM,GAAG,EAAE;EACxB,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,MAAM,MAAM,SAAS,KAAK,OAAO;OACtF,MAAM,KAAK,IAAI;CACtB;CACA,MAAM,OAAO,MAAM,KAAK,SAAU,OAAO,SAAS,WAAW,YAAY,IAAI,IAAI,KAAK,KAAK,KAAK,EAAG,CAAC,CAAC,KAAK,EAAE;CAC5G,OAAO,SAAS,KAAK,OAAO;AAC9B;AAEA,MAAM,IAAI;;AAGV,SAAS,SAAS,MAAyB;CACzC,OAAO,eAAe,UAAU,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Q,KAAK;KAAC;KAAW;KAAM;KAAM;KAAU;KAAM;KAAU;IAAiB;IAAG,OAAO;KAAC;KAAQ;KAAM;IAAiB;GAAE;GACnJ;IAAE,MAAM;IAAW,IAAI;IAAW,MAAM;IAAU,MAAM;GAAY;EACtE;CACF,GACA;EACE,MAAM;EACN,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,OAAO;GACL;IAAE,MAAM;IAAW,IAAI;IAAY,SAAS;IAAO,OAAO,CAAC,mBAAmB,MAAM;GAAE;GACtF;IAAE,MAAM;IAAQ,IAAI;IAAQ,MAAM;IAAa,KAAK;GAAK;GACzD;IAAE,MAAM;IAAQ,IAAI;IAAQ,MAAM;IAAU,QAAQ,CAAC,iBAAiB;IAAG,OAAO;GAAoB;EACtG;CACF,CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/stack-setup",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "description": "The setup inside a host from the records of a system stack: typed steps, their order from the needs, a gate, and a POSIX shell script that checks before it changes. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {