# -*- mode:sh; -*-
cd ${ROOT_DIR}

[[ -d $CONFIG ]] || { echo "$CONFIG does not exist. You should download first."; exit 1; }

declare -a packages
if [[ $# > 0 ]]; then
    packages=($@)
else
    packages=($($BIN/available-packages.sh))
    [[ ${#packages[@]} == 0 ]] && { echo "no package to uninstall"; exit 1; }
    packages=($(gum choose --no-limit ${packages[@]}))
fi

echo "Uninstalling packages: ${packages[@]}"
for p in ${packages[@]}; do
    echo "Uninstalling $p..."
    pushd $CONFIG/$p
    if [ -f ./uninstall.sh ]; then
        ./uninstall.sh || true
    elif [ -f ./install.sh ]; then
        ./install.sh --uninstall || true
    fi
    popd
    echo "✅"
done
 
