mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fish: only show warning instead of auto-installing safe-chain
This commit is contained in:
parent
6a8d56dfec
commit
32e2408ad0
1 changed files with 25 additions and 52 deletions
|
|
@ -1,76 +1,49 @@
|
|||
function installIfCommandNotFound
|
||||
set cmd $argv[1]
|
||||
function printSafeChainWarning
|
||||
set original_cmd $argv[1]
|
||||
|
||||
# Check if the command already exists
|
||||
if type -q $cmd
|
||||
return 0
|
||||
end
|
||||
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
||||
set_color -b yellow black
|
||||
printf "Warning:"
|
||||
set_color normal
|
||||
printf " safe-chain is not available to protect you from installing malware. %s will be run directly.\n" $original_cmd
|
||||
|
||||
# Check if Node.js version is below 18
|
||||
# Safe-chain requires Node.js 18 or higher
|
||||
set node_version (node -v | sed 's/v//' | cut -d'.' -f1)
|
||||
if test $node_version -lt 18
|
||||
return 2
|
||||
end
|
||||
|
||||
# Command not found, ask user if they want to install safe-chain
|
||||
read -l response -P "The command '$cmd' is not available. Do you want to install safe-chain to provide it? (y/N): "
|
||||
|
||||
if string match -qi 'y*' $response
|
||||
printf "Installing safe-chain...\n"
|
||||
installSafeChain
|
||||
|
||||
if test $status -ne 0
|
||||
printf "\nFailed to install safe-chain. Exiting.\n"
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
else
|
||||
printf "Skipping safe-chain installation. Using original command instead.\n"
|
||||
return 2
|
||||
end
|
||||
# Cyan text for the install command
|
||||
printf "Install safe-chain by using "
|
||||
set_color cyan
|
||||
printf "npm install -g @aikidosec/safe-chain"
|
||||
set_color normal
|
||||
printf ".\n"
|
||||
end
|
||||
|
||||
function installSafeChain
|
||||
command npm install -g @aikidosec/safe-chain
|
||||
|
||||
if test $status -ne 0
|
||||
return 1
|
||||
end
|
||||
|
||||
printf "------\n"
|
||||
end
|
||||
|
||||
function wrapCommand
|
||||
function wrapSafeChainCommand
|
||||
set original_cmd $argv[1]
|
||||
set aikido_cmd $argv[2]
|
||||
set cmd_args $argv[3..-1]
|
||||
|
||||
installIfCommandNotFound $aikido_cmd
|
||||
set install_result $status
|
||||
|
||||
if test $install_result -eq 2
|
||||
command $original_cmd $cmd_args
|
||||
else
|
||||
if type -q $aikido_cmd
|
||||
# If the aikido command is available, just run it with the provided arguments
|
||||
$aikido_cmd $cmd_args
|
||||
else
|
||||
# If the aikido command is not available, print a warning and run the original command
|
||||
printSafeChainWarning $original_cmd
|
||||
command $original_cmd $cmd_args
|
||||
end
|
||||
end
|
||||
|
||||
function npx
|
||||
wrapCommand "npx" "aikido-npx" $argv
|
||||
wrapSafeChainCommand "npx" "aikido-npx" $argv
|
||||
end
|
||||
|
||||
function yarn
|
||||
wrapCommand "yarn" "aikido-yarn" $argv
|
||||
wrapSafeChainCommand "yarn" "aikido-yarn" $argv
|
||||
end
|
||||
|
||||
function pnpm
|
||||
wrapCommand "pnpm" "aikido-pnpm" $argv
|
||||
wrapSafeChainCommand "pnpm" "aikido-pnpm" $argv
|
||||
end
|
||||
|
||||
function pnpx
|
||||
wrapCommand "pnpx" "aikido-pnpx" $argv
|
||||
wrapSafeChainCommand "pnpx" "aikido-pnpx" $argv
|
||||
end
|
||||
|
||||
function npm
|
||||
|
|
@ -81,5 +54,5 @@ function npm
|
|||
return
|
||||
end
|
||||
|
||||
wrapCommand "npm" "aikido-npm" $argv
|
||||
wrapSafeChainCommand "npm" "aikido-npm" $argv
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue