-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.sh
executable file
·107 lines (89 loc) · 2.52 KB
/
cleanup.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -e
RESET="\\033[0m"
RED="\\033[31;1m"
GREEN="\\033[32;1m"
YELLOW="\\033[33;1m"
BLUE="\\033[34;1m"
WHITE="\\033[37;1m"
say_green()
{
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${GREEN}" "$1" "${RESET}"
return 0
}
say_red()
{
printf "%b%s%b\\n" "${RED}" "$1" "${RESET}"
}
say_yellow()
{
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${YELLOW}" "$1" "${RESET}"
return 0
}
say_blue()
{
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${BLUE}" "$1" "${RESET}"
return 0
}
say_white()
{
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${WHITE}" "$1" "${RESET}"
return 0
}
at_exit()
{
# shellcheck disable=SC2181
# https://github.com/koalaman/shellcheck/wiki/SC2181
# Disable because we don't actually know the command we're running
# We need the slack/discord workspace URL here for connect
if [ "$?" -ne 0 ]; then
>&2 say_red
>&2 say_red "We're sorry, but it looks like something might have gone wrong during installation."
>&2 say_red "If you need help, feel free to react out to us on [email protected]"
fi
}
trap at_exit EXIT
OS=""
case $(uname) in
"Linux") OS="linux";;
"Darwin") OS="darwin";;
*)
print_unsupported_platform
exit 1
;;
esac
clean_existing_dw() {
if [ $OS = "darwin" ]; then
if command -v dw >/dev/null; then
dw_location=$(which dw)
echo $dw_location
if [[ $dw_location == */usr/local/* ]]; then
>&2 say_red "Non brew dw installation found in system, cleaning it up"
>&2 say_white "We will need root access for the following command"
>&2 say_white "sudo rm $(which dw)"
sudo rm $(which dw)
>&2 say_white "dw-cli cleaned up"
fi
fi
fi
}
clean_legacy_config() {
>&2 say_blue "Cleaning up legacy ~/.dw-cli/config.json in favour of newer config"
rm -f ~/.dw-cli/config.json
}
outro_commands_message() {
if [ $OS = "darwin" ]; then
>&2 say_white "Please do run 'brew update' before installing newer dw"
if command -v dw >/dev/null; then
dw_location=$(which dw)
if [[ $dw_location == */brew/* ]]; then
>&2 say_white "Your system already has a brew dw-cli installation"
>&2 say_white "Please run 'brew upgrade dw'"
fi
fi
fi
>&2 say_white "When everything is installed, please run 'dw config' and you are good to go!"
}
clean_existing_dw
clean_legacy_config
outro_commands_message