alwaysai
Version:
The alwaysAI command-line interface (CLI)
40 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setUpPasswordlessSshComponent = void 0;
const fs_1 = require("fs");
const logSymbols = require("log-symbols");
const paths_1 = require("../../paths");
const util_1 = require("../../util");
const connect_by_ssh_component_1 = require("./connect-by-ssh-component");
// The following shell script is derived 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) {
(0, util_1.echo)('We need to set up your system to enable passwordless ssh.');
(0, util_1.echo)(`Please enter the ssh password for "${props.targetHostname}" when prompted.`);
try {
await (0, util_1.JsSpawner)().run({
exe: 'ssh',
args: [
'-o',
'StrictHostKeyChecking=no',
props.targetHostname,
SHELL_SCRIPT_FOR_APPENDING_TO_AUTHORIZED_KEYS
],
input: (0, fs_1.createReadStream)(paths_1.PUBLIC_KEY_FILE_PATH)
});
(0, util_1.echo)(`${logSymbols.success} Copy "${paths_1.PUBLIC_KEY_FILE_PRETTY_PATH}" to authorized_keys`);
}
catch (exception) {
(0, util_1.echo)(`${logSymbols.error} Copy "${paths_1.PUBLIC_KEY_FILE_PRETTY_PATH}" to authorized_keys`);
throw exception;
}
await (0, connect_by_ssh_component_1.connectBySshComponent)({
targetHostname: props.targetHostname
});
}
exports.setUpPasswordlessSshComponent = setUpPasswordlessSshComponent;
//# sourceMappingURL=set-up-passwordless-ssh-component.js.map