-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·128 lines (102 loc) · 3.58 KB
/
install
File metadata and controls
executable file
·128 lines (102 loc) · 3.58 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
importLib "lib/lib-docker.sh"
# ---------------------------------------------------------------------
# Variables
# ---------------------------------------------------------------------
# Get current file name
CURRENT_FILE_NAME="$(basename "${BASH_SOURCE[0]}")"
# Save command name
args=("$@")
COMMAND_NAME="${args[0]}"
# ---------------------------------------------------------------------
# Messages
# ---------------------------------------------------------------------
MESSAGE_INSTALL_START="Starting installation...";
MESSAGE_INSTALL_ALREADY_INSTALLED="Already installed!";
MESSAGE_INSTALL_SUCCESS="Installation completed!";
MESSAGE_INSTALL_FAILED="Installation failed!";
MESSAGE_TARGET_NOT_WRITABLE="Target path is not writable with the current user, please check the permissions or run the script as root";
MESSAGE_TARGET_NOT_DIRECTORY="Target path is not a directory, please check the path or run the script as root";
# ---------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------
usage() {
helpify_title "install" "[OPTIONS...]"
helpify_subtitle "Install the GDRCD development stack"; echo;
helpify_subtitle "OPTIONS:"
helpify "-h, --help" "Show this help"
helpify "-t, --target" "Set the global command installation path" "[/usr/local/bin]"
helpify "-f, --force" "Force reinstallation of global command"
}
usage4help() {
helpify "install" "Installing the GDRCD development stack"
}
# ---------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------
#---------------------------PARSE ARGUMENTS-------------------------------#
# Set default values
target="/usr/local/bin"
force_reinstall="false"
# Parse arguments
while [[ $# -gt 0 ]]; do
# if the argument is the command name, skip it
if [[ "$1" == "${COMMAND_NAME}" ]]; then
shift; continue
fi
case "${1}" in
-h|--help)
need_help="true"; shift ;;
-t|--target)
target="${2}"; shift; shift ;;
-f|--force)
force_reinstall="true"; shift ;;
*)
messageUnknownCommand "$COMMAND_NAME" "$1"; exit 1;;
esac
done
# Execute post argument parsing checks
finalize_argument_parsing
#---------------------------RUN COMMAND-------------------------------#
install() {
message --magenta "${MESSAGE_INSTALL_START}";
# Check if the target path is a directory
if [[ ! -d "$target" ]]; then
message --error "${MESSAGE_TARGET_NOT_DIRECTORY}";
exit 1;
fi;
# Check if the target path is writable
if [[ ! -w "$target" ]]; then
message --error "${MESSAGE_TARGET_NOT_WRITABLE}";
exit 1;
fi;
# Check if stack is already installed
if [[ -f "${target}/${PROJECT}" ]]; then
if [[ "${force_reinstall}" == "true" ]]; then
rm -f "${target}/${PROJECT}";
else
message --error "${MESSAGE_INSTALL_ALREADY_INSTALLED}";
exit 1;
fi;
fi;
# Create the target path if it does not exist
if [[ ! -d "$target" ]]; then
mkdir -p "$target";
fi;
# Create link to the stack binary
ln -sf "${STACK_DIR}/run" "$target/${PROJECT}" 2>/dev/null;
# Set the permissions
chmod +x "$target/${PROJECT}";
# Check if the installation was successful
if [[ -f "$target/${PROJECT}" ]]; then
message --success "${MESSAGE_INSTALL_SUCCESS}";
else
message --error "${MESSAGE_INSTALL_FAILED}";
exit 1;
fi;
}
# Run command if this file is the command file
if [[ "${COMMAND_NAME}" == "${CURRENT_FILE_NAME}" ]]; then
logo;
install;
fi