mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2025-06-22 04:22:10 +10:00
Add option to execute script before and after rsync
This commit is contained in:
parent
0e7d8019db
commit
5dfe8ebb5a
14 changed files with 278 additions and 213 deletions
|
@ -1,37 +1,20 @@
|
|||
const { writeFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const {
|
||||
validateDir,
|
||||
validateFile
|
||||
} = require('./helpers');
|
||||
const { writeToFile } = require('./helpers');
|
||||
|
||||
const {
|
||||
HOME
|
||||
} = process.env;
|
||||
const addSshKey = (content, filename) => {
|
||||
const { HOME } = process.env;
|
||||
const dir = join(HOME || __dirname, '.ssh');
|
||||
const filePath = join(dir, filename);
|
||||
|
||||
const addSshKey = (key, name) => {
|
||||
const sshDir = join(HOME || __dirname, '.ssh');
|
||||
const filePath = join(sshDir, name);
|
||||
writeToFile({ dir, filename: 'known_hosts', content: '' });
|
||||
writeToFile({ dir, filename, content, isRequired: true });
|
||||
|
||||
validateDir(sshDir);
|
||||
validateFile(`${sshDir}/known_hosts`);
|
||||
|
||||
try {
|
||||
writeFileSync(filePath, key, {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
|
||||
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
||||
console.log('✅ Ssh key added to `.ssh` dir ', dir);
|
||||
|
||||
return filePath;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addSshKey
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue