-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathroll
More file actions
executable file
·96 lines (85 loc) · 3.17 KB
/
roll
File metadata and controls
executable file
·96 lines (85 loc) · 3.17 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
#!/usr/bin/env bash
set -e
trap 'error "$(printf "Command \`%s\` at $BASH_SOURCE:$LINENO failed with exit code $?" "$BASH_COMMAND")"' ERR
## find directory where this script is located following symlinks if necessary
readonly ROLL_DIR="$(
cd "$(
dirname "$(
(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}") \
| sed -e "s#^../#$(dirname "$(dirname "${BASH_SOURCE[0]}")")/#"
)"
)/.." >/dev/null \
&& pwd
)"
source "${ROLL_DIR}/utils/core.sh"
source "${ROLL_DIR}/utils/config.sh"
source "${ROLL_DIR}/utils/registry.sh"
source "${ROLL_DIR}/utils/env.sh"
## verify docker is installed
if ! which docker >/dev/null; then
fatal "docker could not be found; please install and try again."
fi
## verify docker compose meets version constraint
DOCKER_COMPOSE_REQUIRE="2.2.3"
DOCKER_COMPOSE_VERSION="$(docker compose version | grep -oE '[0-9\.]+' | head -n1)"
if ! test $(version ${DOCKER_COMPOSE_VERSION}) -ge $(version ${DOCKER_COMPOSE_REQUIRE}); then
fatal "docker compose version should be ${DOCKER_COMPOSE_REQUIRE} or higher (${DOCKER_COMPOSE_VERSION} installed)"
fi
## define and export global shared directory paths
export readonly ROLL_HOME_DIR="${ROLL_HOME_DIR:-"$HOME/.roll"}"
export readonly ROLL_SSL_DIR="${ROLL_HOME_DIR}/ssl"
export readonly ROLL_COMPOSER_DIR="${ROLL_COMPOSER_DIR:-"$HOME/.composer"}"
## declare variables for flags and arguments
declare ROLL_HELP=
declare ROLL_PARAMS=()
declare ROLL_CMD_VERB=
declare ROLL_CMD_EXEC=
declare ROLL_CMD_HELP=
declare ROLL_CMD_ANYARGS=(svc env db redis sync shell debug rootnotty rootshell clinotty root node npm cli copyfromcontainer copytocontainer composer grunt magento magerun backup restore restore-full duplicate)
## parse first argument as command and determine validity
if (( "$#" )); then
## local project directory if running within one; don't fail if it can't be found
ROLL_ENV_PATH="$(locateEnvPath 2>/dev/null)" || true
ROLL_ENV_TYPE="$(renderEnvType 2>/dev/null)" || true
# Use registry system for command discovery
COMMAND_RESULT="$(findCommand "$1")"
if [[ "$COMMAND_RESULT" =~ ^found: ]]; then
ROLL_CMD_VERB="$1"
# Extract cmd_path and help_path from "found:cmd_path:help_path"
COMMAND_RESULT="${COMMAND_RESULT#found:}"
ROLL_CMD_EXEC="${COMMAND_RESULT%%:*}"
ROLL_CMD_HELP="${COMMAND_RESULT#*:}"
shift
else
ROLL_HELP=1
fi
else
ROLL_HELP=1
fi
## parse arguments
while (( "$#" )); do
case "$1" in
-h|--help)
ROLL_HELP=1
break
;;
--) # end argument parsing (unless command is on 'anyargs' list and consumes anything as params)
shift
containsElement "${ROLL_CMD_VERB}" "${ROLL_CMD_ANYARGS[@]}" || break
;;
-*|--*=) # unsupported flags (unless command is on 'anyargs' list and consumes anything as params)
containsElement "${ROLL_CMD_VERB}" "${ROLL_CMD_ANYARGS[@]}" && break
fatal "Unsupported flag $1"
;;
*) # preserve positional arguments
ROLL_PARAMS+=("$1")
shift
;;
esac
done
## display command specific usage info if help flag is set
if [[ ${ROLL_HELP} ]]; then
source "${ROLL_DIR}/commands/usage.cmd"
fi
## execute sub-command in context of this script
source "${ROLL_CMD_EXEC}"