This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuel.sh
executable file
·150 lines (111 loc) · 3.38 KB
/
fuel.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
shopt -s nullglob
GLOBIGNORE="*.example"
ENVIRONMENTS=( hosts/* )
ENVIRONMENTS=( "${ENVIRONMENTS[@]##*/}" )
NUM_ARGS=1
show_usage() {
echo "
Usage:
./fuel.sh deploy <environment>
./fuel.sh db <environment> <action>
./fuel.sh uploads <environment> <action>
<environment> is the environment to deploy to ("staging", "production", etc)
<action> is the database action ("push", "pull")
Available environments:
`( IFS=$' '; echo "${ENVIRONMENTS[*]}" )`
Examples:
./fuel.sh deploy staging
./fuel.sh uploads staing push
./fuel.sh uploads production pull
./fuel.sh db staging push
./fuel.sh db production pull
"
}
[[ $# -ne $NUM_ARGS && $1 != deploy && $1 != db && $1 != uploads ]] && { show_usage; exit 0; }
if [[ $1 = deploy ]]; then
DEPLOY_CMD="ansible-playbook -i hosts/$2 deploy.yml"
ENVIRONMENTS=( hosts/* )
ENVIRONMENTS=( "${ENVIRONMENTS[@]##*/}" )
NUM_ARGS=2
show_usage() {
echo "
Usage:
./fuel.sh deploy <environment>
<environment> is the environment to deploy to ("staging", "production", etc)
Available environments:
`( IFS=$' '; echo "${ENVIRONMENTS[*]}" )`
Examples:
./fuel.sh deploy staging
./fuel.sh deploy production
"
}
HOSTS_FILE="hosts/$2"
[[ $# -ne $NUM_ARGS || $2 = -h ]] && { show_usage; exit 0; }
if [[ ! -e $HOSTS_FILE ]]; then
echo "Error: $2 is not a valid environment ($HOSTS_FILE does not exist)."
echo
echo "Available environments:"
( IFS=$'\n'; echo "${ENVIRONMENTS[*]}" )
exit 0
fi
$DEPLOY_CMD
fi
if [[ $1 = db ]]; then
DEPLOY_CMD="ansible-playbook -i hosts/$2 db_$3.yml"
ENVIRONMENTS=( hosts/* )
ENVIRONMENTS=( "${ENVIRONMENTS[@]##*/}" )
NUM_ARGS=3
show_usage() {
echo "
Usage:
./fuel.sh db <environment> <action>
<environment> is the environment to deploy to ("staging", "production", etc)
<action> is the database action ("push", "pull")
Available environments:
`( IFS=$' '; echo "${ENVIRONMENTS[*]}" )`
Examples:
./fuel.sh db staging push
./fuel.sh db production pull
"
}
HOSTS_FILE="hosts/$2"
[[ $# -ne $NUM_ARGS || $2 = -h ]] && { show_usage; exit 0; }
if [[ ! -e $HOSTS_FILE ]]; then
echo "Error: $2 is not a valid environment ($HOSTS_FILE does not exist)."
echo
echo "Available environments:"
( IFS=$'\n'; echo "${ENVIRONMENTS[*]}" )
exit 0
fi
$DEPLOY_CMD
fi
if [[ $1 = uploads ]]; then
DEPLOY_CMD="ansible-playbook -i hosts/$2 uploads_$3.yml"
ENVIRONMENTS=( hosts/* )
ENVIRONMENTS=( "${ENVIRONMENTS[@]##*/}" )
NUM_ARGS=3
show_usage() {
echo "
Usage:
./fuel.sh uploads <environment> <action>
<environment> is the environment to deploy to ("staging", "production", etc)
<action> is the database action ("push", "pull")
Available environments:
`( IFS=$' '; echo "${ENVIRONMENTS[*]}" )`
Examples:
./fuel.sh uploads staging push
./fuel.sh uploads production pull
"
}
HOSTS_FILE="hosts/$2"
[[ $# -ne $NUM_ARGS || $2 = -h ]] && { show_usage; exit 0; }
if [[ ! -e $HOSTS_FILE ]]; then
echo "Error: $2 is not a valid environment ($HOSTS_FILE does not exist)."
echo
echo "Available environments:"
( IFS=$'\n'; echo "${ENVIRONMENTS[*]}" )
exit 0
fi
$DEPLOY_CMD
fi