-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
executable file
·51 lines (46 loc) · 1.54 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
49
50
51
#!/bin/bash
help_uninstall() {
echo "Usage: env.sh uninstall [<path> | --config <config-file>]"
echo ""
echo "Uninstalls the environment system."
echo "This removes the environment directory and its associated files."
echo ""
echo "Options:"
echo " <path> The directory where the environment is installed."
echo " --config, -c Specify a custom configuration file to determine the installation path."
echo ""
echo "Exit Codes:"
echo " 0 Uninstallation successful."
echo " 1 Error during uninstallation (e.g., path not found, files cannot be deleted)."
exit 1
}
uninstall() {
if [[ -z "$1" ]] && [[ ! -f "$CONFIG_FILE" ]];then
echo "No installation path provided nor config file"
exit 1
fi
local install_path="$1"
source "$SCRIPT_DIR/utils/get_var_from_config.sh"
source "$SCRIPT_DIR/utils/validate_config.sh"
if [[ -z "$install_path" ]]; then
var="ENV_PATH"
install_path=$(get_var_from_config "$var")
status=$?
if [ $status -ne 0 ]; then
echo "Variable '${var}' is not defined in config file: $?"
exit 1
fi
fi
if [[ ! -f "$install_path/config.sh" ]]; then
echo "No config file found at $install_path. Exiting now..."
exit 1
fi
validate_config "$install_path/config.sh"
if [ $? -ne 0 ]; then
echo "Invalid config.sh file"
exit 1
fi
rm -rf "$install_path"
echo "Environment uninstalled successfully from $install_path."
exit 0
}