mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add nvm safe-chain uninstallation in install script
This commit is contained in:
parent
8bfbe1c77d
commit
24230da4a7
1 changed files with 55 additions and 2 deletions
|
|
@ -159,6 +159,57 @@ remove_volta_installation() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check and uninstall nvm-managed package if present across all Node versions
|
||||||
|
remove_nvm_installation() {
|
||||||
|
# Check if nvm is available as a command
|
||||||
|
if ! command_exists nvm; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get list of installed Node versions
|
||||||
|
nvm_versions=$(nvm list 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "")
|
||||||
|
|
||||||
|
if [ -z "$nvm_versions" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Track if we found any installations
|
||||||
|
found_installation=false
|
||||||
|
uninstall_failed=false
|
||||||
|
current_version=$(nvm current 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
# Check each version for safe-chain installation
|
||||||
|
for version in $nvm_versions; do
|
||||||
|
# Check if this version has safe-chain installed
|
||||||
|
# Use nvm exec to run npm list in the context of that Node version
|
||||||
|
if nvm exec "$version" npm list -g @aikidosec/safe-chain >/dev/null 2>&1; then
|
||||||
|
if [ "$found_installation" = false ]; then
|
||||||
|
info "Detected nvm installation(s) of @aikidosec/safe-chain"
|
||||||
|
info "Uninstalling from all Node versions..."
|
||||||
|
found_installation=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
info " Removing from Node $version..."
|
||||||
|
if nvm exec "$version" npm uninstall -g @aikidosec/safe-chain >/dev/null 2>&1; then
|
||||||
|
info " Successfully uninstalled from Node $version"
|
||||||
|
else
|
||||||
|
warn " Failed to uninstall from Node $version"
|
||||||
|
uninstall_failed=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Restore original Node version if it was set
|
||||||
|
if [ -n "$current_version" ] && [ "$current_version" != "none" ] && [ "$current_version" != "system" ]; then
|
||||||
|
nvm use "$current_version" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If any uninstall failed, error out instead of continuing
|
||||||
|
if [ "$uninstall_failed" = true ]; then
|
||||||
|
error "Failed to uninstall @aikidosec/safe-chain from all nvm Node versions. Please uninstall manually and try again."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Parse command-line arguments
|
# Parse command-line arguments
|
||||||
parse_arguments() {
|
parse_arguments() {
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
|
|
@ -204,9 +255,11 @@ main() {
|
||||||
|
|
||||||
info "$INSTALL_MSG"
|
info "$INSTALL_MSG"
|
||||||
|
|
||||||
# Check for existing safe-chain installation through npm or volta
|
# Check for existing safe-chain installation through nvm, volta, or npm
|
||||||
remove_npm_installation
|
# nvm must be checked first as it manages multiple Node versions
|
||||||
|
remove_nvm_installation
|
||||||
remove_volta_installation
|
remove_volta_installation
|
||||||
|
remove_npm_installation
|
||||||
|
|
||||||
# Detect platform
|
# Detect platform
|
||||||
OS=$(detect_os)
|
OS=$(detect_os)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue