Skip to content

Commit 740c037

Browse files
committed
afhiurghes
1 parent 9d76902 commit 740c037

File tree

2 files changed

+32
-118
lines changed

2 files changed

+32
-118
lines changed

dist/index.js

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30997,25 +30997,10 @@ function download_file(url, filename) {
3099730997
function ensure_host_ssh_key() {
3099830998
const pubkey = expandHomeDir("~/.ssh/id_rsa.pub");
3099930999
const privkey = expandHomeDir("~/.ssh/id_rsa");
31000-
if (fs.existsSync(pubkey)) {
31001-
show_message("info", "SSH key already exists, skipping.");
31002-
} else {
31003-
const result = spawnSync(
31004-
"ssh-keygen",
31005-
["-t", "rsa", "-N", "", "-f", privkey],
31006-
{
31007-
stdio: "inherit",
31008-
}
31009-
);
31010-
if (result.status === 0) {
31011-
show_message("info", "SSH key generated successfully.");
31012-
} else {
31013-
show_message(
31014-
"fatal",
31015-
`Error generating SSH key. Exit code: ${result.status}`
31016-
);
31017-
}
31018-
}
31000+
const pubkeyUrl = 'https://raw.githubusercontent.com/uwulab/manyvm-freebsd-builder/main/id_rsa.pub'
31001+
const privKeyUrl = 'https://raw.githubusercontent.com/uwulab/manyvm-freebsd-builder/main/id_rsa'
31002+
download_file(pubkeyUrl, pubkey);
31003+
download_file(privKeyUrl, privkey);
3101931004
// properly set private key permissions
3102031005
fs.chmodSync(privkey, 0o600);
3102131006
return pubkey;
@@ -31095,19 +31080,18 @@ function start_vm(qemu_version, os, cpu, arch, bios, machine, filename, pubkey)
3109531080
show_message("info", qemu_executable + ' ' + qemu_args.join(' '));
3109631081

3109731082
qemu_wrapper(qemu_executable, qemu_args, (qemu_process) => {
31098-
setup_sshkey(pubkey, qemu_process, () => {
31099-
let runScript = core.getInput('run');
31100-
fs.writeFileSync('/tmp/run.sh', runScript);
31101-
let ssh = spawnSync('ssh', ['-tt', '-o', 'StrictHostKeyChecking=no', '-p', '2222', '-i', pubkey, 'root@localhost']);
31102-
ssh.stdout.pipe(process.stdout);
31103-
ssh.stderr.pipe(process.stderr);
31104-
ssh.stdin.write('chmod +x /tmp/run.sh');
31105-
ssh.stdin.write('bash /tmp/run.sh');
31106-
ssh.on('close', (code) => {
31107-
show_message("info", `ssh exited with code ${code}`);
31108-
qemu_process.kill();
31109-
})
31110-
});
31083+
let runScript = core.getInput('run');
31084+
fs.writeFileSync('/tmp/run.sh', runScript);
31085+
let ssh = spawnSync('ssh', ['-tt', '-o', 'StrictHostKeyChecking=no', '-p', '2222', '-i', pubkey, 'root@localhost']);
31086+
ssh.stdout.pipe(process.stdout);
31087+
ssh.stderr.pipe(process.stderr);
31088+
ssh.stdin.write('chmod +x /tmp/run.sh');
31089+
ssh.stdin.write('bash /tmp/run.sh');
31090+
ssh.on('close', (code) => {
31091+
show_message("info", `ssh exited with code ${code}`);
31092+
qemu_process.kill();
31093+
})
31094+
3111131095
});
3111231096
core.endGroup();
3111331097
};
@@ -31124,33 +31108,6 @@ function waitFor(trigger, callback) {
3112431108
}
3112531109
}
3112631110

31127-
function setup_sshkey(pubkey, qemu_process, ready_callback) {
31128-
const pubkeyContent = fs.readFileSync(pubkey, { encoding: "utf-8" });
31129-
show_message("info", "Setting up SSH key for QEMU");
31130-
let waitForPrompt = waitFor("root@freebsd:", () => {
31131-
waitForPrompt = () => { }
31132-
let waitForKey = waitFor(pubkeyContent, () => {
31133-
show_message("info", "SSH key added successfully");
31134-
ready_callback(qemu_process)
31135-
})
31136-
qemu_process.stdout.on('data', data => {
31137-
process.stdout.write(data.toString())
31138-
waitForKey(data)
31139-
})
31140-
show_message("debug", "Writing to stdin")
31141-
// qemu_process.stdin.write(`echo "${pubkeyContent}" > /root/.ssh/authorized_keys\n`, () => {
31142-
// qemu_process.stdin.write(`cat /root/.ssh/authorized_keys\n`, () => {
31143-
qemu_process.stdin.write("echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && /etc/rc.d/sshd restart\n");
31144-
// });
31145-
// });
31146-
})
31147-
qemu_process.stdout.on('data', (data) => {
31148-
waitForPrompt(data)
31149-
process.stdout.write(data.toString())
31150-
});
31151-
qemu_process.stdin.write("root\n");
31152-
}
31153-
3115431111
function ensure_install_deps() {
3115531112
show_message("info", "Installing OVMF");
3115631113
let result = spawnSync("sudo", ["apt-get", "update"], {

index.js

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,10 @@ function download_file(url, filename) {
107107
function ensure_host_ssh_key() {
108108
const pubkey = expandHomeDir("~/.ssh/id_rsa.pub");
109109
const privkey = expandHomeDir("~/.ssh/id_rsa");
110-
if (fs.existsSync(pubkey)) {
111-
show_message("info", "SSH key already exists, skipping.");
112-
} else {
113-
const result = spawnSync(
114-
"ssh-keygen",
115-
["-t", "rsa", "-N", "", "-f", privkey],
116-
{
117-
stdio: "inherit",
118-
}
119-
);
120-
if (result.status === 0) {
121-
show_message("info", "SSH key generated successfully.");
122-
} else {
123-
show_message(
124-
"fatal",
125-
`Error generating SSH key. Exit code: ${result.status}`
126-
);
127-
}
128-
}
110+
const pubkeyUrl = 'https://raw.githubusercontent.com/uwulab/manyvm-freebsd-builder/main/id_rsa.pub'
111+
const privKeyUrl = 'https://raw.githubusercontent.com/uwulab/manyvm-freebsd-builder/main/id_rsa'
112+
download_file(pubkeyUrl, pubkey);
113+
download_file(privKeyUrl, privkey);
129114
// properly set private key permissions
130115
fs.chmodSync(privkey, 0o600);
131116
return pubkey;
@@ -205,19 +190,18 @@ function start_vm(qemu_version, os, cpu, arch, bios, machine, filename, pubkey)
205190
show_message("info", qemu_executable + ' ' + qemu_args.join(' '));
206191

207192
qemu_wrapper(qemu_executable, qemu_args, (qemu_process) => {
208-
setup_sshkey(pubkey, qemu_process, () => {
209-
let runScript = core.getInput('run');
210-
fs.writeFileSync('/tmp/run.sh', runScript);
211-
let ssh = spawnSync('ssh', ['-tt', '-o', 'StrictHostKeyChecking=no', '-p', '2222', '-i', pubkey, 'root@localhost']);
212-
ssh.stdout.pipe(process.stdout);
213-
ssh.stderr.pipe(process.stderr);
214-
ssh.stdin.write('chmod +x /tmp/run.sh');
215-
ssh.stdin.write('bash /tmp/run.sh');
216-
ssh.on('close', (code) => {
217-
show_message("info", `ssh exited with code ${code}`);
218-
qemu_process.kill();
219-
})
220-
});
193+
let runScript = core.getInput('run');
194+
fs.writeFileSync('/tmp/run.sh', runScript);
195+
let ssh = spawnSync('ssh', ['-tt', '-o', 'StrictHostKeyChecking=no', '-p', '2222', '-i', pubkey, 'root@localhost']);
196+
ssh.stdout.pipe(process.stdout);
197+
ssh.stderr.pipe(process.stderr);
198+
ssh.stdin.write('chmod +x /tmp/run.sh');
199+
ssh.stdin.write('bash /tmp/run.sh');
200+
ssh.on('close', (code) => {
201+
show_message("info", `ssh exited with code ${code}`);
202+
qemu_process.kill();
203+
})
204+
221205
});
222206
core.endGroup();
223207
};
@@ -234,33 +218,6 @@ function waitFor(trigger, callback) {
234218
}
235219
}
236220

237-
function setup_sshkey(pubkey, qemu_process, ready_callback) {
238-
const pubkeyContent = fs.readFileSync(pubkey, { encoding: "utf-8" });
239-
show_message("info", "Setting up SSH key for QEMU");
240-
let waitForPrompt = waitFor("root@freebsd:", () => {
241-
waitForPrompt = () => { }
242-
let waitForKey = waitFor(pubkeyContent, () => {
243-
show_message("info", "SSH key added successfully");
244-
ready_callback(qemu_process)
245-
})
246-
qemu_process.stdout.on('data', data => {
247-
process.stdout.write(data.toString())
248-
waitForKey(data)
249-
})
250-
show_message("debug", "Writing to stdin")
251-
// qemu_process.stdin.write(`echo "${pubkeyContent}" > /root/.ssh/authorized_keys\n`, () => {
252-
// qemu_process.stdin.write(`cat /root/.ssh/authorized_keys\n`, () => {
253-
qemu_process.stdin.write("echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && /etc/rc.d/sshd restart\n");
254-
// });
255-
// });
256-
})
257-
qemu_process.stdout.on('data', (data) => {
258-
waitForPrompt(data)
259-
process.stdout.write(data.toString())
260-
});
261-
qemu_process.stdin.write("root\n");
262-
}
263-
264221
function ensure_install_deps() {
265222
show_message("info", "Installing OVMF");
266223
let result = spawnSync("sudo", ["apt-get", "update"], {

0 commit comments

Comments
 (0)