AikidoSec-safe-chain/src/shell-integration/supported-shells/bash.js
Sander Declerck 9476927b87
Fix tests
2025-07-17 17:15:46 +02:00

45 lines
1 KiB
JavaScript

import {
addLineToFile,
doesExecutableExistOnSystem,
execAndGetOutput,
removeLinesMatchingPattern,
} from "../helpers.js";
const shellName = "Bash";
const executableName = "bash";
const startupFileCommand = "echo ~/.bashrc";
function isInstalled() {
return doesExecutableExistOnSystem(executableName);
}
function teardown() {
const startupFile = execAndGetOutput(startupFileCommand, executableName);
// Removes all aliases starting with "alias npm=", "alias npx=", or "alias yarn="
// This will remove the safe-chain aliases for npm, npx, and yarn commands.
removeLinesMatchingPattern(startupFile, /^alias\s+(npm|npx|yarn)=/);
return true;
}
function setup(tools) {
const startupFile = execAndGetOutput(startupFileCommand, executableName);
teardown();
for (const { tool, aikidoCommand } of tools) {
addLineToFile(
startupFile,
`alias ${tool}="${aikidoCommand}" # Safe-chain alias for ${tool}`
);
}
return true;
}
export default {
name: shellName,
isInstalled,
setup,
teardown,
};