Skip to content

Commit

Permalink
Merge pull request #97 from RunOnFlux/fix-cert
Browse files Browse the repository at this point in the history
fix(cert): write header before checking cert exists
  • Loading branch information
TheTrunk authored Sep 9, 2023
2 parents d6b0aee + 07b67bc commit 1333481
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/services/domain/cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ certbot renew --force-renewal --http-01-port=8787 --preferred-challenges http
try {
await fs.readFile(path);
const autoRenewScript = await fs.readFile(path, { encoding: 'utf-8' });
const cert = `bash -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /etc/ssl/${config.certFolder}/${domain}.pem"`;
if (autoRenewScript.includes(cert)) {
return;
}
// split the contents by new line
const lines = autoRenewScript.split(/\r?\n/);
if (!autoRenewScript.startsWith(header)) {
lines.splice(0, 0, header);
await fs.writeFile(path, lines.join('\n'), {
mode: 0o755,
flag: 'w',
encoding: 'utf-8',
});
}

const cert = `bash -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /etc/ssl/${config.certFolder}/${domain}.pem"`;
if (autoRenewScript.includes(cert)) {
return;
}

lines.splice(6, 0, cert); // push cert to top behind #Concatenate...
const file = lines.join('\n');
await fs.writeFile(path, file, {
Expand Down

0 comments on commit 1333481

Please sign in to comment.