fixup various shell usage

This commit is contained in:
Girish Ramakrishnan
2024-02-28 18:47:53 +01:00
parent 07527fe2b1
commit 3316dd1f42
4 changed files with 47 additions and 21 deletions

View File

@@ -34,7 +34,7 @@ async function ensureKeys() {
debug(`ensureSecrets: generating new sftp keys of type ${keyType}`);
safe.fs.unlinkSync(publicKeyFile);
safe.fs.unlinkSync(privateKeyFile);
const [error] = await safe(shell.exec('ensureKeys', `ssh-keygen -m PEM -t ${keyType} -f "${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key" -q -N ""`, {}));
const [error] = await safe(shell.exec('ensureKeys', `ssh-keygen -m PEM -t ${keyType} -f ${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key -q -N ""`, { shell: '/bin/bash' }));
if (error) throw new BoxError(BoxError.OPENSSL_ERROR, `Could not generate sftp ${keyType} keys: ${error.message}`);
const newPublicKey = safe.fs.readFileSync(publicKeyFile);
await blobs.set(`sftp_${keyType}_public_key`, newPublicKey);
@@ -122,9 +122,11 @@ async function start(existingInfra) {
--label isCloudronManaged=true \
${readOnly} -v /tmp -v /run ${image} ${cmd}`;
// ignore error if container not found (and fail later) so that this code works across restarts
await safe(shell.exec('stopSftp', 'docker stop sftp', {})); // ignore error
await safe(shell.exec('removeSftp', 'docker rm -f sftp', {})); // ignore error
debug('startSftp: stopping and deleting previous sftp container');
await docker.stopContainer('sftp');
await docker.deleteContainer('sftp');
debug('startSftp: starting sftp container');
await shell.exec('startSftp', runCmd, { shell: '/bin/bash' });
}