2023-12-19 19:13:36 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Help screen
|
|
|
|
#---
|
|
|
|
|
|
|
|
function help()
|
|
|
|
{
|
|
|
|
cat << EOF
|
|
|
|
Script for the uninstallation of sh-elf-vhex
|
|
|
|
|
|
|
|
Usage $0 [options...]
|
|
|
|
|
|
|
|
Configurations:
|
|
|
|
-h, --help Display this help
|
|
|
|
--prefix-install Installation (bin) prefix
|
|
|
|
--prefix-sysroot Sysroot (lib, header, ...) prefix
|
|
|
|
--prefix-clone Clone prefix
|
|
|
|
--no-purge Do not remove the cloned folder
|
2024-05-12 00:17:11 +02:00
|
|
|
--force Do not request user validation
|
2023-12-19 19:13:36 +01:00
|
|
|
EOF
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Parse arguments
|
|
|
|
#---
|
|
|
|
|
2024-05-12 00:17:11 +02:00
|
|
|
force='false'
|
2023-12-19 19:13:36 +01:00
|
|
|
purge='true'
|
|
|
|
prefix_install=~/.local/bin
|
|
|
|
prefix_sysroot=~/.local/share/sh-elf-vhex/_sysroot
|
|
|
|
prefix_clone=~/.local/share/sh-elf-vhex
|
|
|
|
for arg
|
|
|
|
do case "$arg" in
|
|
|
|
--help | -h) help;;
|
|
|
|
--no-purge) purge='false';;
|
|
|
|
--prefix-install=*) prefix_install=${arg#*=};;
|
|
|
|
--prefix-sysroot=*) prefix_sysroot=${arg#*=};;
|
|
|
|
--prefix-clone=*) prefix_clone=${arg#*=};;
|
2024-05-12 00:17:11 +02:00
|
|
|
--force) force='true';;
|
2023-12-19 19:13:36 +01:00
|
|
|
*)
|
|
|
|
echo "error: unrecognized argument '$arg', giving up." >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Preliminary check
|
|
|
|
#---
|
|
|
|
|
|
|
|
if [[ ! -d "$prefix_clone" ]]
|
|
|
|
then
|
|
|
|
echo -e \
|
|
|
|
'Are you sure to have installed the project ?\n' \
|
2023-12-22 10:22:24 +01:00
|
|
|
'\rIt seems that the cloned prefix does not exist' \
|
2023-12-19 19:13:36 +01:00
|
|
|
>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "$prefix_install" ]]
|
|
|
|
then
|
|
|
|
echo -e \
|
2023-12-22 10:22:24 +01:00
|
|
|
'WARNING: It seems that the install prefix does not exist\n' \
|
2023-12-19 19:13:36 +01:00
|
|
|
'WARNING: if you continue, the install prefix will be ignore and' \
|
|
|
|
'nothing will be removed' \
|
|
|
|
>&2
|
2023-12-22 10:22:24 +01:00
|
|
|
read -p 'Proceed anyway ? [yN]' -r valid < /dev/tty
|
2023-12-19 19:13:36 +01:00
|
|
|
if [[ "$valid" != 'y' ]]; then
|
|
|
|
echo 'Operation aborted o(x_x)o' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -x "$prefix_sysroot/bin/sh-elf-vhex-as" ]]
|
|
|
|
then
|
|
|
|
echo -e \
|
2023-12-22 10:22:24 +01:00
|
|
|
'ERROR: Are you sure to have built sh-elf-vhex ? It Seems that the' \
|
2023-12-19 19:13:36 +01:00
|
|
|
'sh-elf-vhex-as cannot be found in the sysroot prefix' \
|
|
|
|
>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-12 00:17:11 +02:00
|
|
|
if [[ "$force" != 'true' ]]
|
2023-12-19 19:36:56 +01:00
|
|
|
then
|
2024-05-12 00:17:11 +02:00
|
|
|
echo 'The script will uninstall the sh-elf-vhex compiler with:'
|
|
|
|
echo " - Clone directory: $prefix_clone"
|
|
|
|
echo " - Install directory: $prefix_install"
|
|
|
|
echo " - Sysroot directory: $prefix_sysroot"
|
|
|
|
read -p 'Proceed ? [yN]: ' -r valid < /dev/tty
|
|
|
|
if [[ "$valid" != 'y' ]]
|
|
|
|
then
|
|
|
|
echo 'Operation aborted o(x_x)o'
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-12-19 19:36:56 +01:00
|
|
|
fi
|
|
|
|
|
2023-12-19 19:13:36 +01:00
|
|
|
#---
|
|
|
|
# Unistall step
|
|
|
|
#---
|
|
|
|
|
2023-12-19 19:25:58 +01:00
|
|
|
cd "$prefix_clone/scripts" || exit 1
|
2023-12-19 19:13:36 +01:00
|
|
|
source ./_utils.sh
|
|
|
|
|
|
|
|
echo "$TAG removing symlinks to binaries..."
|
|
|
|
for x in "$prefix_sysroot"/bin/*; do
|
|
|
|
utils_callcmd unlink "$x"
|
|
|
|
if [[ -L "$prefix_install/$(basename "$x")" ]]; then
|
|
|
|
utils_callcmd unlink "$prefix_install/$(basename "$x")"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$TAG removing sysroot..."
|
|
|
|
rm -rf "$prefix_sysroot"
|
|
|
|
|
|
|
|
if [[ "$purge" == 'true' ]]
|
|
|
|
then
|
|
|
|
echo "$TAG removing cloned folder..."
|
|
|
|
rm -rf "$prefix_clone"
|
|
|
|
fi
|