Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrlambda committed Nov 23, 2023
1 parent 30babb2 commit 6155b3c
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.6.6

- Fix .ssh/config when calling `register` multiple times
- Fix bug with null as default for text

# 1.6.5

- Add internet connection test to `help`
Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GIT_HOST = exports.SSH_HOST = exports.HTTP_HOST = exports.API_URL = void 0;
exports.GIT_HOST = exports.SSH_USER = exports.SSH_HOST = exports.HTTP_HOST = exports.API_URL = void 0;
exports.API_URL = `api.merrymake.io`;
exports.HTTP_HOST = `https://${exports.API_URL}`;
exports.SSH_HOST = `${exports.API_URL}`;
exports.SSH_USER = `mist`;
exports.GIT_HOST = `ssh://mist@${exports.API_URL}`;
1 change: 1 addition & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const API_URL = `api.merrymake.io`;

export const HTTP_HOST = `https://${API_URL}`;
export const SSH_HOST = `${API_URL}`;
export const SSH_USER = `mist`;
export const GIT_HOST = `ssh://mist@${API_URL}`;
Binary file modified dist/windows.zip
Binary file not shown.
57 changes: 44 additions & 13 deletions executors.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ function addKnownHost() {
let lines = ("" + fs_1.default.readFileSync(`${os_1.default.homedir()}/.ssh/known_hosts`)).split("\n");
isKnownHost = lines.some((x) => x.includes(`${config_1.API_URL} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOW2dgo+0nuahOzHD7XVnSdrCwhkK9wMnAZyr6XOKotO`));
}
if (!isKnownHost)
if (!isKnownHost) {
console.log("Adding fingerprint...");
fs_1.default.appendFileSync(`${os_1.default.homedir()}/.ssh/known_hosts`, `\n${config_1.API_URL} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOW2dgo+0nuahOzHD7XVnSdrCwhkK9wMnAZyr6XOKotO\n`);
}
}
exports.addKnownHost = addKnownHost;
function do_register(keyAction, email) {
Expand Down Expand Up @@ -241,15 +243,48 @@ function do_register(keyAction, email) {
});
}
exports.do_register = do_register;
function saveSSHConfig(path) {
console.log(`Saving preference...`);
let lines = [];
let foundHost = false;
if (fs_1.default.existsSync(`${os_1.default.homedir()}/.ssh/config`)) {
lines = fs_1.default
.readFileSync(`${os_1.default.homedir()}/.ssh/config`)
.toString()
.split("\n");
let inHost = false;
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if ((line.startsWith("\t") || line.startsWith(" ")) && inHost) {
if (line.includes("User "))
lines[i] =
line.substring(0, line.indexOf("User ")) + `User ${config_1.SSH_USER}`;
else if (line.includes("IdentityFile "))
lines[i] =
line.substring(0, line.indexOf("IdentityFile ")) +
`IdentityFile ~/.ssh/${path}`;
}
else if (line.startsWith("\t") || line.startsWith(" ")) {
}
else if (line.startsWith(`Host ${config_1.API_URL}`)) {
inHost = true;
foundHost = true;
}
else {
inHost = false;
}
}
}
if (!foundHost) {
lines.push(`Host ${config_1.API_URL}`, `\tUser ${config_1.SSH_USER}`, `\tHostName ${config_1.API_URL}`, `\tPreferredAuthentications publickey`, `\tIdentityFile ~/.ssh/${path}\n`);
}
fs_1.default.writeFileSync(`${os_1.default.homedir()}/.ssh/config`, lines.join("\n"));
}
function useExistingKey(path) {
return __awaiter(this, void 0, void 0, function* () {
try {
fs_1.default.appendFileSync(`${os_1.default.homedir()}/.ssh/config`, `\nHost ${config_1.API_URL}
\tUser mist
\tHostName ${config_1.API_URL}
\tPreferredAuthentications publickey
\tIdentityFile ~/.ssh/${path}\n`);
console.log(`Reading ${path}.pub`);
saveSSHConfig(path);
console.log(`Reading ${path}.pub...`);
return "" + fs_1.default.readFileSync(os_1.default.homedir() + `/.ssh/${path}.pub`);
}
catch (e) {
Expand All @@ -261,15 +296,11 @@ exports.useExistingKey = useExistingKey;
function generateNewKey() {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log(`Generating new ssh key`);
console.log(`Generating new ssh key...`);
if (!fs_1.default.existsSync(os_1.default.homedir() + "/.ssh"))
fs_1.default.mkdirSync(os_1.default.homedir() + "/.ssh");
yield (0, utils_1.execPromise)(`ssh-keygen -t rsa -b 4096 -f "${os_1.default.homedir()}/.ssh/merrymake" -N ""`);
fs_1.default.appendFileSync(`${os_1.default.homedir()}/.ssh/config`, `\nHost ${config_1.API_URL}
\tUser mist
\tHostName ${config_1.API_URL}
\tPreferredAuthentications publickey
\tIdentityFile ~/.ssh/merrymake\n`);
saveSSHConfig("merrymake");
return "" + fs_1.default.readFileSync(os_1.default.homedir() + "/.ssh/merrymake.pub");
}
catch (e) {
Expand Down
69 changes: 49 additions & 20 deletions executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getCache,
fetchOrgRaw,
} from "./utils";
import { API_URL, GIT_HOST, HTTP_HOST } from "./config";
import { API_URL, GIT_HOST, HTTP_HOST, SSH_USER } from "./config";
import {
detectProjectType,
BUILD_SCRIPT_MAKERS,
Expand Down Expand Up @@ -237,11 +237,13 @@ export function addKnownHost() {
)
);
}
if (!isKnownHost)
if (!isKnownHost) {
console.log("Adding fingerprint...");
fs.appendFileSync(
`${os.homedir()}/.ssh/known_hosts`,
`\n${API_URL} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOW2dgo+0nuahOzHD7XVnSdrCwhkK9wMnAZyr6XOKotO\n`
);
}
}

export async function do_register(
Expand Down Expand Up @@ -270,17 +272,51 @@ export async function do_register(
}
}

function saveSSHConfig(path: string) {
console.log(`Saving preference...`);
let lines: string[] = [];
let foundHost = false;
if (fs.existsSync(`${os.homedir()}/.ssh/config`)) {
lines = fs
.readFileSync(`${os.homedir()}/.ssh/config`)
.toString()
.split("\n");
let inHost = false;
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if ((line.startsWith("\t") || line.startsWith(" ")) && inHost) {
if (line.includes("User "))
lines[i] =
line.substring(0, line.indexOf("User ")) + `User ${SSH_USER}`;
else if (line.includes("IdentityFile "))
lines[i] =
line.substring(0, line.indexOf("IdentityFile ")) +
`IdentityFile ~/.ssh/${path}`;
} else if (line.startsWith("\t") || line.startsWith(" ")) {
} else if (line.startsWith(`Host ${API_URL}`)) {
inHost = true;
foundHost = true;
} else {
inHost = false;
}
}
}
if (!foundHost) {
lines.push(
`Host ${API_URL}`,
`\tUser ${SSH_USER}`,
`\tHostName ${API_URL}`,
`\tPreferredAuthentications publickey`,
`\tIdentityFile ~/.ssh/${path}\n`
);
}
fs.writeFileSync(`${os.homedir()}/.ssh/config`, lines.join("\n"));
}

export async function useExistingKey(path: string) {
try {
fs.appendFileSync(
`${os.homedir()}/.ssh/config`,
`\nHost ${API_URL}
\tUser mist
\tHostName ${API_URL}
\tPreferredAuthentications publickey
\tIdentityFile ~/.ssh/${path}\n`
);
console.log(`Reading ${path}.pub`);
saveSSHConfig(path);
console.log(`Reading ${path}.pub...`);
return "" + fs.readFileSync(os.homedir() + `/.ssh/${path}.pub`);
} catch (e) {
throw e;
Expand All @@ -289,20 +325,13 @@ export async function useExistingKey(path: string) {

export async function generateNewKey() {
try {
console.log(`Generating new ssh key`);
console.log(`Generating new ssh key...`);
if (!fs.existsSync(os.homedir() + "/.ssh"))
fs.mkdirSync(os.homedir() + "/.ssh");
await execPromise(
`ssh-keygen -t rsa -b 4096 -f "${os.homedir()}/.ssh/merrymake" -N ""`
);
fs.appendFileSync(
`${os.homedir()}/.ssh/config`,
`\nHost ${API_URL}
\tUser mist
\tHostName ${API_URL}
\tPreferredAuthentications publickey
\tIdentityFile ~/.ssh/merrymake\n`
);
saveSSHConfig("merrymake");
return "" + fs.readFileSync(os.homedir() + "/.ssh/merrymake.pub");
} catch (e) {
throw e;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@merrymake/cli",
"version": "1.6.5",
"version": "1.6.6",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ function spinner_stop() {
}
}
exports.spinner_stop = spinner_stop;
function shortText(prompt, description, defaultValue) {
function shortText(prompt, description, defaultValueArg) {
return new Promise((resolve) => {
let defaultValue = defaultValueArg === null ? "" : defaultValueArg;
if ((0, args_1.getArgs)()[0] !== undefined) {
let result = (0, args_1.getArgs)()[0] === "_" ? defaultValue : (0, args_1.getArgs)()[0];
command += " " + (result.includes(" ") ? `'${result}'` : result);
Expand Down
3 changes: 2 additions & 1 deletion prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ export function spinner_stop() {
export function shortText(
prompt: string,
description: string,
defaultValue: string
defaultValueArg: string | null
) {
return new Promise<string>((resolve) => {
let defaultValue = defaultValueArg === null ? "" : defaultValueArg;
if (getArgs()[0] !== undefined) {
let result = getArgs()[0] === "_" ? defaultValue : getArgs()[0];
command += " " + (result.includes(" ") ? `'${result}'` : result);
Expand Down

0 comments on commit 6155b3c

Please sign in to comment.