-
Notifications
You must be signed in to change notification settings - Fork 4
/
chf
executable file
·98 lines (88 loc) · 3.37 KB
/
chf
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
#!/bin/bash
SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "-------------------------------------------------------------------"
echo "Content Hub Farm Control Script"
echo ""
echo "Usage:"
echo " \$./bin/chf <COMMAND> <COMMAND-ARGUMENTS>"
echo " \$./bin/chf <CONTAINER> <COMMAND> <COMMAND-ARGUMENTS>"
echo ""
echo "To list all available commands: \$./bin/chf list-commands"
echo "-------------------------------------------------------------------"
# List all available commands if 'list-commands' argument is provided.
if [ "$1" == "list-commands" ]; then
echo "Available Internal Commands:"
ls -1 ${SCRIPT_DIRECTORY}/bin/commands/internal | sed -e 's/\.sh$//' | sed -e 's/^/ * /'
echo "Available Commands in Container Scope:"
ls -1 ${SCRIPT_DIRECTORY}/bin/commands/container | sed -e 's/\.sh$//' | sed -e 's/^/ * /'
exit
fi
# Check whether this was an internal command or in the scope of a container.
INTERNAL_COMMAND=false
INTERNAL_COMMAND_LIST=`ls -1 ${SCRIPT_DIRECTORY}/bin/commands/internal | sed -e 's/\.sh$//' | sed -e 'H;${x;s/\n/|/g;s/^,//;p;};d'`
if [[ "$1" =~ ^(echo ${INTERNAL_COMMAND_LIST})$ ]]; then
INTERNAL_COMMAND=true;
fi
if [ $INTERNAL_COMMAND == true ]; then
COMMAND="$1"
COMMAND_FILE=${SCRIPT_DIRECTORY}/bin/commands/internal/${COMMAND}.sh
else
CONTAINER="$1"
COMMAND="$2"
COMMAND_FILE=${SCRIPT_DIRECTORY}/bin/commands/container/${COMMAND}.sh
# Obtaining the list of available containers.
list=`docker-compose images | sed -n '1,2!p' | cut -f 1 -d ' ' | awk '{print $NF}'`
# Checking if container is available.
if [[ $list =~ (^|[[:space:]])"$CONTAINER"($|[[:space:]]) ]] ; then
if [[ -z "$CONTAINER" && -z "$COMMAND" ]]; then
echo "Services are not running..."
else
echo "Executing command '$2' on container '$1'..."
fi
else
echo "Cannot connect to container '$CONTAINER'. Plese use one of the following containers:"
echo "$list" | sed -e 's/^/ * /'
echo ""
echo "You need to provide a command to execute. Some examples below:"
echo "For Internal Commands:"
echo ""
echo "\$./chf go ; Full Setup and installation"
echo "\$./chf setup ; Sets up the environment and creates configuration files."
echo "\$./chf up ; Creates and starts containers."
echo "\$./chf start ; Starts services."
echo "\$./chf stop ; Stops services."
echo "\$./chf pause ; Pause services."
echo "\$./chf logs ; View output from containers."
echo ""
echo "For Commands in the container scope:"
echo ""
echo "\$./chf <container> enable_xdebug ; Enables Xdebug in the container."
echo "\$./chf <container> drush <arguments> ; Executes drush commands in the container."
echo "\$./chf <container> sh ; Opens a terminal to the container."
echo ""
exit
fi
fi
# Eliminating command argument to pass to command script.
args=""
for i in "$@" ; do
if [ "$i" != "$COMMAND" ]; then
args="${args} $i"
fi
done
# Execute command.
if [ -f "$COMMAND_FILE" ]; then
source ${COMMAND_FILE} $args
else
if [[ -z "$CONTAINER" && -z "$COMMAND" ]]; then
echo ""
echo "To create and start services:"
echo " ./chf up"
echo ""
echo "To start services, if containers are already built:"
echo " ./chf start"
echo ""
else
echo "The command '${COMMAND}' is not implemented."
fi
fi