2021-01-25 14:36:44 +00:00
|
|
|
#!/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>]'
|
|
|
|
|
2021-03-08 10:48:56 +00:00
|
|
|
version_requested=$(echo $version_requested | sed 's/^v//')
|
|
|
|
|
2021-01-25 14:36:44 +00:00
|
|
|
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
|