dctlenv/libexec/dctlenv-uninstall

24 lines
855 B
Bash
Executable File

#!/usr/bin/env bash
set -uo pipefail
[ "$#" -gt 1 ] && log_error "Need 1 version instead of $#" 'usage: dctlenv uninstall [<version>]'
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv uninstall [<version>]'
version_requested=$(echo $version_requested | sed 's/^v//')
version="$(dctlenv-list 2>/dev/null | sed -E 's/^(\*| )? //g; s/ \(set by .+\)$//' | grep -e "$version_requested" | head -n 1)"
[ -n "$version" ] || log_error "No versions matching '$version_requested' found in local"
dst_path="$DCTLENV_ROOT/versions/$version"
if [ -f "$dst_path/driftctl" ]; then
echo "Uninstall driftctl v$version"
rm -r "$dst_path"
# If no versions remain, remove the versions directory
rmdir "$DCTLENV_ROOT/versions" 2>/dev/null
echo "driftctl v$version is successfully uninstalled"
fi