-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathuninstall.sh
executable file
·48 lines (38 loc) · 1.15 KB
/
uninstall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
if [ $# == 0 ]; then
exit 3
fi
realpath() {
if [ -x "$( which realpath )" ]
then
# call the realpath utility if installed
"$( which realpath )" "$1"
else
# on MacOS there is no realpath utility on a default installation
# -> use fallback to perl
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
fi
}
APP_DIR=$(pwd)
if [[ -f "$APP_DIR/.bash_cli" ]]; then
APP_DIR=$(dirname "$APP_DIR")
fi
if [[ ! -f "$APP_DIR/app/.bash_cli" ]]; then
>&2 echo -e "\033[31mYou are not within a Bash CLI project\033[39m"
>&2 echo "Please change your directory to a valid project or run the init command to set one up."
exit 1
fi
NAME="$1"
FOLDER="${2-"/usr/bin"}"
if [[ ! -f "$FOLDER/$NAME" ]]; then
>&2 echo -e "\033[31mCommand \033[36m$1\033[31m did not exist in \033[36m$2\033[39m"
exit 1
fi
LN_PATH=$(realpath "$FOLDER/$NAME")
if [[ "$LN_PATH" != "$APP_DIR/cli" ]]; then
>&2 echo -e "\033[31mCommand \033[36m$1\033[31m doesn't resolve to this project\033[39m"
>&2 echo "Expected: $APP_DIR/cli"
>&2 echo "Got: $LN_PATH"
exit 1
fi
rm "$FOLDER/$NAME"