UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

42 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const echo_1 = require("../util/echo"); const run_1 = require("../spawner/spawner-base/run"); const check_for_passwordless_ssh_connectivity_component_1 = require("./check-for-passwordless-ssh-connectivity-component"); const write_private_key_file_component_1 = require("./write-private-key-file-component"); const constants_1 = require("../constants"); const logSymbols = require("log-symbols"); // The following shell script is from the openSSH utility "ssh-copy-id" // * Create the .ssh directory with appropriate permissions if it does not exist // * Append \n to authorized_keys if it exists but does not end in \n (?) // * Append to authorized_keys from stdin using cat // * Reset the security context (type) (extended attributes) of authorized_keys const SHELL_SCRIPT_FOR_APPENDING_TO_AUTHORIZED_KEYS = `exec sh -c 'cd ; umask 077 ; mkdir -p .ssh && { [ -z "'\`tail -1c .ssh/authorized_keys 2>/dev/null\`'" ] || echo >> .ssh/authorized_keys ; } && cat >> .ssh/authorized_keys || exit 1 ; if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'`; async function setUpPasswordlessSshComponent(props) { echo_1.echo('We need to set up your system to enable passwordless ssh.'); await write_private_key_file_component_1.writePrivateKeyFileComponent(); echo_1.echo(`Please enter the ssh password for "${props.targetHostname}" when prompted.`); try { await run_1.run({ exe: 'ssh', args: [ '-o', 'StrictHostKeyChecking=no', props.targetHostname, SHELL_SCRIPT_FOR_APPENDING_TO_AUTHORIZED_KEYS, ], input: fs_1.createReadStream(constants_1.PUBLIC_KEY_FILE_PATH), }); echo_1.echo(`${logSymbols.success} Copy "${constants_1.PUBLIC_KEY_FILE_PRETTY_PATH}" to authorized_keys`); } catch (exception) { echo_1.echo(`${logSymbols.error} Copy "${constants_1.PUBLIC_KEY_FILE_PRETTY_PATH}" to authorized_keys`); throw exception; } await check_for_passwordless_ssh_connectivity_component_1.checkForPasswordlessSshConnectivityComponent({ targetHostname: props.targetHostname, }); } exports.setUpPasswordlessSshComponent = setUpPasswordlessSshComponent; //# sourceMappingURL=set-up-passwordless-ssh-component.js.map